{"id":37753,"date":"2004-09-24T18:09:00","date_gmt":"2004-09-24T18:09:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/oldnewthing\/2004\/09\/24\/how-to-host-an-icontextmenu-part-4-key-context\/"},"modified":"2004-09-24T18:09:00","modified_gmt":"2004-09-24T18:09:00","slug":"how-to-host-an-icontextmenu-part-4-key-context","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20040924-00\/?p=37753","title":{"rendered":"How to host an IContextMenu, part 4 &#8211; Key context"},"content":{"rendered":"<p><P>\nAnother of the bugs you may have noticed in\n<A HREF=\"\/oldnewthing\/archive\/2004\/09\/22\/232836.aspx\">\nour first attempt at displaying the context menu to the user<\/A>\nis that the Delete command doesn&#8217;t alter its behavior depending\non whether you hold the shift key.  Recall that\n<A HREF=\"http:\/\/support.microsoft.com\/?kbid=126449\">\nholding the shift key changes the behavior of the Delete command,\ncausing it to delete a file immediately instead of moving it\nto the Recycle Bin<\/A>.\nBut in our sample program, it always offers to move the file\nto the Recycle Bin, even if you have the shift key down.\n<\/P>\n<P>\n(You can see the difference in the wording of the dialog\nand in the icon.  If the operation is to move the item into the\nRecycle Bin, you get a Recycle Bin icon and the text asks you\nto confirm sending the item to the Recycle Bin.  If the operation\nwill delete the item permanently, then you get an icon that shows\na file and a folder fading away and the text asks you to confirm\ndeleting the item.)\n<\/P>\n<P>\nTo convey this information to the context menu, you need to\npass the key states in\n<A HREF=\"http:\/\/msdn.microsoft.com\/library\/en-us\/shellcc\/platform\/shell\/reference\/structures\/cminvokecommandinfoex.asp\">\nthe CMINVOKECOMMANDINFOEX structure<\/A>.\n<\/P>\n<PRE>\n          CMINVOKECOMMANDINFOEX info = { 0 };\n          info.cbSize = sizeof(info);\n          info.fMask = CMIC_MASK_UNICODE | CMIC_MASK_PTINVOKE;\n          <FONT COLOR=\"blue\">if (GetKeyState(VK_CONTROL) &lt; 0) {\n            info.fMask |= CMIC_MASK_CONTROL_DOWN;\n          }\n          if (GetKeyState(VK_SHIFT) &lt; 0) {\n            info.fMask |= CMIC_MASK_SHIFT_DOWN;\n          }<\/FONT>\n<\/PRE>\n<P>\nMake this change and observe that the dialogs you get from\nthe Delete option now respect your shift key state.\n<\/P>\n<P>\n<STRONG>Warning<\/STRONG>: Before playing with this, make sure that\nyou have enabled delete confirmation warnings or you will end up\ndeleting your clock.avi file for real!<\/STRONG>\nIf you want to play around with the Delete option, you may want\nto tweak the program so it operates on a file you don&#8217;t mind losing.\n<\/P>\n<P>\n<STRONG>Exercise<\/STRONG>: There&#8217;s another place where key\ncontext influences the context menu, namely the convention that\nholding the shift key while right-clicking enables\n&#8220;extended verbs&#8221;.  These are verbs that are lesser-used and\ntherefore do not appear on the conventional context menu to\navoid creating clutter.  For homework, incorporate the\nextended verb convention into the sample program.\n<\/P>\n<P>\n[Sorry today&#8217;s entries are late.  Had problems connecting to the\nblog server.]\n<\/P><\/p>\n","protected":false},"excerpt":{"rendered":"<p>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&#8217;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 [&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-37753","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-code"],"acf":[],"blog_post_summary":"<p>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&#8217;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 [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/37753","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=37753"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/37753\/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=37753"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=37753"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=37753"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}