{"id":8773,"date":"2011-12-29T07:00:00","date_gmt":"2011-12-29T07:00:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/oldnewthing\/2011\/12\/29\/using-the-mns_dragdrop-style-dropping-in\/"},"modified":"2011-12-29T07:00:00","modified_gmt":"2011-12-29T07:00:00","slug":"using-the-mns_dragdrop-style-dropping-in","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20111229-00\/?p=8773","title":{"rendered":"Using the MNS_DRAGDROP style: Dropping in"},"content":{"rendered":"<p>\nLast time,\n<a HREF=\"http:\/\/blogs.msdn.com\/b\/oldnewthing\/archive\/2011\/12\/28\/10251521.aspx\">\nwe looked at using the <code>MNS_DRAG&shy;DROP<\/code> style\nfor dragging items out of a menu<\/a>.\nToday, we&#8217;ll look at dropping them in.\n<\/p>\n<p>\nTake the program from last time and make the following additions.\nFirst, let&#8217;s add a second item to the menu.\n<\/p>\n<pre>\n\/\/ resource header file\n#define IDM_MAIN 1\n#define IDC_CLOCK 100\n<font COLOR=\"blue\">#define IDC_WMP 101<\/font>\n\/\/ resource file\nIDM_MAIN MENU PRELOAD\nBEGIN\n    POPUP \"&amp;Test\"\n    BEGIN\n        MENUITEM \"&amp;Clock\", IDC_CLOCK\n        <font COLOR=\"blue\">MENUITEM \"&amp;WMP\", IDC_WMP<\/font>\n    END\nEND\n\/\/ scratch.cpp\nHRESULT GetMenuObject(HWND hwnd, HMENU hmenu, UINT uPos,\n                      REFIID riid, void **ppvOut)\n{\n HRESULT hr = E_NOTIMPL;\n *ppvOut = NULL;\n if (hmenu == GetSubMenu(GetMenu(hwnd), 0)) {\n  switch (GetMenuItemID(hmenu, uPos)) {\n  case IDC_CLOCK:\n   hr = GetUIObjectOfFile(hwnd, L\"C:\\\\Windows\\\\clock.avi\",\n                                             riid, ppvOut);\n   break;\n  <font COLOR=\"blue\">case IDC_WMP:\n   hr = GetUIObjectOfFile(hwnd, L\"C:\\\\Program Files\"\n                  L\"\\\\Windows Media Player\\\\wmplayer.exe\",\n                                             riid, ppvOut);\n   break;<\/font>\n  }\n }\n return hr;\n}\n<\/pre>\n<p>\nYes, I hard-coded another path.\nThis is a demo, not production code.\n<\/p>\n<p>\nAnyway, it&#8217;s time to hook up the\n<code>WM_MENU&shy;GET&shy;OBJECT<\/code> message:\n<\/p>\n<pre>\n#define HANDLE_WM_MENUGETOBJECT(hwnd, wParam, lParam, fn) \\\n (fn)((hwnd), (MENUGETOBJECTINFO*)(lParam))\nLRESULT OnMenuGetObject(HWND hwnd, MENUGETOBJECTINFO *p<a HREF=\"http:\/\/daisann.com\/2007\/03\/04\/somewhere-between-do-jeh-and-mgoi.aspx\">mgoi<\/a>)\n{\n LRESULT lres = MNGO_NOINTERFACE;\n if (!(pmgoi-&gt;dwFlags &amp; (MNGOF_BOTTOMGAP | MNGOF_TOPGAP)) &amp;&amp;\n     SUCCEEDED(GetMenuObject(hwnd, pmgoi-&gt;hmenu, pmgoi-&gt;uPos,\n               *(IID*)pmgoi-&gt;riid, &amp;pmgoi-&gt;pvObj))) {\n  lres = MNGO_NOERROR;\n }\n return lres;\n}\n    HANDLE_MSG(hwnd, WM_MENUGETOBJECT, OnMenuGetObject);\n<\/pre>\n<p>\nTo handle the\n<code>WM_MENU&shy;GET&shy;OBJECT<\/code> message,\nyou convert the <code>hmenu<\/code>, <code>uPos<\/code> pair\ninto a COM object, requesting the interface provided by the\n<code>riid<\/code> member,\nand putting the result into the <code>pvObj<\/code> member.\n(Exercise: Why is the <code>riid<\/code> member\ntyped as <code>void *<\/code>\nrather than <code>REFIID<\/code>?)\n<\/p>\n<p>\nWhen the user tries to drop on a menu item, we just give them\nthe corresponding object in the shell namespace.\nNotice that I filter out the <code>GAP<\/code> messages,\nsince they indicate that the user is trying to drop <i>between<\/i>\nitems rather than on them.\n<\/p>\n<p>\nRun this program, open the <i>Test<\/i> menu, and drag the Clock\nmenu item onto the WMP menu item.\nIf all goes well\n(assuming you changed the path for <code>clock.avi<\/code>\nto some other AVI file),\nthe AVI file will be opened by Windows Media Player,\nsince that&#8217;s the behavior of Windows Media Player when you\ndrop an AVI file on it.\n<\/p>\n<p>\nSo that&#8217;s menu drag\/drop. It&#8217;s really not all that exciting.\nOf course, what people tend to be most interested in is not\ngeneric drag\/drop for menus but menu customization via drag\/drop.\nThat&#8217;s not something that\n<code>MNS_DRAG&shy;DROP<\/code> gives you directly;\nthat&#8217;s something you need to build yourself out of the\nbuilding blocks provided.\n<\/p>\n<p>\nWe&#8217;ll\n<a HREF=\"http:\/\/blogs.msdn.com\/b\/oldnewthing\/archive\/2009\/08\/04\/9856634.aspx\">\nsnap some blocks together<\/a>\nnext time.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Last time, we looked at using the MNS_DRAG&shy;DROP style for dragging items out of a menu. Today, we&#8217;ll look at dropping them in. Take the program from last time and make the following additions. First, let&#8217;s add a second item to the menu. \/\/ resource header file #define IDM_MAIN 1 #define IDC_CLOCK 100 #define IDC_WMP [&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-8773","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-code"],"acf":[],"blog_post_summary":"<p>Last time, we looked at using the MNS_DRAG&shy;DROP style for dragging items out of a menu. Today, we&#8217;ll look at dropping them in. Take the program from last time and make the following additions. First, let&#8217;s add a second item to the menu. \/\/ resource header file #define IDM_MAIN 1 #define IDC_CLOCK 100 #define IDC_WMP [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/8773","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=8773"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/8773\/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=8773"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=8773"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=8773"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}