{"id":37693,"date":"2004-09-30T07:00:00","date_gmt":"2004-09-30T07:00:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/oldnewthing\/2004\/09\/30\/how-to-host-an-icontextmenu-part-7-invoking-the-default-verb\/"},"modified":"2004-09-30T07:00:00","modified_gmt":"2004-09-30T07:00:00","slug":"how-to-host-an-icontextmenu-part-7-invoking-the-default-verb","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20040930-00\/?p=37693\/","title":{"rendered":"How to host an IContextMenu, part 7 &#8211; Invoking the default verb"},"content":{"rendered":"<p><P>\n<A href=\"http:\/\/blogs.msdn.com\/oldnewthing\/archive\/2004\/09\/20\/231739.aspx\">\nWhen we last left our hero<\/A>,\nwe were wondering how to invoke the default verb programmatically.\nNow that we&#8217;ve learned a lot about how IContextMenu is used\nin the interactive case, we can use that information to guide\nus in its use in the noninteractive case.\n<\/P>\n<P>\nThe key here is using the HMENU to\n<A href=\"http:\/\/blogs.msdn.com\/oldnewthing\/archive\/2004\/09\/29\/235737.aspx\">\nidentify the default menu item<\/A>\nand just invoke it directly.\nGo back to the program from part&nbsp;1 where we left it and\nmake these changes:\n<\/P>\n<PRE>\nvoid OnContextMenu(HWND hwnd, HWND hwndContext, UINT xPos, UINT yPos)\n{\n  IContextMenu *pcm;\n  if (SUCCEEDED(GetUIObjectOfFile(hwnd, L&#8221;C:\\\\Windows\\\\clock.avi&#8221;,\n                   IID_IContextMenu, (void**)&amp;pcm))) {\n    HMENU hmenu = CreatePopupMenu();\n    if (hmenu) {\n      if (SUCCEEDED(pcm-&gt;QueryContextMenu(hmenu, 0,\n                             SCRATCH_QCM_FIRST, SCRATCH_QCM_LAST,\n                             CMF_NORMAL))) {\n        <FONT COLOR=\"blue\">UINT id = GetMenuDefaultItem(hmenu, FALSE, 0);\n        if (id != (UINT)-1) {<\/FONT>\n          CMINVOKECOMMANDINFO info = { 0 };\n          info.cbSize = sizeof(info);\n          info.hwnd = hwnd;\n          <FONT COLOR=\"blue\">info.lpVerb = MAKEINTRESOURCEA(id &#8211; SCRATCH_QCM_FIRST);<\/FONT>\n          pcm-&gt;InvokeCommand(&amp;info);\n        <FONT COLOR=\"blue\">}<\/FONT>\n      }\n      DestroyMenu(hmenu);\n    }\n    pcm-&gt;Release();\n  }\n}\n<\/PRE>\n<P>\nWe added the call to\n<A HREF=\"http:\/\/msdn.microsoft.com\/library\/en-us\/winui\/WinUI\/WindowsUserInterface\/Resources\/Menus\/MenuReference\/MenuFunctions\/GetMenuDefaultItem.asp\">\nGetMenuDefaultItem<\/A> to obtain the default menu item\nand then set the verb in the form of a menu identifier offset.\n(I.e., we subtract the starting point we passed to\n<A HREF=\"http:\/\/msdn.microsoft.com\/library\/en-us\/shellcc\/platform\/shell\/reference\/ifaces\/icontextmenu\/QueryContextMenu.asp\">\nIContextMenu::QueryContextMenu<\/A>.)\n<\/P>\n<P>\nThis code works but could be better.\nNext time, we&#8217;ll make a minuscule tweak that improves the performance.\n<\/P><\/p>\n","protected":false},"excerpt":{"rendered":"<p>When we last left our hero, we were wondering how to invoke the default verb programmatically. Now that we&#8217;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 [&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-37693","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-code"],"acf":[],"blog_post_summary":"<p>When we last left our hero, we were wondering how to invoke the default verb programmatically. Now that we&#8217;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 [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/37693","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=37693"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/37693\/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=37693"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=37693"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=37693"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}