各位兄弟,哪位高手能帮小弟我完善一下代码,不胜感激,要求对Hook有点了解的朋友
各位兄弟,谁能帮我完善一下代码,不胜感激,要求对Hook有点了解的朋友。
我想写一个程序,程序运行后,捕获鼠标的移动事件,在鼠标的位置画一个半径是5(单位是像素)的红色圆点。不要替换鼠标的图标,只是在鼠标的图标的中心处再画一个红色圆点。这是我找到的部分代码,那位高人帮我完善一下?
HWND hWndServer = NULL;
HINSTANCE hInst;
HHOOK hook;
static LRESULT CALLBACK msghook(UINT nCode, WPARAM wParam, LPARAM lParam);
/****************************************************************************
* setMyHook
* Inputs:
* HWND hWnd: Window to notify
* Result: BOOL
* TRUE if successful
* FALSE if error
* Effect:
* Sets the hook
****************************************************************************/
BOOL setMyHook(HWND hWnd)
{
if(hWndServer != NULL)
return FALSE; // already hooked!
hook = SetWindowsHookEx(WH_GETMESSAGE,
(HOOKPROC)msghook,
hInst,
0);
if(hook != NULL)
{ /* success */
hWndServer = hWnd;
return TRUE;
} /* success */
return FALSE; // failed to set hook
} // setMyHook
/****************************************************************************
* clearMyHook
* Inputs:
* HWND hWnd: Window hook
* Result: BOOL
* TRUE if successful
* FALSE if error
* Effect:
* Removes the hook that has been set
****************************************************************************/
BOOL clearMyHook(HWND hWnd)
{
if(hWnd != hWndServer || hWnd == NULL)
return FALSE;
BOOL unhooked = UnhookWindowsHookEx(hook);
if(unhooked)
hWndServer = NULL;
return unhooked;
} // clearMyHook
/****************************************************************************
* msghook
* Inputs:
* int nCode: Code value
* WPARAM wParam:
* LPARAM lParam:
* Result: LRESULT
* Either 0 or the result of CallNextHookEx
* Effect:
* Hook processing function. If the message is a mouse-move message,
我想写一个程序,程序运行后,捕获鼠标的移动事件,在鼠标的位置画一个半径是5(单位是像素)的红色圆点。不要替换鼠标的图标,只是在鼠标的图标的中心处再画一个红色圆点。这是我找到的部分代码,那位高人帮我完善一下?
HWND hWndServer = NULL;
HINSTANCE hInst;
HHOOK hook;
static LRESULT CALLBACK msghook(UINT nCode, WPARAM wParam, LPARAM lParam);
/****************************************************************************
* setMyHook
* Inputs:
* HWND hWnd: Window to notify
* Result: BOOL
* TRUE if successful
* FALSE if error
* Effect:
* Sets the hook
****************************************************************************/
BOOL setMyHook(HWND hWnd)
{
if(hWndServer != NULL)
return FALSE; // already hooked!
hook = SetWindowsHookEx(WH_GETMESSAGE,
(HOOKPROC)msghook,
hInst,
0);
if(hook != NULL)
{ /* success */
hWndServer = hWnd;
return TRUE;
} /* success */
return FALSE; // failed to set hook
} // setMyHook
/****************************************************************************
* clearMyHook
* Inputs:
* HWND hWnd: Window hook
* Result: BOOL
* TRUE if successful
* FALSE if error
* Effect:
* Removes the hook that has been set
****************************************************************************/
BOOL clearMyHook(HWND hWnd)
{
if(hWnd != hWndServer || hWnd == NULL)
return FALSE;
BOOL unhooked = UnhookWindowsHookEx(hook);
if(unhooked)
hWndServer = NULL;
return unhooked;
} // clearMyHook
/****************************************************************************
* msghook
* Inputs:
* int nCode: Code value
* WPARAM wParam:
* LPARAM lParam:
* Result: LRESULT
* Either 0 or the result of CallNextHookEx
* Effect:
* Hook processing function. If the message is a mouse-move message,