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?



Relevant Pages

  • Re: [RFC/PATCH 0/22] W1: sysfs, lifetime and other fixes
    ... >> which is managed by bus master dirver, but also some logic over it, ... Why do you think caller is in process context? ... Control thread was created to process that work, ... Using connector for exaple you may send command REMOVE_*, ...
  • Re: SIGINT for Emacs/gdb in a terminal and background processes
    ... In the context of shells, ... "background command" is used to refer to any command started ... SIGINT to other processes. ... When xclock is started from the shell, ...
  • Re: And So The Question Is......
    ... that accessing a given command from a ... context menu is harder to hit accurately. ... certainly factors other than pure efficiency that drive most peoples' ... person to finally acquire contradictory data. ...
  • Re: there are too many context menues
    ... I am refering to the shy toolbar. ... 'clickless' command. ... put an arrow pointing up on the right click context menue that ... out the shy menue. ...
  • Re: Why doesnt foreach return a value
    ... Every Tcl command is implemented as a C level function. ... What we want at the script level is the ... What changes occur is very specific to the context. ...