bool OsShell::openShellContextMenuForObjects(const std::vector<std::wstring>& objects, int xPos, int yPos, void * parentWindow)
{
	ComInitializer comInitializer;

	IContextMenu * imenu = 0;
	HMENU hMenu = NULL;
	if (!prepareContextMenuForObjects(objects, parentWindow, hMenu, imenu) || !hMenu || !imenu)
		return false;

	CComInterfaceReleaser menuReleaser(imenu);

	const int iCmd = TrackPopupMenuEx(hMenu, TPM_RETURNCMD, xPos, yPos, (HWND)parentWindow, NULL);
	if (iCmd > 0)
	{
		CMINVOKECOMMANDINFO info = { 0 };
		info.cbSize = sizeof(info);
		info.hwnd = (HWND)parentWindow;
		info.lpVerb  = MAKEINTRESOURCEA(iCmd - 1);
		info.nShow = SW_SHOWNORMAL;
		imenu->InvokeCommand((LPCMINVOKECOMMANDINFO)&info);
	}

	DestroyMenu(hMenu);

	return true;
}
Beispiel #2
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;
}
void IPlugVST3Plugin::PopupHostContextMenuForParam(int param, int x, int y)
{
  if (componentHandler == 0 || viewsArray.at(0) == 0)
    return;

  FUnknownPtr<IComponentHandler3>handler(componentHandler);

  if (handler == 0)
    return;

  ParamID p = param;

  IContextMenu* menu = handler->createContextMenu(viewsArray.at(0), &p);

  if (menu)
  {
    menu->popup((UCoord) x,(UCoord) y);
    menu->release();
  }
}
bool OsShell::pasteFilesAndFoldersFromClipboard(std::wstring destFolder, void * parentWindow)
{
	ComInitializer comInitializer;

	IContextMenu * imenu = 0;
	HMENU hMenu = NULL;
	if (!prepareContextMenuForObjects(std::vector<std::wstring>(1, destFolder), parentWindow, hMenu, imenu) || !hMenu || !imenu)
		return false;

	CComInterfaceReleaser menuReleaser(imenu);

	const char command [] = "Paste";

	CMINVOKECOMMANDINFO info = { 0 };
	info.cbSize = sizeof(info);
	info.hwnd = (HWND) parentWindow;
	info.lpVerb = command;
	info.nShow = SW_SHOWNORMAL;
	const auto result = imenu->InvokeCommand((LPCMINVOKECOMMANDINFO) &info);

	DestroyMenu(hMenu);

	return SUCCEEDED(result);
}
Beispiel #6
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 #7
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 #8
0
HRESULT AddContextMenu(WCHAR* file)
{
  HRESULT hr = E_UNEXPECTED;
  LPVOID lpVoid;
  HMENU fileMenu = CreatePopupMenu();
  IShellFolder* deskFolder = NULL;
  IShellFolder* appObject = NULL;
  LPITEMIDLIST pidlLocal = NULL;
  LPITEMIDLIST pidlRelative = NULL;
  IContextMenu* contextMenu = NULL;
  CONTEXTINFO contextInfo;

  wcscpy(contextInfo.value, file);

  hr = SHGetDesktopFolder(&deskFolder);
  if (FAILED(hr))
  {
    return hr;
  }

  hr = deskFolder->ParseDisplayName(NULL, NULL, file, NULL, &pidlLocal, NULL);
  if (FAILED(hr))
  {
    deskFolder->Release();
    return hr;
  }

  pidlRelative = ILClone(ILFindLastID(pidlLocal));
  ILRemoveLastID(pidlLocal);

  hr = deskFolder->BindToObject(pidlLocal, NULL, IID_IShellFolder, &lpVoid);
  if (FAILED(hr))
  {
    deskFolder->Release();
    ILFree(pidlLocal);
    return hr;
  }
  appObject = reinterpret_cast <IShellFolder*> (lpVoid);

  deskFolder->Release();
  ILFree(pidlLocal);

  hr = appObject->GetUIObjectOf(NULL, 1, (LPCITEMIDLIST*)&pidlRelative,
                                IID_IContextMenu, NULL, &lpVoid);
  if (FAILED(hr))
  {
    appObject->Release();
    ILFree(pidlRelative);
    return hr;
  }
  contextMenu = reinterpret_cast <IContextMenu*> (lpVoid);

  ILFree(pidlRelative);
  appObject->Release();

  contextMenu->QueryInterface(IID_IContextMenu2, &lpVoid);
  if (FAILED(hr))
  {
    contextMenu->Release();
    return hr;
  }
  contextInfo.ic2 = reinterpret_cast <IContextMenu2*> (lpVoid);

  contextMenu->Release();

  hr = contextInfo.ic2->QueryContextMenu(fileMenu, 0, SYSMENUMIN, SYSMENUMAX, CMF_NORMAL);
  if (FAILED(hr))
  {
    contextInfo.ic2->Release();
    return hr;
  }

  if (!ELIsDirectory(file))
  {
    AppendMenu(fileMenu, MF_SEPARATOR, 0x8000, NULL);
    AppendMenu(fileMenu, MF_STRING, 0x8001, TEXT("Open Folder"));
  }

  contextMap.insert(std::pair<HMENU, CONTEXTINFO>(fileMenu, contextInfo));

  return hr;
}
Beispiel #9
0
//***************************************************************************************
void CBCGPShellList::OnContextMenu(CWnd* /*pWnd*/, CPoint point) 
{
	ASSERT_VALID (this);
	ASSERT_VALID (g_pShellManager);
	ASSERT (g_pShellManager->m_pBCGMalloc != NULL);

	if (m_pContextMenu2 != NULL)
	{
		return;
	}

	if (!m_bContextMenu)
	{
		Default ();
		return;
	}

	if (m_psfCurFolder == NULL)
	{
		return;
	}

	UINT	nSelItems = GetSelectedCount ();
	int		nClickedItem = -1;

	if (point.x == -1 && point.y == -1)
	{
		//--------------------------------------------------------
		// Keyboard, show menu for the currently selected item(s):
		//--------------------------------------------------------
		if (nSelItems == 0)
		{
			return;
		}

		int nCurItem = -1;
		int nLastSelItem = -1;

		for (UINT i = 0; i < nSelItems; i++)
		{
			nCurItem = GetNextItem (nCurItem, LVNI_SELECTED);
			nLastSelItem = nCurItem;
		}

		CRect rectItem;
		if (GetItemRect (nLastSelItem, rectItem, LVIR_BOUNDS))
		{
			point.x = rectItem.left;
			point.y = rectItem.bottom + 1;

			ClientToScreen (&point);
		}
	}
	else
	{
		//--------------------------
		// Clicked on specifed item:
		//--------------------------
		LVHITTESTINFO lvhti;
		lvhti.pt = point;
		ScreenToClient(&lvhti.pt);
		
		lvhti.flags = LVHT_NOWHERE;
		
		HitTest (&lvhti);
		
		if ((lvhti.flags & LVHT_ONITEM) == 0)
		{
			//-----------------------------------
			// Click ouside of items, do nothing
			//-----------------------------------
			return;
		}

		nClickedItem = lvhti.iItem;
	}

	LPITEMIDLIST* pPidls = (LPITEMIDLIST*) 
						g_pShellManager->m_pBCGMalloc->Alloc (sizeof(LPITEMIDLIST) * nSelItems);
	ASSERT (pPidls != NULL);

	//------------------------
	// Get the selected items:
	//------------------------
	LVITEM lvItem;
	ZeroMemory(&lvItem, sizeof(lvItem));
	lvItem.mask = LVIF_PARAM;

	LPBCGCBITEMINFO pClickedInfo = (LPBCGCBITEMINFO)lvItem.lParam;

	if (nClickedItem >= 0)
	{
		//-------------------------------------------
		// Put the item clicked on first in the list:
		//-------------------------------------------
		lvItem.iItem = nClickedItem;

		if (GetItem (&lvItem))
		{
			pClickedInfo = (LPBCGCBITEMINFO)lvItem.lParam;
			pPidls [0] = pClickedInfo->pidlRel;
		}
	}
	
	int nCurItem = -1;
	for (UINT i = nClickedItem >= 0 ? 1 : 0; i < nSelItems; i++)
	{
		nCurItem = GetNextItem (nCurItem, LVNI_SELECTED);
		if (nCurItem != nClickedItem)
		{
			lvItem.iItem = nCurItem;

			if (GetItem (&lvItem))
			{
				LPBCGCBITEMINFO pInfo = (LPBCGCBITEMINFO)lvItem.lParam;
				pPidls [i] = pInfo->pidlRel;

				if (pClickedInfo == NULL)
				{
					pClickedInfo = pInfo;
				}
			}
		}
		else
		{
			i--;
		}
	}
	
	if (pPidls [0] == NULL)
	{
		g_pShellManager->m_pBCGMalloc->Free (pPidls);
		return;
	}

	IContextMenu* pcm;
	HRESULT hr = m_psfCurFolder->GetUIObjectOf (GetSafeHwnd (),
		nSelItems, 
		(LPCITEMIDLIST*)pPidls, 
		IID_IContextMenu, 
		NULL, 
		(LPVOID*)&pcm);
	
	if (SUCCEEDED (hr))
	{
		hr = pcm->QueryInterface (IID_IContextMenu2, (LPVOID*)&m_pContextMenu2);

		if (SUCCEEDED (hr))
		{
			HMENU hPopup = CreatePopupMenu ();
			if (hPopup != NULL)
			{
				hr = m_pContextMenu2->QueryContextMenu(hPopup, 0, 1, 0x7fff, CMF_NORMAL | CMF_EXPLORE);
				
				if (SUCCEEDED(hr))
				{
					UINT idCmd = TrackPopupMenu (hPopup,
							TPM_LEFTALIGN | TPM_RETURNCMD | TPM_RIGHTBUTTON, 
							point.x,
							point.y,
							0,
							GetSafeHwnd (),
							NULL);

					if (idCmd != 0)
					{
						BOOL bIsFolder = FALSE;

						if (nSelItems == 1 &&
							idCmd == ::GetMenuDefaultItem (hPopup, FALSE, 0))
						{
							//-----------------------------------------------------
							// If specified element is a folder, try to display it:
							//-----------------------------------------------------
							ULONG ulAttrs = SFGAO_FOLDER;
							m_psfCurFolder->GetAttributesOf (1, 
								(const struct _ITEMIDLIST **) &pClickedInfo->pidlRel, &ulAttrs);

							if (ulAttrs & SFGAO_FOLDER)
							{
								bIsFolder = TRUE;
								DisplayFolder (pClickedInfo);
							}
						}

						if (!bIsFolder)
						{
							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);
							}
						}
					}
				}
			}

			if (m_pContextMenu2 != NULL)
			{
				m_pContextMenu2->Release();
				m_pContextMenu2 = NULL;
			}
		}
		
		pcm->Release();
	}
	
	g_pShellManager->m_pBCGMalloc->Free (pPidls);
}
Beispiel #10
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 ();
}