Tip: If you want to set a system-level Hook, the hook function must be in the DLL.
Setwindowshookex (idhook: integer; {hook type} lpfn: tfnhookproc; {function pointer} hmod: hinst; {module (exe, DLL) handle containing hook functions; generally hinstance; for the current thread, it can be 0} dwthreadid: DWORD {associated thread; Use getcurrentthreadid to obtain the current thread; 0 to indicate system-level hook}): hhook; {return hook handle; 0 indicates failure} // hook type idhook option: wh_msgfilter =-1; {Thread level; intercept message between user and control} wh_journalrecord = 0; {system level; record all input messages sent from the message queue in the message queue, which occurs when the message is cleared from the queue; can be used for macro record} wh_journalplayback = 1; {system level; playback of messages recorded by wh_journalrecord, that is, these messages are re-sent to the Message Queue} wh_keyboard = 2; {system level or line level; the Keyboard Message is intercepted} wh_getmessage = 3; {system level or line level; intercepted messages sent from the Message Queue} wh_callwndproc = 4; {system level or line level; intercepted messages sent to the target window, occurred when sendmessage was called} wh_cbt = 5; {system level or line level; basic system messages are intercepted, such as window creation, activation, closing, maximum minimization, and moving.} wh_sysmsgfilter = 6; {system level; intercept messages between users and controls in the system} wh_mouse = 7; {system level or line level; intercept mouse messages} wh_hardware = 8; {system level or line level; intercepted messages from non-standard hardware (non-mouse or keyboard)} wh_debug = 9; {system level or line level; called before calling other hooks for debugging hooks} wh_shell = 10; {system-level or thread-level; intercepted messages sent to the shell application} wh_foregroundidle = 11; {system-level or thread-level; called when the program's front-end thread is idle} wh_callwndprocret = 12; {system-level or thread-level; intercepted messages processed in the target window. After sendmessage is called,} response unhookwindowshookex (HHK: hhook {hook handle}): bool; {true/false}
--------------------------------------------------------------------------------
From http://www.cnblogs.com/del/archive/2008/02/25/1080541.html
Http://www.cnblogs.com/del/archive/2008/02/25/1080516.html