Home > Software engineering >  Windows hook global hooks how to get the click of the mouse control handle?
Windows hook global hooks how to get the click of the mouse control handle?

Time:09-24

To implement a requirement is intercepted on the window of the third party software click a button, and then make their software related response,
Generally use hook technology to process Windows messages,
Refer to this article
https://blog.csdn.net/aoshilang2249/article/details/46896311Global hooks installed, can intercept the mouse click event,

Now have the following two questions
1. Click on the control handle
Define a hook message structure:
[StructLayout (LayoutKind. Sequential)]
Public class MouseHookStruct
{
Public POINT pt;
Public int hWnd;
Public int wHitTestCode;
Public int dwExtraInfo;
}

Perform the hook callback function public delegate int HookProc (int nCode, Int32 wParam, IntPtr lParam);
MouseHookStruct m=(MouseHookStruct) Marshal PtrToStructure (lParam, typeof (MouseHookStruct)); In this way the lParam this message structure parameters to hook,

Question: when I click on the button, the message structure in the hWnd value is always 0, this should not be click the control handle?
Pt coordinates x, y is a value, WindowFromPoint can get using this function is to control handle,

2. Shut down your software will be stuck
Global hooks in the software installed the mouse, click close the window, the program will be stuck, this is why, and how to handle?

CodePudding user response:

About the second question, saw this article
https://q.cnblogs.com/q/40041/Found strange indeed, Windows 7 32-bit system, areo button to close the window will not get stuck, basic theme, point closed, will be stuck,
  • Related