The Old New Thing

How to host an IContextMenu, part 6 – Displaying menu help

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 ...

How to host an IContextMenu, part 5 – Handling menu messages

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 ...

How to host an IContextMenu, part 4 – Key context

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 ...

How to host an IContextMenu, part 3 – Invocation location

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...

How to host an IContextMenu, part 2 – Displaying the context menu

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...

Pitfalls in handling the WM_CONTEXTMENU message

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), ...

How to host an IContextMenu, part 1 – Initial foray

Most documentation describes how to plug into the shell context menu structure and be a context menu provider. If you read the documentation from the other side, then you also see how to host the context menu. (This is the first of an eleven-part series with three digressions. Yes, eleven parts—sorry for all you folks who are in it ...

What happens when you specify RegexOptions.ECMAScript?

The flag changes the behavior of .NET regular expressions. One of the changes I had discussed earlier was with respect to matching digits. For those who want to know more, a summary of the differences is documented in MSDN under the devious title "ECMAScript vs. Canonical Matching Behavior". Apparently some people had trouble finding that...

Interlocked operations don’t solve everything

Interlocked operations are a high-performance way of updating DWORD-sized or pointer-sized values in an atomic manner. Note, however, that this doesn't mean that you can avoid the critical section. For example, suppose you have a critical section that protects a variable, and in some other part of the code, you want to update the variable ...