我是VC新手,最近在学习钩子,现在碰到一个问题,如何让鼠标经过某窗口的某控件时能及时得到该控件的句柄?也就是说鼠标移动到什么位置,就要及时得到鼠标所在窗口中所指的控件的句柄。在论坛里找了很多相关的提问,可没有一个写的是完整的,对于我这个新手来说实在是有些困难,所以请各位高手们尽量把主要实现代码写完整,同时也写清各变量所使用的类型。谢谢!
解决方案 »
- VAX1912和河蟹它的补丁,另求生日祝福~~
- MFC的一般类,如继承CView类的,有没有类似C++设计模式中的单实例设计模式的获取实例函数
- vc6.0+DataGrid + Access,如何获取DataGrid的表名?
- 问个DirectX简单问题
- 高分相送,有人会读wab文件中的文件夹吗?
- 请问:哪里能够找到人脸检测的源代码?非常感谢!
- 如何打开帮助文件?在线等.....
- 在VIEW上放两个自制控件,如何在他们之间连线?
- 如何获取机器硬件厂商信息?
- 请问在调用_RecordsetPtr->Open()前如何判断该_RecordsetPtr是否已经打开??
- SendMessage( hwnd,WM_ACTIVATEAPP,TRUE,thisThID); //不管用?
- 如何获得键盘的事件
POINT pt;
HWND hwnd;
UINT wHitTestCode;
ULONG_PTR dwExtraInfo;
} MOUSEHOOKSTRUCT, *PMOUSEHOOKSTRUCT;
LRESULT CALLBACK MouseProc( int nCode,
WPARAM wParam,
LPARAM lParam
);
ParametersnCode
[in] Specifies a code the hook procedure uses to determine how to process the message. If nCode is less than zero, the hook procedure must pass the message to the CallNextHookEx function without further processing and should return the value returned by CallNextHookEx. This parameter can be one of the following values.
HC_ACTION
The wParam and lParam parameters contain information about a mouse message.
HC_NOREMOVE
The wParam and lParam parameters contain information about a mouse message, and the mouse message has not been removed from the message queue. (An application called the PeekMessage function, specifying the PM_NOREMOVE flag.)
wParam
[in] Specifies the identifier of the mouse message.
lParam
[in] Pointer to a MOUSEHOOKSTRUCT structure.
由此可见,MouseHook中已经可以直接取到窗口句柄了。根本不用其它什么方法了。
pmouse = (PMOUSEHOOKSTRUCT)lParam;
HWND hWnd=pmouse->hWnd;
http://blog.csdn.net/laiyiling/archive/2004/11/21/189305.aspx
static CWnd* PASCAL FromHandle( HWND hWnd );
like spy++ example