Re: Dynamic context menu from C#

So, my current strategy is to process the window messages for the
explorer window, grab the WM_INITMENUPOPUP one in order to get an
hmenu for the context menu, insert my items, and then handle the event
if the click happens to be on one of my items. I've managed to do all
but the last of those things.

In the MSDN article at,
it says
The following examples demonstrate how to use the IOleCommandTarget
(CGID_ShellDocView command group) to add and remove custom menu
options from the standard Internet Explorer context menu:

In this example, they implement IDocHostUIHandler and reach into the
IE DLL to grab resources and reconstruct the original context menu
from there. Obviously this is a poor strategy, as the article itself
shows with the warning that these resources have changed places in
IE7. But the interesting part is this:
// Send selected shortcut menu item command to shell
LRESULT lr = ::SendMessage(hwnd, WM_COMMAND, iSelection, NULL);
So after calling TrackPopupMenu, they send a WM_COMMAND to the shell
notifying it of which command was selected. Presumably if they had
inserted their own commands (as in the subsequent section entitled
"Appending Extensions to Your Custom Menu"), they would simply handle
that situation themselves by checking the iSelection variable first.

However, I don't want to override ShowContextMenu, because I want IE
to show its own context menu, doing whatever it is it wants to do with
it. But I figured that since the example sends a WM_COMMAND message,
IE would send its own WM_COMMAND messages when the menu items on its
menu are clicked. However, this does not appear to be the case at all.
I used Spy++ to examine all messages to the system looking
specifically for WM_COMMAND and WM_MENUCOMMAND messages, and found
none of them sent when an item is selected from the standard IE menu.

So how is it that I can run my own function when my menu items are
selected while still allowing IE to display its own menu?