Wednesday, 15 January 2014

windows - Cascade submenus inside context menu shell extension with c++ -



windows - Cascade submenus inside context menu shell extension with c++ -

hello i'm trying cascade window within context menu in shell extension. add together 2 submenus within context menu of .dll extension, but want create 1 cascade submenu (i open first menu , after clicking on menu inside, want open next submenu).

how cascade submenus code, did create mistake?

// openwithctxmenuext.cpp : implementation of copenwithctxmenuext #include "stdafx.h" #include "openwithext.h" #include "openwithctxmenuext.h" #pragma comment(lib,"shlwapi") ///////////////////////////////////////////////////////////////////////////// // copenwithctxmenuext hresult copenwithctxmenuext::initialize ( lpcitemidlist pidlfolder, lpdataobject pdataobj, hkey hprogid ) { formatetc fmt = { cf_hdrop, null, dvaspect_content, -1, tymed_hglobal }; stgmedium stg = { tymed_hglobal }; hdrop hdrop; // cf_hdrop info in info object. if ( failed( pdataobj->getdata ( &fmt, &stg ))) { // nope! homecoming "invalid argument" error explorer. homecoming e_invalidarg; } // pointer actual data. hdrop = (hdrop) globallock ( stg.hglobal ); // create sure worked. if ( null == hdrop ) homecoming e_invalidarg; // sanity check - create sure there @ to the lowest degree 1 filename. uint unumfiles = dragqueryfile ( hdrop, 0xffffffff, null, 0 ); if ( 0 == unumfiles ) { globalunlock ( stg.hglobal ); releasestgmedium ( &stg ); homecoming e_invalidarg; } hresult hr = s_ok; // name of first file , store in our fellow member variable m_szfile. if ( 0 == dragqueryfile ( hdrop, 0, m_szselectedfile, max_path )) hr = e_invalidarg; else { // quote name if contains spaces (needed cmd line built properly) pathquotespaces ( m_szselectedfile ); } globalunlock ( stg.hglobal ); releasestgmedium ( &stg ); homecoming hr; } hresult copenwithctxmenuext::querycontextmenu ( hmenu hmenu, uint umenuindex, uint uidfirstcmd, uint uidlastcmd, uint uflags ) { // if flags include cmf_defaultonly shouldn't anything. if ( uflags & cmf_defaultonly ) homecoming make_hresult ( severity_success, facility_null, 0 ); // first, create , populate submenu. hmenu hsubmenu = createpopupmenu(); hmenu hsubmenu1 = createpopupmenu(); uint uid = uidfirstcmd; insertmenu ( hsubmenu, 0, mf_byposition, uid++, _t("&notepad") ); insertmenu ( hsubmenu, 1, mf_byposition, uid++, _t("&internet explorer") ); insertmenu ( hsubmenu, 2, mf_byposition, uid++, _t("&mspaint") ); insertmenu ( hsubmenu, 3, mf_byposition, uid++, _t("&pop") ); // provjeriti uid da se ne zbraja insertmenu ( hsubmenu1, 0, mf_byposition, uid++, _t("&notepad") ); insertmenu ( hsubmenu1, 1, mf_byposition, uid++, _t("&mspaint") ); // insert submenu ctx menu provided explorer. menuiteminfo mii = { sizeof(menuiteminfo) }; mii.fmask = miim_submenu | /*miim_string*/ 0x00000040 | miim_id; mii.wid = uid++; mii.hsubmenu = hsubmenu; mii.dwtypedata = _t("c&p open with"); insertmenuitem ( hmenu, umenuindex, true, &mii ); // insert submenu ctx menu provided explorer. menuiteminfo mii1 = { sizeof(menuiteminfo) }; mii1.fmask = miim_submenu | /*miim_string*/ 0x00000040 | miim_id; mii1.wid = uid++; mii1.hsubmenu = hsubmenu; mii1.dwtypedata = _t("c&p pod_folder"); insertmenuitem ( hmenu, umenuindex, true, &mii1 ); homecoming make_hresult ( severity_success, facility_null, uid - uidfirstcmd ); } hresult copenwithctxmenuext::getcommandstring ( uint idcmd, uint uflags, uint* pwreserved, lpstr pszname, uint cchmax ) { uses_conversion; // check idcmd, must 0 or 1 since have 2 menu items. if ( idcmd > 3 ) homecoming e_invalidarg; // if explorer asking help string, re-create our string // supplied buffer. if ( uflags & gcs_helptext ) { lpctstr sznotepadtext = _t("open selected file in notepad"); lpctstr szietext = _t("open selected file in net explorer"); lpctstr szpinttext = _t("open selected file mspaint"); lpctstr szpoptext = _t("popout"); lpctstr sznotepad1text = _t("open selected file in notepad"); lpctstr szpint1text = _t("open selected file mspaint"); //lpctstr psztext = (0 == idcmd) ? sznotepadtext : szietext; lpctstr psztext; if(idcmd == 0){ psztext = sznotepadtext; } if(idcmd == 1){ psztext = szietext; } if(idcmd == 2){ psztext = szpinttext; } if(idcmd == 3){ psztext = szpoptext; } if(idcmd == 4){ psztext = sznotepad1text; } if(idcmd == 5){ psztext = szpint1text; } if ( uflags & gcs_unicode ) { // need cast pszname unicode string, , utilize // unicode string re-create api. lstrcpynw ( (lpwstr) pszname, t2cw(psztext), cchmax ); } else { // utilize ansi string re-create api homecoming help string. lstrcpyna ( pszname, t2ca(psztext), cchmax ); } homecoming s_ok; } homecoming e_invalidarg; } hresult copenwithctxmenuext::invokecommand ( lpcminvokecommandinfo pcmdinfo ) { // if lpverb points string, ignore function phone call , bail out. if ( 0 != hiword( pcmdinfo->lpverb )) homecoming e_invalidarg; // command index. switch ( loword( pcmdinfo->lpverb )) { case 0: { shellexecute ( pcmdinfo->hwnd, _t("open"), _t("notepad.exe"), m_szselectedfile, null, sw_show ); homecoming s_ok; } break; case 1: { shellexecute ( pcmdinfo->hwnd, _t("open"), _t("iexplore.exe"), m_szselectedfile, null, sw_show ); homecoming s_ok; } break; case 2: { shellexecute ( pcmdinfo->hwnd, _t("open"), _t("mspaint.exe"), m_szselectedfile, null, sw_show ); homecoming s_ok; } break; case 3: { shellexecute ( pcmdinfo->hwnd, _t("open"), _t("mspaint.exe"), m_szselectedfile, null, sw_show ); homecoming s_ok; } break; case 4: { shellexecute ( pcmdinfo->hwnd, _t("open"), _t("notepad.exe"), m_szselectedfile, null, sw_show ); homecoming s_ok; } break; case 5: { shellexecute ( pcmdinfo->hwnd, _t("open"), _t("mspaint.exe"), m_szselectedfile, null, sw_show ); homecoming s_ok; } break; default: homecoming e_invalidarg; break; } }

