The indexMenu, idCmdFirst and idCmdLast parameters to
the IContextMenu::QueryContextMenu method
allow you, the host, to control where in the context menu
the IContextMenu will insert its commands.
To illustrate this, let's put two bonus commands on our
context menu, with the boring names "Top" and "Bottom".
We need to reserve some space in our ...
There is a small improvement that can be made to
to the program we wrote last time.
It involves taking advantage of the last parameter to
the IContextMenu::QueryContextMenu method:
CMF_DEFAULTONLY
This flag is set when the user is activating the default action,
typically by double-clicking.
This flag provides a hint for the shortcut menu exte...
When we last left our hero,
we were wondering how to invoke the default verb programmatically.
Now that we've learned a lot about how IContextMenu is used
in the interactive case, we can use that information to guide
us in its use in the noninteractive case.
The key here is using the HMENU to
identify the default menu item
and just invoke it d...
One of the subtleties of context menus is showing help in the
status bar. Now, the program we've been developing doesn't
have a status bar, so we'll fake it by putting the help text
in the title bar.
The key method for this task is
IContextMenu::GetCommandString, which
allows communication with a context menu handler about the
verbs in the men...
One bug that was called out immediately in
our first attempt at displaying the context menu to the user
is that the Open With and Send To submenus don't work.
The reason for this is that these submenus are delay-generated
(which explains why they don't contain anything interesting when
you expand them) and owner-drawn (which you can't notice ye...
Another of the bugs you may have noticed in
our first attempt at displaying the context menu to the user
is that the Delete command doesn't alter its behavior depending
on whether you hold the shift key. Recall that
holding the shift key changes the behavior of the Delete command,
causing it to delete a file immediately instead of moving it
to ...
One of the bugs you may have noticed in
our first attempt at displaying the context menu to the user
is that the Properties dialog doesn't show up at the point you
clicked. The Properties dialog isn't psychic; it doesn't know
where the original mouse click occurred. You have to tell it.
CMINVOKECOMMANDINFOEX info = { 0 };
...
Instead of
invoking a fixed verb,
we'll ask the user to choose
from the context menu and invoke the result.
Make these changes to the OnContextMenu function:
#define SCRATCH_QCM_FIRST 1
#define SCRATCH_QCM_LAST 0x7FFF
#undef HANDLE_WM_CONTEXTMENU
#define HANDLE_WM_CONTEXTMENU(hwnd, wParam, lParam, fn) \
((fn)((hwnd), (HWND)(wParam), GET...
Before we continue with our IContextMenu discussion,
I need to take a little side trip and discuss the subtleties
of
the WM_CONTEXTMENU message.
First, a correction to the existing <windowsx.h> header file:
#undef HANDLE_WM_CONTEXTMENU
#define HANDLE_WM_CONTEXTMENU(hwnd, wParam, lParam, fn) \
((fn)((hwnd), (HWND)(wParam), GET_X_LPAR...