Beispiel #1
0
HRESULT DesktopShellView::DoDesktopContextMenu(int x, int y)
{
	IContextMenu* pcm;

	HRESULT hr = DesktopFolder()->GetUIObjectOf(_hwnd, 0, NULL, IID_IContextMenu, NULL, (LPVOID*)&pcm);

	if (SUCCEEDED(hr)) {
		pcm = _cm_ifs.query_interfaces(pcm);

		HMENU hmenu = CreatePopupMenu();

		if (hmenu) {
			hr = pcm->QueryContextMenu(hmenu, 0, FCIDM_SHVIEWFIRST, FCIDM_SHVIEWLAST-1, CMF_NORMAL|CMF_EXPLORE);

			if (SUCCEEDED(hr)) {
				AppendMenu(hmenu, MF_SEPARATOR, 0, NULL);
				AppendMenu(hmenu, 0, FCIDM_SHVIEWLAST-1, ResString(IDS_ABOUT_EXPLORER));

				UINT idCmd = TrackPopupMenu(hmenu, TPM_LEFTALIGN|TPM_RETURNCMD|TPM_RIGHTBUTTON, x, y, 0, _hwnd, NULL);

				_cm_ifs.reset();

				if (idCmd == FCIDM_SHVIEWLAST-1) {
					explorer_about(_hwnd);
				} else if (idCmd) {
				  CMINVOKECOMMANDINFO cmi;

				  cmi.cbSize = sizeof(CMINVOKECOMMANDINFO);
				  cmi.fMask = 0;
				  cmi.hwnd = _hwnd;
				  cmi.lpVerb = (LPCSTR)(INT_PTR)(idCmd - FCIDM_SHVIEWFIRST);
				  cmi.lpParameters = NULL;
				  cmi.lpDirectory = NULL;
				  cmi.nShow = SW_SHOWNORMAL;
				  cmi.dwHotKey = 0;
				  cmi.hIcon = 0;

				  hr = pcm->InvokeCommand(&cmi);
				}
			} else
				_cm_ifs.reset();
			DestroyMenu(hmenu);
		}

		pcm->Release();
	}

	return hr;
}
bool OsShell::recycleBinContextMenu(int xPos, int yPos, void *parentWindow)
{
	ComInitializer comInitializer;

	PIDLIST_ABSOLUTE idlist = 0;
	if (!SUCCEEDED(SHGetFolderLocation(0, CSIDL_BITBUCKET, 0, 0, &idlist)))
		return false;

	IShellFolder * iFolder = 0;
	LPCITEMIDLIST list;
	HRESULT result = SHBindToParent(idlist, IID_IShellFolder, (void**)&iFolder, &list);
	if (!SUCCEEDED(result) || !list || !iFolder)
		return false;

	IContextMenu * imenu = 0;
	result = iFolder->GetUIObjectOf((HWND)parentWindow, 1u, &list, IID_IContextMenu, 0, (void**)&imenu);
	CoTaskMemFree(idlist);
	if (!SUCCEEDED(result) || !imenu)
		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;
}
Beispiel #3
0
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();
      }
   }
}
Beispiel #4
0
/// <summary>
/// Brings up the context menu for the currently selected icons.
/// </summary>
void TileGroup::ContextMenu() {
  IContextMenu *contextMenu;
  HMENU menu;
  std::vector<LPCITEMIDLIST> items;
  HRESULT hr;

  for (Tile *tile : mTiles) {
    if (tile->IsSelected()) {
      items.push_back(tile->GetItem());
    }
  }

  if (items.empty()) {
    return;
  }

  if (SUCCEEDED(hr = mWorkingFolder->GetUIObjectOf(nullptr, UINT(items.size()), &items[0], IID_IContextMenu, nullptr, reinterpret_cast<LPVOID*>(&contextMenu)))) {
    menu = CreatePopupMenu();
    if (menu) {
      if (SUCCEEDED(hr = contextMenu->QueryContextMenu(menu, 0, 1, 1024, CMF_NORMAL | CMF_CANRENAME))) {
        POINT pt;
        GetCursorPos(&pt);
        contextMenu->QueryInterface(IID_IContextMenu2, (LPVOID*)&mContextMenu2);
        contextMenu->QueryInterface(IID_IContextMenu3, (LPVOID*)&mContextMenu3);
        int command = TrackPopupMenuEx(menu, TPM_RETURNCMD | TPM_RIGHTBUTTON, pt.x, pt.y, mWindow->GetWindowHandle(), nullptr);
        SAFERELEASE(mContextMenu2);
        SAFERELEASE(mContextMenu3);
        if (command != 0) {
          //WCHAR verb[MAX_LINE_LENGTH];
          //if (SUCCEEDED(hr = contextMenu->GetCommandString(command, GCS_VERBW, nullptr, LPSTR(verb), _countof(verb))))
          {
            // TODO::Figure out why InvokeCommand fails if i go for unicode.
            CMINVOKECOMMANDINFOEX info;
            ZeroMemory(&info, sizeof(info));
            info.cbSize = sizeof(info);
            info.fMask = CMIC_MASK_UNICODE | CMIC_MASK_PTINVOKE;
            if (GetKeyState(VK_CONTROL) < 0)
            {
              info.fMask |= CMIC_MASK_CONTROL_DOWN;
            }
            if (GetKeyState(VK_SHIFT) < 0)
            {
              info.fMask |= CMIC_MASK_SHIFT_DOWN;
            }

            info.hwnd = mWindow->GetWindowHandle();
            //info.lpVerb = verb;
            //info.lpVerbW = verb;
            info.lpVerb = MAKEINTRESOURCEA(command - 1);
            info.lpVerbW = MAKEINTRESOURCEW(command - 1);
            info.ptInvoke = pt;
            hr = contextMenu->InvokeCommand(LPCMINVOKECOMMANDINFO(&info));
          }
        }
      }

      DestroyMenu(menu);
    }

    contextMenu->Release();
  }
}
Beispiel #5
0
//***************************************************************************************
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 ();
}