如何获得.net控件的windows句柄
2012-10-20 11:38
183 查看
有一个简单的获得控件的句柄的窍门。你将窗体设置为鼠标可捕获,那么你的窗口句柄可以通过使用Windows API捕获。 这个想法在以下的GetHWnd函数中实现:
class WinAPI
{
[DllImport("coredll.dll")]
private static extern IntPtr SetCapture(IntPtr hWnd);
[DllImport("coredll.dll")]
private static extern IntPtr GetCapture();
public static IntPtr GetHWnd(Control ctrl)
{
IntPtr hOldWnd = GetCapture();
ctrl.Capture = true;
IntPtr hWnd = GetCapture();
ctrl.Capture = false;
SetCapture(hOldWnd);
return hWnd;
}
}
这是GetHWnd函数的简单用法:
IntPtr hWndButton = WinAPI.GetHWnd(button1);
class WinAPI
{
[DllImport("coredll.dll")]
private static extern IntPtr SetCapture(IntPtr hWnd);
[DllImport("coredll.dll")]
private static extern IntPtr GetCapture();
public static IntPtr GetHWnd(Control ctrl)
{
IntPtr hOldWnd = GetCapture();
ctrl.Capture = true;
IntPtr hWnd = GetCapture();
ctrl.Capture = false;
SetCapture(hOldWnd);
return hWnd;
}
}
这是GetHWnd函数的简单用法:
IntPtr hWndButton = WinAPI.GetHWnd(button1);
相关文章推荐
- 如何获得.net控件的windows句柄
- 怎样获得.net控件的windows句柄(PPC)
- 获得.net控件的windows句柄的方法
- [windows编程] 如何利用句柄操作其他windows窗体(1)
- 如何从Internet Explorer_Server窗口句柄获得IHTMLDocument
- 如何获得Windows的启动时间
- 如何获得Windows 8 应用的版本信息
- 如何获得Windows 8中已记住的WIFI的明文密码
- 如何用SC获得Windows Service的启动类型,运行状态, 修改启动类型
- VC学习资料收集(22):如何获得Windows各类系统目录
- dll中如何获得调用者的窗口?得到窗口句柄那么DC也就可以得到了!
- 已知IWebBrowser2接口,如何获得其Internet Explorer_Server窗口句柄?
- 如何获得窗口句柄以及WIN32+API参考大全
- WINDOWS 2000下如何获得用户登录名和密码
- 如何获得另外一个应用程序中的控件句柄。 - 日志 - tomore - 问友源码空间
- C# Windows API应用之GetDesktopWindow ——获得桌面所有窗口句柄的方法
- 如何用VB获得Windows各类系统目录
- 如何通过窗口句柄来获得一个程序窗口的大小
- spy++如何获得其他进程中的句柄