Apply Setwineventhook to intercept Windows events

Source: Internet
Author: User

With SetWindowsHookEx, you can intercept messages in Windows, but for more advanced Windows events such as pop-up menu events, Atl+tab switching events, and so on, you can intercept them with Setwineventhook.

The hooks created by Setwineventhook are also divided into both in-process and out-of-process, in-process hooks that are efficient but must be in the form of DLLs because they need to be mapped to other processes. In this demo I use out-of-process hooks to intercept all events.

The hook routines are as follows:

650) this.width=650; "src="/img/fz.gif "alt=" Copy Code "style=" border:0px; "/>

VOID CALLBACK Wineventsproc (Hwineventhook Hwineventhook, DWORD Dwevent, HWND hwnd, long idobject, Long Idchild, DWORD DwE Ventthread, DWORD Dwmseventtime)
{
Switch(dwevent)
{
CaseEvent_system_switchstart:
Atlmessagebox (NULL, _t ("ALT + TAB start") );
Break;

CaseEvent_system_switchend:
Atlmessagebox (NULL, _t ("ALT + TAB End") );
Break;

CaseEvent_system_menupopupstart:
Atlmessagebox (NULL, _t ("pop-up menu start") );
Break;

CaseEvent_system_menupopupend:
Atlmessagebox (NULL, _t ("pop-up menu start") );
Break;

650) this.width=650; "src=" Http://www.cnblogs.com/Images/dot.gif "style=" border:0px; "/>

}
}

650) this.width=650; "src="/img/fz.gif "alt=" Copy Code "style=" border:0px; "/>

Install out-of-process hooks (intercept all events for all processes):

Hwineventhook Hhook =:: Setwineventhook (Event_min, Event_max, NULL, Wineventsproc, 0, 0, Winevent_ou Tofcontext);

Be sure to uninstall the hook when you're done with it:

:: Unhookwinevent (Hhook);


Apply Setwineventhook to intercept Windows events

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.