c++ - Calling Windows shell menu (same as right-click in Explorer) for multiple files programmatically -


i'm trying display shell context menu file (same when right-click file in explorer) programmatically. i've managed single file / folder, code below. now, how can call context menu list of files, if have selected couple in explorer , clicked them?

bool openshellcontextmenuforobject(const std::wstring &path, int xpos, int ypos, void * parentwindow) {     assert (parentwindow);     itemidlist * id = 0;     std::wstring windowspath = path;     std::replace(windowspath.begin(), windowspath.end(), '/', '\\');     hresult result = shparsedisplayname(windowspath.c_str(), 0, &id, 0, 0);     if (!succeeded(result) || !id)         return false;     citemidlistreleaser idreleaser (id);      ishellfolder * ifolder = 0;      lpcitemidlist idchild = 0;     result = shbindtoparent(id, iid_ishellfolder, (void**)&ifolder, &idchild);     if (!succeeded(result) || !ifolder)         return false;     ccominterfacereleaser ifolderreleaser (ifolder);      icontextmenu * imenu = 0;     result = ifolder->getuiobjectof((hwnd)parentwindow, 1, (const itemidlist **)&idchild, iid_icontextmenu, 0, (void**)&imenu);     if (!succeeded(result) || !ifolder)         return false;     ccominterfacereleaser menureleaser(imenu);      hmenu hmenu = createpopupmenu();     if (!hmenu)         return false;     if (succeeded(imenu->querycontextmenu(hmenu, 0, 1, 0x7fff, cmf_normal)))     {         int icmd = trackpopupmenuex(hmenu, tpm_returncmd, xpos, ypos, (hwnd)parentwindow, null);         if (icmd > 0)         {             cminvokecommandinfoex info = { 0 };             info.cbsize = sizeof(info);             info.fmask = cmic_mask_unicode;             info.hwnd = (hwnd)parentwindow;             info.lpverb  = makeintresourcea(icmd - 1);             info.lpverbw = makeintresourcew(icmd - 1);             info.nshow = sw_shownormal;             imenu->invokecommand((lpcminvokecommandinfo)&info);         }     }     destroymenu(hmenu);      return true; } 

result = ifolder->getuiobjectof((hwnd)parentwindow, 1, (const itemidlist **)&idchild, iid_icontextmenu, 0, (void**)&imenu); 

the getuiobjectof function takes array of pidls. 1 in function call indicates array contains 1 item, can pass number of child pidls using same method. e.g.:

lpitemidlist pidlarray[3] = { pidl1, pidl2, pidl3 }; result = ifolder->getuiobjectof((hwnd)parentwindow, _countof(pidlarray), pidlarray, iid_icontextmenu, 0, (void**)&imenu); 

(in real world build array dynamically). note items have children of same parent folder.


Comments

Popular posts from this blog

css - Which browser returns the correct result for getBoundingClientRect of an SVG element? -

gcc - Calling fftR4() in c from assembly -

Function that returns a formatted array in VBA -