This article is a stub, and incomplete. You can help by contributing to it.

Shellhook Library

For some applications such as taskbars or virtual window managers it could be important to get notified if applications are started/closed or if applications are changing their position/state. Implementing this must be done with a seperate dll which registers a global hook on shell messages. SharpE already has a shellhook dll which can be used by all components and modules/plugins for receiving shell messages. Due to some limitations only 5 application can use this shell hook dll at the same time. So make sure to only use the shell hooks if you really need them. Also make sure to unregister the shell hook if you do not need it anymore.

Dll header file: svn\common\libraries\ShellHook\ShellHook.pas

To use the shellhook.dll insert the shellhook.pas header file into your project.
Then call:


glacialfury: What do each of these do, and what are they used for?

  SHSetMainHandle(windowhandle);
  SHSetCallBack(@dllcallback);
  SHSetHook;

glacialfury: Following needs more clarification. Does it need anything in the procedure? What is this procedure used for? What does it do? Is it even necessary?

@dllcallback can be an simple function like:

  procedure dllcallback(handle : hwnd);
  begin
  end;

The window specified in SHSetMainHandle will now receives a WM_SHELLHOOK message.
The message.lparam value contains the shell message type, it can be:

  M_NEWTASK (HSHELL_WINDOWCREATED)
  M_DELTASK (HSHELL_WINDOWDESTROYED)
  M_ACTIVATETASK (HSHELL_WINDOWACTIVATED)
  M_CAPTIONUPDATE (HSHELL_REDRAW - lparam = false)
  M_TASKFLASHING (HSHELL_REDRAW - lparam = true)
  M_GETMINRECT (HSHELL_GETMINRECT)

The message.wparam value contains the handle to the window executing the shell message.

To unregister your shell hook call SHUnsetHook.


SharpBar? modules which need shell hook notification are NOT ALLOWED to use the shellhook.dll directly. Modules must register itself with the SharpBar? host application to get shell notifications - those modules will then get the same shell notification message from their SharpBar? host application.
To register a module for receiving shell notifications send the following window message:

  PostMessage(BarWnd,WM_REGISTERSHELLHOOK,ModuleID,0);

After a module is registered as to receive shell notifications from the SharpBar? it will receive the same WM_ShellHook message as described above.
To unregister a module from receiving shell notifications send:

  PostMessage(BarWnd,WM_UNREGISTERSHELLHOOK,ModuleWndowHandle,0);

See MSDN Library for more details on the HSHELL_ messages: MSDN Library link