after time found solution making cascade context menu within of existing context menu ... here code:

// openwithctxmenuext.cpp : implementation of copenwithctxmenuext #include "stdafx.h" #include "openwithext.h" #include "openwithctxmenuext.h" #pragma comment(lib,"shlwapi") ///////////////////////////////////////////////////////////////////////////// // copenwithctxmenuext hresult copenwithctxmenuext::initialize ( lpcitemidlist pidlfolder, lpdataobject pdataobj, hkey hprogid ) { formatetc fmt = { cf_hdrop, null, dvaspect_content, -1, tymed_hglobal }; stgmedium stg = { tymed_hglobal }; hdrop hdrop; // cf_hdrop info in info object. if ( failed( pdataobj->getdata ( &fmt, &stg ))) { // nope! homecoming "invalid argument" error explorer. homecoming e_invalidarg; } // pointer actual data. hdrop = (hdrop) globallock ( stg.hglobal ); // create sure worked. if ( null == hdrop ) homecoming e_invalidarg; // sanity check - create sure there @ to the lowest degree 1 filename. uint unumfiles = dragqueryfile ( hdrop, 0xffffffff, null, 0 ); if ( 0 == unumfiles ) { globalunlock ( stg.hglobal ); releasestgmedium ( &stg ); homecoming e_invalidarg; } hresult hr = s_ok; // name of first file , store in our fellow member variable m_szfile. if ( 0 == dragqueryfile ( hdrop, 0, m_szselectedfile, max_path )) hr = e_invalidarg; else { // quote name if contains spaces (needed cmd line built properly) pathquotespaces ( m_szselectedfile ); } globalunlock ( stg.hglobal ); releasestgmedium ( &stg ); homecoming hr; } hresult copenwithctxmenuext::querycontextmenu ( hmenu hmenu, uint umenuindex, uint uidfirstcmd, uint uidlastcmd, uint uflags ) { // if flags include cmf_defaultonly shouldn't anything. if ( uflags & cmf_defaultonly ) homecoming make_hresult ( severity_success, facility_null, 0 ); // first, create , populate submenu. hmenu hsubmenu = createpopupmenu(); hmenu hsub = createpopupmenu(); uint uid = uidfirstcmd; insertmenu ( hsubmenu, 0, mf_byposition, uid++, _t("&notepad") ); insertmenu ( hsubmenu, 1, mf_byposition, uid++, _t("&internet explorer") ); insertmenu ( hsubmenu, 2, mf_byposition, uid++, _t("&mspaint") ); insertmenu ( hsubmenu, 3, mf_byposition, uid++, _t("&pop") ); insertmenu ( hsub, 4, mf_byposition, uid++, _t("&case") ); insertmenu ( hsub, 5, mf_byposition, uid++, _t("&case") ); // insert submenu ctx menu provided explorer. menuiteminfo mii = { sizeof(menuiteminfo) }; mii.fmask = miim_submenu | /*miim_string*/ 0x00000040 | miim_id; mii.wid = uid++; mii.hsubmenu = hsubmenu; mii.dwtypedata = _t("open with&x"); insertmenuitem ( hmenu, umenuindex, true, &mii ); mii.hsubmenu = hsub; mii.dwtypedata = _t("novi subm&enu"); insertmenuitem ( hsubmenu, umenuindex, true, &mii ); homecoming make_hresult ( severity_success, facility_null, uid - uidfirstcmd ); } hresult copenwithctxmenuext::getcommandstring ( uint idcmd, uint uflags, uint* pwreserved, lpstr pszname, uint cchmax ) { uses_conversion; // check idcmd, must 0 or 1 since have 2 menu items. if ( idcmd > 4 ) homecoming e_invalidarg; // if explorer asking help string, re-create our string // supplied buffer. if ( uflags & gcs_helptext ) { lpctstr sznotepadtext = _t("open selected file in notepad"); lpctstr szietext = _t("open selected file in net explorer"); lpctstr szpinttext = _t("open selected file mspaint"); lpctstr szpoptext = _t("popout"); //lpctstr psztext = (0 == idcmd) ? sznotepadtext : szietext; lpctstr psztext; if(idcmd == 0){ psztext = sznotepadtext; } if(idcmd == 1){ psztext = szietext; } if(idcmd == 2){ psztext = szpinttext; } if(idcmd == 3){ psztext = szpoptext; } if(idcmd == 4){ psztext = szpoptext; } if ( uflags & gcs_unicode ) { // need cast pszname unicode string, , utilize // unicode string re-create api. lstrcpynw ( (lpwstr) pszname, t2cw(psztext), cchmax ); } else { // utilize ansi string re-create api homecoming help string. lstrcpyna ( pszname, t2ca(psztext), cchmax ); } homecoming s_ok; } homecoming e_invalidarg; } hresult copenwithctxmenuext::invokecommand ( lpcminvokecommandinfo pcmdinfo ) { // if lpverb points string, ignore function phone call , bail out. if ( 0 != hiword( pcmdinfo->lpverb )) homecoming e_invalidarg; // command index. switch ( loword( pcmdinfo->lpverb )) { case 0: { shellexecute ( pcmdinfo->hwnd, _t("open"), _t("notepad.exe"), m_szselectedfile, null, sw_show ); homecoming s_ok; } break; case 1: { shellexecute ( pcmdinfo->hwnd, _t("open"), _t("iexplore.exe"), m_szselectedfile, null, sw_show ); homecoming s_ok; } break; case 2: { shellexecute ( pcmdinfo->hwnd, _t("open"), _t("mspaint.exe"), m_szselectedfile, null, sw_show ); homecoming s_ok; } break; case 4: { messagebox(0, "new command sub menu", "case 4", 0); homecoming s_ok; } break; case 5: { messagebox(0, "new sec command sub menu", "case 5", 0); homecoming s_ok; } break; default: homecoming e_invalidarg; break; } }

c++ windows shell contextmenu submenu

No comments:

Post a Comment