SetWindowsHookEx

  HHOOK SetWindowsHookEx(idHook, hkprc, hMod, dwThreadID)    
  int idHook; /* type of hook to install */
  HOOKPROC hkprc; /* address of hook procedure */
  HANDLE hMod; /* handle of application instance */
  DWORD dwThreadID; /* thread to install hook for */

The SetWindowsHookEx function installs an application-defined hook procedure into a hook chain. An application installs a hook procedure to monitor the system for certain types of events. A hook procedure can monitor events associated with either a specific thread or with all threads in the system.

Parameters

idHook

Specifies the type of hook procedure to be installed. This parameter can be one of the following values:

Value Meaning

WH_CALLWNDPROC  
  Installs a window-procedure filter. For more information, see the description of the CallWndProc callback function.
WH_CBT  
  Installs a computer-based training (CBT) filter. For more information, see the description of the CBTProc callback function.
WH_DEBUG  
  Installs a debugging filter. For more information, see the description of the DebugProc callback function.
WH_GETMESSAGE  
  Installs a message filter. For more information, see the description of the GetMsgProc callback function.
WH_JOURNALPLAYBACK  
  Installs a journaling playback filter. For more information, see the description of the JournalPlaybackProc callback function.
WH_JOURNALRECORD  
  Installs a journaling record filter. For more information, see the description of the JournalRecordProc callback function.
WH_KEYBOARD  
  Installs a keyboard filter. For more information, see the description of the KeyboardProc callback function.
WH_MOUSE  
  Installs a mouse-message filter. For more information, see the description of the MouseProc callback function.
WH_MSGFILTER  
  Installs a message filter. For more information, see the description of the MessageProc callback function.
WH_SHELL  
  Installs a shell-application filter. For more information, see the description of the ShellProc callback function.
WH_SYSMSGFILTER  
  Installs a system-wide message filter. For more information, see the description of the SysMsgProc callback function.

hkprc

Points to the hook procedure. If the dwThreadID parameter is 0 or specifies the identifier of a thread created by a different process, the hkprc parameter must point to a hook procedure in a dynamic-link library (DLL). Otherwise, the hkprc parameter can point to a hook procedure in the code associated with the current process.

hMod

Identifies the DLL containing the hook procedure pointed to by the hkprc parameter. The hMod parameter should be set to NULL if the dwThreadID parameter specifies a thread created by the current process and the the hook procedure is within the code associated with the current process.

dwThreadID

Specifies the identifier of the thread with which the hook procedure is to be associated. If this parameter is 0, the hook procedure is associated with all existing threads.

Return Value

The return value is the handle of the hook procedure if the function is successful. Otherwise, the return value is NULL.

Comments

An error may occur if the hMod parameter is NULL and the dwThreadId parameter is 0 or specifies the identifier of a thread created by another process.

See Also

CallNextHookEx, SetWindowsHook, UnhookWindowsHookEx