These days, I have been confused by global hooks under win7 for a long time. I always thought that there was no change in global hooks under win7 and that my code was wrong .... today, I was awakened by my colleagues when I was crazy. Originally, TMD Microsoft hooked the global hook of win7 to a different one !! I checked it on the Internet. That's it ~~ Another old habit of inertial thinking has been made. Let's write it down first and verify it tomorrow...
Thanks to the original author!
Due to uipi restrictions in win7, the high-permission process cannot receive messages from the bottom-permission process. Therefore, messages cannot be received during window message hook, the solution is to call changewindowmessagefilterex before calling setwindowshookex. This function modifies the uipi message filtering settings in the specified window. The prototype is as follows:
Bool winapi changewindowmessagefilterex (hwnd, uint message, DWORD action, pchangefilterstruct); the first parameter changes the window sentence structure, and the second parameter filters messages, the action to be executed by the third parameter. The fourth parameter points to a changefilterestruct structure. This structure is used to return the Modification result. In addition, changewindowmessagefilterex needs to be exported from USER32
As follows:
Bool callchangewindowmessagefilter (hwnd, uint nmsg, DWORD dwaction, pchangefilterstruct chfit)
{
Typedef bool (winapi * lpfunc) (hwnd, uint, DWORD, pchangefilterstruct );
Hmodule hlib = loadlibrarya ("user32.dll ");
If (hlib)
{
Lpfunc func = (lpfunc) getprocaddress (hlib, "changewindowmessagefilterex ");
If (func & chfit)
Return func (hwnd, nmsg, dwaction, chfit );
}
Return false;
}
If you want to set a window message constructor, you can call it as follows:
Changefilterstruct chfit = {sizeof (changefilterstruct )};
Changewindowmessagefilter (hwnd, wm_copydata, msgflt_allow, & chfit );
G_hhookcbtmsg = setwindowshookexw (wh_cbt, cbtproc, hdll, 0 );
In this way, your process can obtain messages from the underlying permission process.