{"id":7033,"date":"2012-07-27T07:00:00","date_gmt":"2012-07-27T07:00:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/oldnewthing\/2012\/07\/27\/psychic-debugging-why-your-icontextmenuinvokecommand-never-gets-called\/"},"modified":"2012-07-27T07:00:00","modified_gmt":"2012-07-27T07:00:00","slug":"psychic-debugging-why-your-icontextmenuinvokecommand-never-gets-called","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20120727-00\/?p=7033\/","title":{"rendered":"Psychic debugging: Why your IContextMenu::InvokeCommand never gets called"},"content":{"rendered":"<p>A customer reported a problem with their shell context menu extension.<\/p>\n<blockquote class=\"q\"><p> I have implemented the <code>IContext&shy;Menu<\/code> shell extension, but when the user selects my custom menu item, my <code>IContext&shy;Menu::Invoke&shy;Command<\/code> is never called. Can anyone please let me know what the problem could be and how to fix it? <\/p><\/blockquote>\n<p> Since there really isn&#8217;t much information provided in this request, I was forced to invoke my psychic powers. Actually, <a href=\"http:\/\/blogs.msdn.com\/oldnewthing\/archive\/2004\/10\/07\/239197.aspx\"> given what you know about shell context menu hosting<\/a>, you probably know the answer too.<\/p>\n<blockquote class=\"m\"><p> My psychic powers tell me that you gave your menu item the wrong ID, or you returned the wrong value from <code>IContext&shy;Menu::Query&shy;Context&shy;Menu<\/code>. <\/p><\/blockquote>\n<p> If the menu IDs do not lie in the range you described by the return value from <code>IContext&shy;Menu::Query&shy;Context&shy;Menu<\/code>, then when the user chooses the menu item, the item ID will not map to your shell extension. In our sample composite context menu, observe that <code>CComposite&shy;Context&shy;Menu::Reduce&shy;Ordinal<\/code> relies on the component context menu handlers putting their menu IDs in the range <code>idCmd&shy;First<\/code> through <code>idCmd&shy;First - return_value - 1<\/code>. If the two don&#8217;t line up, then <code>CComposite&shy;Context&shy;Menu::Reduce&shy;Ordinal<\/code> won&#8217;t realize that the menu item the user selected corresponds to you.\n We never did hear back from the customer, so the world may never know whether my psychic prediction was correct.<\/p>\n<p> <b>Bonus chatter<\/b>: When possible, use a static verb registration instead of an <code>IContext&shy;Menu<\/code> handler. They are much simpler to implement while still providing a good amount of expressive power. <\/p>\n<ul>\n<li><a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/cc144101(VS.85).aspx#class\">A simple command line<\/a>. <\/li>\n<li>     <a href=\"http:\/\/blogs.msdn.com\/b\/oldnewthing\/archive\/2010\/05\/03\/10006065.aspx\">     A drop target<\/a>. <\/li>\n<li>     <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/bb762475(VS.85).aspx\">     An <code>IExecute&shy;Command<\/code><\/a>. <\/li>\n<li>     <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/windows\/desktop\/bb761880(v=vs.85).aspx\">     An <code>IExplorer&shy;Command<\/code><\/a>. <\/li>\n<\/ul>\n<p> You can <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/cc144171(VS.85).aspx#dynamic_behavior\"> provide additional information in your registration<\/a> to control things like the conditions under which your verb should be shown. You can even <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/windows\/desktop\/hh127424(v=vs.85).aspx\"> register cascading submenus statically<\/a>. <\/p>\n","protected":false},"excerpt":{"rendered":"<p>A customer reported a problem with their shell context menu extension. I have implemented the IContext&shy;Menu shell extension, but when the user selects my custom menu item, my IContext&shy;Menu::Invoke&shy;Command is never called. Can anyone please let me know what the problem could be and how to fix it? Since there really isn&#8217;t much information provided [&hellip;]<\/p>\n","protected":false},"author":1069,"featured_media":111744,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[25],"class_list":["post-7033","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-code"],"acf":[],"blog_post_summary":"<p>A customer reported a problem with their shell context menu extension. I have implemented the IContext&shy;Menu shell extension, but when the user selects my custom menu item, my IContext&shy;Menu::Invoke&shy;Command is never called. Can anyone please let me know what the problem could be and how to fix it? Since there really isn&#8217;t much information provided [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/7033","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=7033"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/7033\/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=7033"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=7033"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=7033"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}