本文整理汇总了C++中LPCONTEXTMENU::InvokeCommand方法的典型用法代码示例。如果您正苦于以下问题:C++ LPCONTEXTMENU::InvokeCommand方法的具体用法?C++ LPCONTEXTMENU::InvokeCommand怎么用?C++ LPCONTEXTMENU::InvokeCommand使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类LPCONTEXTMENU
的用法示例。
在下文中一共展示了LPCONTEXTMENU::InvokeCommand方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ExecCommand
BOOL CRecBinViewer::ExecCommand (LPCONTEXTMENU pCtxMenu, LPCTSTR lpszCommand)
{
UINT uiID = UINT (-1);
UINT uiCommand = 0;
UINT uiMenuFirst = 1;
UINT uiMenuLast = 0x00007FFF;
HMENU hmenuCtx;
int iMenuPos = 0;
int iMenuMax = 0;
TCHAR szMenuItem[MAX_PATH];
TCHAR verb[MAX_PATH] ;
hmenuCtx = CreatePopupMenu();
HRESULT hr = pCtxMenu->QueryContextMenu(hmenuCtx, 0, uiMenuFirst, uiMenuLast, CMF_NORMAL);
iMenuMax = GetMenuItemCount(hmenuCtx);
for (iMenuPos = 0 ; iMenuPos < iMenuMax; iMenuPos++)
{
GetMenuString(hmenuCtx, iMenuPos, szMenuItem, MAX_PATH, MF_BYPOSITION) ;
uiID = GetMenuItemID(hmenuCtx, iMenuPos) ;
if ((uiID == -1) || (uiID == 0))
{
}
else
{
hr = pCtxMenu->GetCommandString(uiID - 1, GCS_VERB, NULL, (LPSTR)verb, MAX_PATH);
if (FAILED (hr))
{
verb[0] = TCHAR ('\0') ;
}
else
{
if (0 == _tcsicmp (verb, lpszCommand))
uiCommand = uiID - 1;
}
}
}
if ((UINT)-1 != uiCommand)
{
CMINVOKECOMMANDINFO cmi;
ZeroMemory(&cmi, sizeof(CMINVOKECOMMANDINFO));
cmi.cbSize = sizeof(CMINVOKECOMMANDINFO);
cmi.fMask = CMIC_MASK_FLAG_NO_UI;
cmi.hwnd = m_hWnd;
cmi.lpVerb = (LPSTR)MAKEINTRESOURCE (uiCommand);
cmi.nShow = SW_SHOWNORMAL;
hr = pCtxMenu->InvokeCommand(&cmi);
if (SUCCEEDED (hr))
return TRUE;
}
return false;
}
示例2: InvokeCommand
void CShellContextMenu::InvokeCommand (LPCONTEXTMENU pContextMenu, UINT idCommand)
{
CMINVOKECOMMANDINFO cmi = {0};
cmi.cbSize = sizeof (CMINVOKECOMMANDINFO);
cmi.lpVerb = (LPSTR) MAKEINTRESOURCE (idCommand);
cmi.nShow = SW_SHOWNORMAL;
pContextMenu->InvokeCommand (&cmi);
}
示例3: DirList_PropertyDlg
// Shows standard Win95 Property Dlg for selected Item
BOOL DirList_PropertyDlg(HWND hwnd, int iItem) {
LV_ITEM lvi;
LPLV_ITEMDATA lplvid;
LPCONTEXTMENU lpcm;
CMINVOKECOMMANDINFO cmi;
BOOL bSuccess = TRUE;
static const char* lpVerb = "properties";
if (iItem == -1) {
if (ListView_GetSelectedCount(hwnd))
iItem = ListView_GetNextItem(hwnd, -1, LVNI_ALL | LVNI_SELECTED);
else
return FALSE;
}
lvi.mask = LVIF_PARAM;
lvi.iItem = iItem;
lvi.iSubItem = 0;
if (!ListView_GetItem(hwnd, &lvi))
return FALSE;
lplvid = (LPLV_ITEMDATA)lvi.lParam;
if (NOERROR ==
lplvid->lpsf->GetUIObjectOf(GetParent(hwnd), // Owner
1, // Number of objects
(LPCITEMIDLIST*)&lplvid->pidl, // pidl
IID_IContextMenu, NULL, (void**)&lpcm)) {
cmi.cbSize = sizeof(CMINVOKECOMMANDINFO);
cmi.fMask = 0;
cmi.hwnd = GetParent(hwnd);
cmi.lpVerb = lpVerb;
cmi.lpParameters = NULL;
cmi.lpDirectory = NULL;
cmi.nShow = SW_SHOWNORMAL;
cmi.dwHotKey = 0;
cmi.hIcon = NULL;
if (NOERROR != lpcm->InvokeCommand(&cmi))
bSuccess = FALSE;
lpcm->Release();
} else
bSuccess = FALSE;
return bSuccess;
}
示例4: DriveBox_PropertyDlg
// Shows standard Win95 Property Dlg for selected Drive
BOOL DriveBox_PropertyDlg(HWND hwnd) {
COMBOBOXEXITEM cbei;
LPDC_ITEMDATA lpdcid;
int iItem;
LPCONTEXTMENU lpcm;
CMINVOKECOMMANDINFO cmi;
BOOL bSuccess = TRUE;
static const char* lpVerb = "properties";
iItem = (int)SendMessage(hwnd, CB_GETCURSEL, 0, 0);
if (iItem == CB_ERR)
return FALSE;
cbei.mask = CBEIF_LPARAM;
cbei.iItem = iItem;
SendMessage(hwnd, CBEM_GETITEM, 0, (LPARAM)&cbei);
lpdcid = (LPDC_ITEMDATA)cbei.lParam;
if (NOERROR ==
lpdcid->lpsf->GetUIObjectOf(GetParent(hwnd), // Owner
1, // Number of objects
(LPCITEMIDLIST*)&lpdcid->pidl, // pidl
IID_IContextMenu, NULL, (void**)&lpcm)) {
cmi.cbSize = sizeof(CMINVOKECOMMANDINFO);
cmi.fMask = 0;
cmi.hwnd = GetParent(hwnd);
cmi.lpVerb = lpVerb;
cmi.lpParameters = NULL;
cmi.lpDirectory = NULL;
cmi.nShow = SW_SHOWNORMAL;
cmi.dwHotKey = 0;
cmi.hIcon = NULL;
if (NOERROR != lpcm->InvokeCommand(&cmi))
bSuccess = FALSE;
lpcm->Release();
} else
bSuccess = FALSE;
return bSuccess;
}
示例5: Invoke
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
void ShellContext::Invoke(int nCmd)
{
HRESULT hr = S_OK;
if (19 == nCmd) // rename
{
TCHAR oldName[256]; TCHAR newName[256]; WCHAR newNameW[256];
sh_get_displayname(psfFolder, pidlItem, SHGDN_NORMAL, oldName);
if (IDOK == EditBox(_T("bbLean"), _T("Enter new name:"), oldName, newName, 256))
{
#ifdef UNICODE
wcsncpy_s(newNameW, 256, newName, _TRUNCATE);
#else
MultiByteToWideChar (CP_ACP, 0, newName, -1, newNameW, 256);
#endif
hr = psfFolder->SetNameOf(NULL, pidlItem, newNameW, SHGDN_NORMAL, NULL);
}
}
else
{
CMINVOKECOMMANDINFO ici;
ici.cbSize = sizeof(ici);
ici.fMask = 0;//CMIC_MASK_FLAG_NO_UI;
ici.hwnd = NULL;
ici.lpVerb = (const CHAR*)(nCmd - MIN_SHELL_ID);
ici.lpParameters = NULL;
ici.lpDirectory = NULL;
ici.nShow = SW_SHOWNORMAL;
ici.dwHotKey = 0;
ici.hIcon = NULL;
hr = pContextMenu->InvokeCommand(&ici);
}
if (0==SUCCEEDED(hr))
{
;//MessageBeep(MB_OK);
}
}
示例6: showContextMenu
BOOL showContextMenu (HWND hDlg, TCHAR* FName, WNDPROC menuProc)
{
TCHAR* FileName = PathFindFileName (FName);
TCHAR FilePath [MAX_PATH];
lstrcpy (FilePath, FName);
*PathFindFileName (FilePath) = L'\0';
LPSHELLFOLDER DesktopFolder;
if (NOERROR != SHGetDesktopFolder (&DesktopFolder))
{
return FALSE;
}
LPITEMIDLIST ParentPidl;
ULONG Eaten;
if (S_OK != DesktopFolder->ParseDisplayName (hDlg, 0, FilePath, &Eaten, &ParentPidl, 0))
{
return FALSE;
}
LPSHELLFOLDER ParentFolder;
if (S_OK != DesktopFolder->BindToObject (ParentPidl, 0, IID_IShellFolder, (void**)&ParentFolder))
{
return FALSE;
}
LPITEMIDLIST Pidl;
if (S_OK != ParentFolder->ParseDisplayName (hDlg, 0, FileName, &Eaten, &Pidl, 0))
{
return FALSE;
}
LPCONTEXTMENU CM;
if (S_OK != ParentFolder->GetUIObjectOf (hDlg, 1, (LPCITEMIDLIST*)&Pidl, IID_IContextMenu, 0, (void**)&CM))
{
return FALSE;
}
HMENU hMenu = CreatePopupMenu ();
if (hMenu == NULL)
{
return FALSE;
}
CM->QueryContextMenu (hMenu, 0, 1, 0x7FFF, CMF_EXTENDEDVERBS | CMF_EXPLORE);
WNDPROC defWndProc = (WNDPROC) SetWindowLong (hDlg, GWL_WNDPROC, (LONG)menuProc);
SetProp (hDlg, L"defWndProc", (HANDLE) defWndProc);
POINT pt;
GetCursorPos (&pt);
int Cmd = TrackPopupMenu (hMenu,
TPM_LEFTALIGN | TPM_LEFTBUTTON | TPM_RIGHTBUTTON | TPM_RETURNCMD,
pt.x, pt.y, 0, hDlg, 0);
SetWindowLong (hDlg, GWL_WNDPROC, (LONG) RemoveProp (hDlg, L"defWndProc"));
if (Cmd)
{
// Set up a CMINVOKECOMMANDINFO structure.
CMINVOKECOMMANDINFO CI;
ZeroMemory (&CI, sizeof(CMINVOKECOMMANDINFO));
CI.cbSize = sizeof (CMINVOKECOMMANDINFO);
CI.hwnd = hDlg;
CI.lpVerb = (LPCSTR) MAKEINTRESOURCE(Cmd - 1);
CI.lpParameters = "";
CI.lpDirectory = "";
CI.nShow = SW_SHOWNORMAL;
CM->InvokeCommand (&CI);
}
return DestroyMenu (hMenu);
}
示例7: OnNotify
//.........这里部分代码省略.........
}
break;
default:
{
}
}
}
m_pidlManager.Delete( pItem );
pItem = NULL;
}
}
else if( pNmhdr->code == NM_RCLICK )
{
LPITEMIDLIST* ppIdl = NULL;
int nSelCount = ListView_GetSelectedCount(m_hWnd);
if ( nSelCount > 0 )
{
ppIdl = (LPITEMIDLIST*)_Module.m_Allocator.Alloc( sizeof(LPITEMIDLIST)*nSelCount );
int iIndex = ListView_GetNextItem( m_hWnd, -1, LVIS_SELECTED );
LV_ITEM item = {0};
item.iSubItem = 0;
item.mask = LVIF_PARAM;
int _i = 0;
while( iIndex >= 0
&& _i < nSelCount )
{
item.iItem = iIndex;
ListView_GetItem( m_hWnd, &item );
ppIdl[_i] = m_pidlManager.Copy( ITEMLISTPTR(item.lParam) );
++_i;
iIndex = ListView_GetNextItem( m_hWnd, -1, LVIS_SELECTED );
}
}
LPCONTEXTMENU pMenu = NULL;
HRESULT hr = E_FAIL;
hr = m_pFolder->GetUIObjectOf( m_hWnd, nSelCount, \
(LPCITEMIDLIST*)ppIdl, IID_IContextMenu, NULL, (void**)&pMenu );
if ( FAILED(hr)
|| !pMenu)
{
LOG(_T("IID_IContextMenu Failed"));
if ( nSelCount > 0 )
{
for ( int _i = 0; _i < nSelCount; ++_i )
{
m_pidlManager.Delete( ppIdl[_i] );
}
_Module.m_Allocator.Free( ppIdl );
}
return S_OK;
}
HMENU hMenu = ::CreatePopupMenu();
if ( !hMenu )
{
if ( nSelCount > 0 )
{
for ( int _i = 0; _i < nSelCount; ++_i )
{
m_pidlManager.Delete( ppIdl[_i] );
}
_Module.m_Allocator.Free( ppIdl );
}
return S_OK;
}
hr = pMenu->QueryContextMenu( hMenu, 0, 10, 32767, CMF_NORMAL | CMF_EXPLORE );
if ( FAILED(hr) )
{
if ( nSelCount > 0 )
{
for ( int _i = 0; _i < nSelCount; ++_i )
{
m_pidlManager.Delete( ppIdl[_i] );
}
_Module.m_Allocator.Free( ppIdl );
}
DestroyMenu( hMenu );
return hr;
}
POINT point = {0};
GetCursorPos( &point );
UINT command = (UINT)TrackPopupMenu ( hMenu, TPM_RETURNCMD | TPM_LEFTALIGN, point.x, point.y, 0, m_hWnd, NULL );
CMINVOKECOMMANDINFO cmi = {0};
cmi.cbSize = sizeof (CMINVOKECOMMANDINFO);
cmi.lpVerb = (LPSTR) MAKEINTRESOURCE (command-10);
cmi.nShow = SW_SHOWNORMAL;
pMenu->InvokeCommand( &cmi );
pMenu->Release();
if ( nSelCount > 0 )
{
for ( int _i = 0; _i < nSelCount; ++_i )
{
m_pidlManager.Delete( ppIdl[_i] );
}
_Module.m_Allocator.Free( ppIdl );
}
DestroyMenu( hMenu );
}
}
TRACE_RETURN S_OK;
}
示例8: InvokeCommand
BOOL COXShellNamespaceNavigator::InvokeCommand(const LPSHELLFOLDER lpParentFolder,
const LPITEMIDLIST lpRelativeIDL,
UINT nCmdID, DWORD dwFlags) const
{
// If any command from popup menu was selected then it should be
// applied to corresponding shell object.
// So we have to fill CMINVOKECOMMANDINFO structure
CMINVOKECOMMANDINFO cmici={ sizeof(CMINVOKECOMMANDINFO) };
cmici.fMask=0;
cmici.hwnd=m_pOwnerWnd!=NULL ? m_pOwnerWnd->GetSafeHwnd() : NULL;
cmici.lpVerb=LPCSTR((UINT_PTR)nCmdID-1);
cmici.lpParameters=NULL;
cmici.lpDirectory=NULL;
cmici.nShow=SW_SHOWNORMAL;
cmici.dwHotKey=0;
cmici.hIcon=NULL;
// We can request IContextMenu interface using
// IShellFolder::GetUIObjectOf method.
//
/*
HRESULT GetUIObjectOf(
HWND hwndOwner,
UINT cidl,
LPCITEMIDLIST *apidl,
REFIID riid,
UINT *prgfInOut,
LPVOID *ppvOut
);
Retrieves an OLE interface that can be used to carry out actions on the specified
file objects or folders.
Returns NOERROR if successful, E_NOINTERFACE if the interface is not supported, or an
OLE-defined error value otherwise.
hwndOwner - Handle to the owner window that the client should specify if it
displays a dialog box or message box.
cidl - Number of file objects or subfolders specified in the apidl
parameter.
apidl - Address of an array of pointers to ITEMIDLIST structures, each of
which uniquely identifies a file object or subfolder relative to
the parent folder. Each item identifier list must contain exactly
one SHITEMID structure followed by a terminating zero.
riid - Identifier of the COM interface object to return. This can be any
valid interface identifier that can be created for an item. The
most common identifiers used by the shell are listed in the
comments at the end of this reference.
prgfInOut - Reserved.
ppvOut - Address that receives the interface pointer. If an error occurs,
a NULL pointer is returned in this address.
If cidl is greater than one, the GetUIObjectOf implementation should only succeed if
it can create one object for all items specified in apidl. If the implementation
cannot create one object for all items, this method should fail.
The following are the most common interface identifiers the shell uses when
requesting an interface from this method. The list also indicates if cidl can be
greater than one for the requested interface.
Interface Identifier Allowed cidl Value
IContextMenu The cidl parameter can be greater than or equal to one.
IContextMenu2 The cidl parameter can be greater than or equal to one.
IDataObject The cidl parameter can be greater than or equal to one.
IDropTarget The cidl parameter can only be one.
IExtractIcon The cidl parameter can only be one.
IQueryInfo The cidl parameter can only be one.
*/
LPCONTEXTMENU lpcm;
HRESULT hResult=lpParentFolder->
GetUIObjectOf(m_pOwnerWnd!=NULL ? m_pOwnerWnd->GetSafeHwnd() : NULL, 1,
(const struct _ITEMIDLIST**)&(lpRelativeIDL), IID_IContextMenu, 0,
(LPVOID*)&lpcm);
if(FAILED(hResult))
return FALSE;
// In order to apply specified command we use
// IContextMenu::InvokeCommand() method.
/*
HRESULT InvokeCommand(
LPCMINVOKECOMMANDINFO lpici
);
Carries out the command associated with a context menu item.
Returns NOERROR if successful, or an OLE-defined error code otherwise.
lpici - Address of a CMINVOKECOMMANDINFO structure containing information about
the command.
typedef struct _CMInvokeCommandInfo{
DWORD cbSize;
DWORD fMask;
HWND hwnd;
LPCSTR lpVerb;
LPCSTR lpParameters;
LPCSTR lpDirectory;
int nShow;
//.........这里部分代码省略.........