RegisterShellHookWindow function (winuser.h)

[This function is not intended for general use. It may be altered or unavailable in subsequent versions of Windows.]

Registers a specified Shell window to receive certain messages for events or notifications that are useful to Shell applications.

The event messages received are only those sent to the Shell window associated with the specified window's desktop. Many of the messages are the same as those that can be received after calling the SetWindowsHookEx function and specifying WH_SHELL for the hook type. The difference with RegisterShellHookWindow is that the messages are received through the specified window's WindowProc and not through a call back procedure.


BOOL RegisterShellHookWindow(
  [in] HWND hwnd


[in] hwnd

Type: HWND

A handle to the window to register for Shell hook messages.

Return value

Type: BOOL

TRUE if the function succeeds; otherwise, FALSE.


As with normal window messages, the second parameter of the window procedure identifies the message as a WM_SHELLHOOKMESSAGE. However, for these Shell hook messages, the message value is not a pre-defined constant like other message IDs such as WM_COMMAND. The value must be obtained dynamically using a call to RegisterWindowMessage as shown here:


This precludes handling these messages using a traditional switch statement which requires ID values that are known at compile time. For handling Shell hook messages, the normal practice is to code an If statement in the default section of your switch statement and then handle the message if the value of the message ID is the same as the value obtained from the RegisterWindowMessage call.

The following table describes the wParam and lParam parameter values passed to the window procedure for the Shell hook messages.

wParam lParam
HSHELL_WINDOWACTIVATED A handle to the activated window.
HSHELL_RUDEAPPACTIVATED A handle to the activated window.
HSHELL_WINDOWREPLACING A handle to the window replacing the top-level window.
HSHELL_WINDOWREPLACED A handle to the window being replaced.
HSHELL_WINDOWCREATED A handle to the window being created.
HSHELL_WINDOWDESTROYED A handle to the top-level window being destroyed.
HSHELL_TASKMAN Can be ignored.
HSHELL_REDRAW A handle to the window that needs to be redrawn.
HSHELL_FLASH A handle to the window that needs to be flashed.
HSHELL_ENDTASK A handle to the window that should be forced to exit.
HSHELL_APPCOMMAND The APPCOMMAND which has been unhandled by the application or other hooks. See WM_APPCOMMAND and use the GET_APPCOMMAND_LPARAM macro to retrieve this parameter.
HSHELL_MONITORCHANGED A handle to the window that moved to a different monitor.

This function was not included in the SDK headers and libraries until Windows XP with Service Pack 1 (SP1) and Windows Server 2003. If you do not have a header file and import library for this function, you can call the function using LoadLibrary and GetProcAddress.


Minimum supported client Windows 2000 Professional [desktop apps only]
Minimum supported server Windows 2000 Server [desktop apps only]
Target Platform Windows
Header winuser.h (include Windows.h)
Library User32.lib
DLL User32.dll

See also



Other Resources




Using Messages and Message Queues