SetWindowsHook

2.x

  HHOOK SetWindowsHook(idHook, hkprc)    
  int idHook; /* type of hook to install */
  HOOKPROC hkprc; /* filter function procedure-instance address */

The SetWindowsHook function is obsolete but has been retained for backward compatibility with Windows versions 3.0 and earlier. Applications written for Windows version 3.1 should use the SetWindowsHookEx function.

The SetWindowsHook function installs an application-defined hook function into a hook chain.

Parameters

idHook

Specifies the type of hook 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_HARDWARE Installs a nonstandard hardware-message filter. For more information, see the description of the HardwareProc 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

Specifies the procedure-instance address of the application-defined hook procedure to be installed.

Return Value

The return value is a handle of the installed hook, if the function is successful. Otherwise, it is NULL.

Comments

Before terminating, an application must call the UnhookWindowsHook function to free system resources associated with the hook.

The WH_CALLWNDPROC hook affects system performance. It is supplied for debugging purposes only.

The system hooks are a shared resource. Installing a hook affects all applications. Most hook functions must be in libraries. The only exception is WH_MSGFILTER, which is task-specific. System hooks should be restricted to special-purpose applications or to use as a development aid during debugging of an application. Libraries that no longer need the hook should remove the filter function.

To install a filter function, the SetWindowsHook function must receive a procedure-instance address of the function and the function must be exported in the library's module-definition file. A task must use the MakeProcInstance function to get a procedure-instance address. A dynamic-link library can pass the procedure address directly.

See Also

DefHookProc, GetProcAddress, MakeProcInstance, MessageBox, PeekMessage, PostMessage, SendMessage, SetWindowsHookEx, UnhookWindowsHook