Date: | October 27, 2003 / year-entry #110 |
Tags: | code |
Orig Link: | https://blogs.msdn.microsoft.com/oldnewthing/20031027-00/?p=42023 |
Comments: | 2 |
Summary: | Explorer does it. Now you can too. It's a simple matter of detecting a context menu on the caption icon and displaying a custom context menu. Here are the simple changes to our scratch program to display a rather pointless one-item menu. // Add to WndProc case WM_CONTEXTMENU: if (lParam != -1 && SendMessage(hwnd, WM_NCHITTEST,... |
Explorer does it. Now you can too. It's a simple matter of detecting a context menu on the caption icon and displaying a custom context menu. Here are the simple changes to our scratch program to display a rather pointless one-item menu. // Add to WndProc case WM_CONTEXTMENU: if (lParam != -1 && SendMessage(hwnd, WM_NCHITTEST, 0, lParam) == HTSYSMENU) { HMENU hmenu = CreatePopupMenu(); if (hmenu) { AppendMenu(hmenu, MF_STRING, 1, TEXT("Custom menu")); TrackPopupMenu(hmenu, TPM_LEFTALIGN | TPM_TOPALIGN | TPM_RIGHTBUTTON, GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam), 0, hwnd, NULL); DestroyMenu(hmenu); } return 0; } break;
When we receive a Of course, in real life, you probably would use LoadMenu to get the menu so you could just use the resource editor to create it, rather than creating it in code. |
Comments (2)
Comments are closed. |
I’m a little late to this party, but what exactly is the caption icon?
The icon in the top left corner of an app’s window, next to the caption. You’ll notice that the context menu for most of them looks exactly like the context menu for the app in the taskbar, but IE and Explorer do custom menus there.