windowsshellwinapishell-extensionswindow-messages

How to intercept a window message in a shell extension


I have a shell extension that needs to reload its configuration when a specific window message (custom message registered with RegisterWindowMessage) is broadcasted by another application.

I tried several approaches to intercept the message:

Is there a reliable way to receive a window message in a shell extension?

A window message initially seemed to be the easiest way to notify the shell extension, but if you think another mechanism would be more appropriate, I'm open to suggestions.


Solution

  • Create a hidden window and listen for the message in its window procedure.

    1. Register a window class that has default values for all the fields apart from the window procedure and class name. You don't need to specify anything else in the window class since the window will never be visible.
    2. When you create the window, pass 0 for the window style. Specifically exclude WS_VISIBLE.
    3. Pass 0 for the WndParent when you create the window. This will make it a top level window and so eligible to receive broadcast messages.