Address: http://www.zdexe.com/program/201004/578.html
To take advantage of a participant type of Hook, the developer provides a hook procedure and uses the setwindowshookex function to install it into the chain associated with the hook. A hook procedure must have the following syntax:
To take advantage of a specific type of Hook, the developer provides the hook Child Program. You can use the setwindowshookex method to install the hook program to the hook linked list associated with the hook. The hook procedure must have the following syntax:
LRESULT CALLBACK HookProc
(
int nCode,
WPARAM wParam,
LPARAM lParam
);
HookprocIs a placeholder for an application-defined name.
Hookproc is a placeholder for the name defined by the application. That is, hookproc is the name defined by the application.
TheNcodeParameter is a hook code that the hook procedure uses to determine the action to perform. the value of the hook Code depends on the type of the hook; each type has its own characteristic set of hook codes. the values ofWparamAndLparamParameters depend on the hook code, but they typically contain information about a message that was sent or posted ..
Parameter ncode: hook code, which determines the action to perform. The value depends on the hook type. Each type has its own set of hook code.
Parameters wparam andLparamThe value depends on the hook code. However, it generally contains information about the sent or transmitted messages.
The setwindowshookex function always installa hook procedure at the beginning of a hook chain. when an event occurs that is monitored by a participant type of hook, the system callthe procedure at the beginning of the hook chain associated with the hook. each hook procedure in the chain determines whether to pass the event to the next procedure. A hook procedure passes an event to the next procedure by calling the callnexthookex function.
Method setwindowshookex always installs the hook program at the beginning of the hook chain. When an event monitored by a hook type occurs, the system calls the hook child program associated with the hook at the beginning of the hook list. The hooks in each hook linked list determine whether to pass the event to the next hook. The hook program sends an event to the next hook program by calling callnexthookex.
Note that the hook procedures for some types of hooks can only monitor messages. The system passes messages to each hook procedure, regardless of whether a special procedure CILS callnexthookex.
Note: Some Types of hooks can only monitor messages. No matter whether a special hook program calls the callnexthookex method, the system will send messages to each hook,
AGlobal hookMonitors messages for all threads in the same desktop as the calling thread.Thread-specific hookMonitors messages for only an individual thread. A global hook procedure can be called in the context of any application in the same desktop as the calling thread, so the procedure must be in a separate dynamic-link library (DLL) module. A thread-specific hook procedure is called only in the context of the associated thread. if an application installa hook procedure for one of its own threads, the hook procedure can be in either the same module as the rest of the application's code or in a DLL. if the application installa hook procedure for a thread of a different application, the procedure must be in a DLL. for information, see dynamic-link libraries.
The above literal meaning is: The Global hook monitors all the thread messages used as call threads on the same desktop. Thread hooks only monitor messages of a single thread. The global hook sub-program can be called in the context of any application under the desktop. Therefore, the hook sub-program must be in a separate dynamic link library DLL. (Note: In DLL, it can be mapped to the memory and called by all programs ). The hook program of the thread Hook can only be called in the context of the thread. If an application installs a hook program in its own thread, the hook program can be placed in this module, other parts of the application code, and DLL. If the application installs the hook program for another different application, the hook program must be placed in the DLL. Refer to DLL for more information.
I personally think it is hard to understand. Better understanding: see the last part of hook first contact (2. Haha.
Note you should use global hooks only for debugging purposes; otherwise, you should avoid them. Global hooks hurt system performance and cause conflicts with other applications that implement the same type of global hook.
Note: You should only use global hooks for debugging purposes; otherwise, do not use them. Global hooks sacrifice system performance. There will also be conflicts between applications that use the same type of global hooks.
Hook tutorial-principle (4): hook procedure