Windows Hook messages cannot be received in win7

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.