void CFileTreeCtrl::doItemMenu (HWND hwndTreeView, HTREEITEM hItem, LPPOINT pptScreen) { TVITEM tvItem; ZeroMemory(&tvItem, sizeof(tvItem)); tvItem.mask = TVIF_PARAM; tvItem.hItem = hItem; if(TreeView_GetItem(hwndTreeView, &tvItem)) { HWND hwndParent = ::GetParent(hwndTreeView); HRESULT hr; CTreeItemInfo* pInfo = (CTreeItemInfo*)tvItem.lParam; IContextMenu *pcm; IShellFolder *psfFolder = pInfo->pParentFolder; if(!psfFolder) { SHGetDesktopFolder(&psfFolder); } else { psfFolder->AddRef(); } if(psfFolder) { hr = psfFolder->GetUIObjectOf( hwndParent, 1, (LPCITEMIDLIST*)&pInfo->pidlSelf, IID_IContextMenu, NULL, (LPVOID*)&pcm); if(SUCCEEDED(hr)) { HMENU hPopup; hPopup = CreatePopupMenu(); if(hPopup) { hr = pcm->QueryContextMenu(hPopup, 0, 1, 0x7fff, CMF_NORMAL | CMF_EXPLORE); if(SUCCEEDED(hr)) { IContextMenu2* pcm2; pcm->QueryInterface(IID_IContextMenu2, (LPVOID*)&pcm2); UINT idCmd; idCmd = TrackPopupMenu( hPopup, TPM_LEFTALIGN | TPM_RETURNCMD | TPM_RIGHTBUTTON, pptScreen->x, pptScreen->y, 0, hwndParent, NULL); if(pcm2) { pcm2->Release(); pcm2 = NULL; } if(idCmd) { CMINVOKECOMMANDINFO cmi; cmi.cbSize = sizeof(CMINVOKECOMMANDINFO); cmi.fMask = 0; cmi.hwnd = hwndParent; cmi.lpVerb = (LPCSTR)(INT_PTR)(idCmd - 1); cmi.lpParameters = NULL; cmi.lpDirectory = NULL; cmi.nShow = SW_SHOWNORMAL; cmi.dwHotKey = 0; cmi.hIcon = NULL; hr = pcm->InvokeCommand(&cmi); } } } pcm->Release(); } psfFolder->Release(); } } }
ShellFolderWithPidl(IShellFolder * theSF = 0, LPITEMIDLIST thePidl = 0) : SF(theSF), Pidl(thePidl) { if (SF != 0) SF->AddRef(); }
ShellFolderWithPidl(const ShellFolderWithPidl & theOrig) : SF(theOrig.SF), Pidl(theOrig.Pidl) { if (SF != 0) SF->AddRef(); }
//*************************************************************************************** void CBCGPShellList::DoDefault (int iItem) { LVITEM lvItem; ZeroMemory(&lvItem, sizeof(lvItem)); lvItem.mask = LVIF_PARAM; lvItem.iItem = iItem; if (!GetItem (&lvItem)) { return; } LPBCGCBITEMINFO pInfo = (LPBCGCBITEMINFO) lvItem.lParam; if (pInfo == NULL || pInfo->pParentFolder == NULL || pInfo->pidlRel == NULL) { ASSERT (FALSE); return; } IShellFolder *psfFolder = pInfo->pParentFolder; if (psfFolder == NULL) { SHGetDesktopFolder (&psfFolder); } else { psfFolder->AddRef (); } if (psfFolder == NULL) { return; } //----------------------------------------------------- // If specified element is a folder, try to display it: //----------------------------------------------------- ULONG ulAttrs = SFGAO_FOLDER; psfFolder->GetAttributesOf (1, (const struct _ITEMIDLIST **) &pInfo->pidlRel, &ulAttrs); if (ulAttrs & SFGAO_FOLDER) { DisplayFolder (pInfo); } else { //------------------------------- // Invoke a default menu command: //------------------------------- IContextMenu *pcm; HRESULT hr = psfFolder->GetUIObjectOf (GetSafeHwnd (), 1, (LPCITEMIDLIST*)&pInfo->pidlRel, IID_IContextMenu, NULL, (LPVOID*)&pcm); if (SUCCEEDED (hr)) { HMENU hPopup = CreatePopupMenu (); if (hPopup != NULL) { hr = pcm->QueryContextMenu (hPopup, 0, 1, 0x7fff, CMF_DEFAULTONLY | CMF_EXPLORE); if (SUCCEEDED (hr)) { UINT idCmd = ::GetMenuDefaultItem (hPopup, FALSE, 0); if (idCmd != 0 && idCmd != (UINT)-1) { CMINVOKECOMMANDINFO cmi; cmi.cbSize = sizeof (CMINVOKECOMMANDINFO); cmi.fMask = 0; cmi.hwnd = GetParent()->GetSafeHwnd (); cmi.lpVerb = (LPCSTR)(INT_PTR)(idCmd - 1); cmi.lpParameters = NULL; cmi.lpDirectory = NULL; cmi.nShow = SW_SHOWNORMAL; cmi.dwHotKey = 0; cmi.hIcon = NULL; hr = pcm->InvokeCommand (&cmi); if (SUCCEEDED (hr) && GetParent () != NULL) { GetParent ()->SendMessage (BCGPM_ON_AFTER_SHELL_COMMAND, (WPARAM) idCmd); } } } } pcm->Release (); } } psfFolder->Release (); }