{"id":37813,"date":"2004-09-21T07:00:00","date_gmt":"2004-09-21T07:00:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/oldnewthing\/2004\/09\/21\/pitfalls-in-handling-the-wm_contextmenu-message\/"},"modified":"2004-09-21T07:00:00","modified_gmt":"2004-09-21T07:00:00","slug":"pitfalls-in-handling-the-wm_contextmenu-message","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20040921-00\/?p=37813","title":{"rendered":"Pitfalls in handling the WM_CONTEXTMENU message"},"content":{"rendered":"<p><P>\nBefore we continue with our IContextMenu discussion,\nI need to take a little side trip and discuss the subtleties\nof\n<A HREF=\"http:\/\/msdn.microsoft.com\/library\/en-us\/winui\/WinUI\/WindowsUserInterface\/Resources\/Menus\/MenuReference\/MenuMessages\/WM_CONTEXTMENU.asp\">\nthe WM_CONTEXTMENU message<\/a>.\n<\/P>\n<P>\nFirst, a correction to the existing &lt;windowsx.h&gt; header file:\n<\/P>\n<PRE>\n#undef HANDLE_WM_CONTEXTMENU\n#define HANDLE_WM_CONTEXTMENU(hwnd, wParam, lParam, fn) \\\n    ((fn)((hwnd), (HWND)(wParam), <FONT COLOR=\"blue\">GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam)<\/FONT>), 0L)\n<\/PRE>\n<P>\nApparently, HANDLE_WM_CONTEXTMENU was overlooked when the\n&lt;windowsx.h&gt; header file gained multimonitor support.\n<\/P>\n<P>\nThe second subtlety of the WM_CONTEXTMENU message is the\nrecognition that context menus can be invoked from the keyboard,\nnot just by the mouse.  If you have a 104-key keyboard, you\nwill probably have a menu key to the right of your space bar.\n(Laptop owners: You&#8217;re on your own.  Laptop keyboards are hardly\nstandardized.)  Alternatively, you can type Shift+F10 to get\nthe same effect.\n<\/P>\n<P>\nWhen the user invokes a context menu from the keyboard, the\nx and y coordinates are both -1.  In this case, you should\ndisplay the context menu for the currently-selected item\n(or items, if a multiple selection is active).\nIf you miss this detail, then you will end up hit-testing\nagainst (-1, -1) and probably not find anything.\n<\/P>\n<P>\nOkay, now that these remarks on the WM_CONTEXTMENU message are\nout of the way, we can return to our discussion of the\nIContextMenu interface\n<A href=\"http:\/\/blogs.msdn.com\/oldnewthing\/archive\/2004\/09\/22\/232836.aspx\">\nnext time<\/A>.\n<\/P><\/p>\n","protected":false},"excerpt":{"rendered":"<p>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 &lt;windowsx.h&gt; header file: #undef HANDLE_WM_CONTEXTMENU #define HANDLE_WM_CONTEXTMENU(hwnd, wParam, lParam, fn) \\ ((fn)((hwnd), (HWND)(wParam), GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam)), 0L) Apparently, HANDLE_WM_CONTEXTMENU was overlooked when the &lt;windowsx.h&gt; header file gained [&hellip;]<\/p>\n","protected":false},"author":1069,"featured_media":111744,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[25],"class_list":["post-37813","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-code"],"acf":[],"blog_post_summary":"<p>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 &lt;windowsx.h&gt; header file: #undef HANDLE_WM_CONTEXTMENU #define HANDLE_WM_CONTEXTMENU(hwnd, wParam, lParam, fn) \\ ((fn)((hwnd), (HWND)(wParam), GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam)), 0L) Apparently, HANDLE_WM_CONTEXTMENU was overlooked when the &lt;windowsx.h&gt; header file gained [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/37813","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/users\/1069"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/comments?post=37813"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/37813\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media\/111744"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media?parent=37813"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=37813"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=37813"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}