window message:
When a child window of an inactive top-level window or inactive top-level window is clicked, a wm_mouseactivate message is first generated and passed to the top-level window. When the window receives the message, it is referred to defwindowproc for processing.
wm_mouseactivate messages can be responded to in the following ways:
Ma_activate activates the window and receives mouse messages
Ma_noactivate does not activate the window to receive mouse messages
Ma_activatendeat activates the window, ignoring the mouse message
Ma_noactivateandeat does not activate the window, ignoring the mouse message
protected override void WndProc (ref message M)
{
Base. WndProc (ref m);
const int ma_noactivate = 3;
const int wm_mouseactivate = 0x21;
if (m.msg = = wm_mouseactivate)
M.result = (IntPtr) ma_noactivate;
}
If the window is activated by the mouse click and the Wm_mouseactivate returns Ma_activate, the system message Wm_activateapp (WParam is identified as active) is received, and then the Wm_activate message is received (WParam is identified as active) , and then there is wm_setfocus news. But before this process, the window that originally had the focus would start with the following event: Wm_activate (WParam is identified as inactivated)-> Wm_activateapp (WParam is identified as inactivated)-> Wm_killfocus.
If the window is activated by the mouse, the return of the Wm_noactivateandeat window will not receive wm_setfocus, which will make the current window has no focus, and the object on the window can not get the mouse message, including click. To make the original window not lose focus, you can capture the Wm_ncactivate message on the original window, and when WParam = 0 o'clock, set it back to 1, that is, WParam = 1. Then the focus of the original window is still preserved.
protected override void WndProc (ref message M)
{
const int wm_ncactivate = 0x86;
if (m.msg = = Wm_ncactivate && M.wparam = = IntPtr.Zero)
M.wparam = (IntPtr) 1;
Base. WndProc (ref m);
}
gets the high and low values of the WParam:
Fetch DWORD unsigned integer Low:
(IntPtr) LoWord = (IntPtr) WParam & 0xFFFF;
Fetch DWORD unsigned integer High:
(IntPtr) HiWord = (IntPtr) wParam >> & 0xFFFF;
Wm_mouseactivate = &h21 When the window is activated with the mouse
Wm_activateapp = &h1c ' window ready to be activated or ready to lose activation after the message
Wm_ Ncactivate = &h86 ' Windows non-client area when the message
Wm_activate = &h6 window is ready to be activated or ready to lose activation status when ready to be activated or ready to lose activation state
Wm_setfocus = &h7 Message when the window gets focus (such as when the window is minimized)
Wm_killfocus = &h8 window loses focus when