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