本文整理汇总了C++中LPCONTEXTMENU::QueryContextMenu方法的典型用法代码示例。如果您正苦于以下问题:C++ LPCONTEXTMENU::QueryContextMenu方法的具体用法?C++ LPCONTEXTMENU::QueryContextMenu怎么用?C++ LPCONTEXTMENU::QueryContextMenu使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类LPCONTEXTMENU
的用法示例。
在下文中一共展示了LPCONTEXTMENU::QueryContextMenu方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: ShowContextMenu
UINT CShellContextMenu::ShowContextMenu(QWidget * pParentWidget, QPoint pt, QMenu* pMenu )
{
HWND hWnd = pParentWidget->winId();
int iMenuType = 0; // to know which version of IContextMenu is supported
LPCONTEXTMENU pContextMenu; // common pointer to IContextMenu and higher version interface
if (!GetContextMenu ((void**) &pContextMenu, iMenuType))
return (0); // something went wrong
if (!m_hMenu)
{
DestroyMenu( m_hMenu );
m_hMenu = CreatePopupMenu ();
}
int i;
QList<QAction*> actionList = pMenu->actions();
for( i=0; i<actionList.count(); ++i )
{
QString s = actionList.at(i)->text();
if (!s.isEmpty())
AppendMenuW( m_hMenu, MF_STRING, i+1, (LPCWSTR)s.utf16() );
}
AppendMenuW( m_hMenu, MF_SEPARATOR, i+1, L"" );
// lets fill the our popupmenu
pContextMenu->QueryContextMenu (m_hMenu, GetMenuItemCount (m_hMenu), MIN_ID, MAX_ID, CMF_NORMAL | CMF_EXPLORE);
// subclass window to handle menurelated messages in CShellContextMenu
WNDPROC OldWndProc;
if (iMenuType > 1) // only subclass if its version 2 or 3
{
OldWndProc = (WNDPROC) SetWindowLongPtr (hWnd, GWLP_WNDPROC, (LONG_PTR) HookWndProc);
if (iMenuType == 2)
g_IContext2 = (LPCONTEXTMENU2) pContextMenu;
else // version 3
g_IContext3 = (LPCONTEXTMENU3) pContextMenu;
}
else
OldWndProc = NULL;
UINT idCommand = TrackPopupMenu (m_hMenu,TPM_RETURNCMD | TPM_LEFTALIGN, pt.x(), pt.y(), 0, pParentWidget->winId(), 0);
if (OldWndProc) // unsubclass
SetWindowLongPtr (hWnd, GWLP_WNDPROC, (LONG_PTR) OldWndProc);
if (idCommand >= MIN_ID && idCommand <= MAX_ID) // see if returned idCommand belongs to shell menu entries
{
InvokeCommand (pContextMenu, idCommand - MIN_ID); // execute related command
idCommand = 0;
}
pContextMenu->Release();
g_IContext2 = NULL;
g_IContext3 = NULL;
return (idCommand);
}
示例3: ShowContextMenu
UINT CShellContextMenu::ShowContextMenu(HWND hWnd, CPoint pt)
{
int iMenuType = 0; // to know which version of IContextMenu is supported
LPCONTEXTMENU pContextMenu; // common pointer to IContextMenu and higher version interface
if(!GetContextMenu((LPVOID*)&pContextMenu, iMenuType))
return 0; // something went wrong
if(!m_Menu)
{
delete m_Menu;
m_Menu = NULL;
m_Menu = new CMenu;
m_Menu->CreatePopupMenu();
}
// lets fill the popupmenu
pContextMenu->QueryContextMenu(m_Menu->m_hMenu, m_Menu->GetMenuItemCount(), ID_SHELLCONTEXTMENU_MIN, ID_SHELLCONTEXTMENU_MAX, CMF_NORMAL | CMF_EXPLORE);
// subclass window to handle menurelated messages in CShellContextMenu
WNDPROC OldWndProc;
if(iMenuType > 1) // only subclass if its version 2 or 3
{
OldWndProc = (WNDPROC) SetWindowLong(hWnd, GWL_WNDPROC, (DWORD) HookWndProc);
if(iMenuType == 2)
g_IContext2 = (LPCONTEXTMENU2) pContextMenu;
else // version 3
g_IContext3 = (LPCONTEXTMENU3) pContextMenu;
}
else
OldWndProc = NULL;
UINT idCommand = m_Menu->TrackPopupMenu(TPM_RETURNCMD | TPM_LEFTALIGN, pt.x, pt.y, hWnd);
if(OldWndProc) // unsubclass
SetWindowLong(hWnd, GWL_WNDPROC, (DWORD) OldWndProc);
if(idCommand >= ID_SHELLCONTEXTMENU_MIN && idCommand <= ID_SHELLCONTEXTMENU_MAX)
{
InvokeCommand(pContextMenu, idCommand - ID_SHELLCONTEXTMENU_MIN);
idCommand = 0;
}
pContextMenu->Release();
g_IContext2 = NULL;
g_IContext3 = NULL;
return idCommand;
}
示例4: ShowContextMenu
UINT CShellContextMenu::ShowContextMenu(CWnd *pWnd, CPoint pt)
{
int iMenuType = 0; // to know which version of IContextMenu is supported
LPCONTEXTMENU pContextMenu; // common pointer to IContextMenu and higher version interface
if (!GetContextMenu ((void**) &pContextMenu, iMenuType))
return (0); // something went wrong
if (m_Menu)
{
delete m_Menu;
m_Menu = NULL;
}
m_Menu = new CMenu;
m_Menu->CreatePopupMenu ();
// lets fill the our popupmenu
pContextMenu->QueryContextMenu (m_Menu->m_hMenu, m_Menu->GetMenuItemCount (), MIN_ID, MAX_ID, CMF_NORMAL | CMF_EXPLORE);
// subclass window to handle menurelated messages in CShellContextMenu
WNDPROC OldWndProc;
if (iMenuType > 1) // only subclass if its version 2 or 3
{
OldWndProc = (WNDPROC) SetWindowLong (pWnd->m_hWnd, GWL_WNDPROC, (DWORD) HookWndProc);
if (iMenuType == 2)
g_IContext2 = (LPCONTEXTMENU2) pContextMenu;
else // version 3
g_IContext3 = (LPCONTEXTMENU3) pContextMenu;
}
else
OldWndProc = NULL;
UINT idCommand = m_Menu->TrackPopupMenu (TPM_RETURNCMD | TPM_LEFTALIGN, pt.x, pt.y, pWnd);
if (OldWndProc) // unsubclass
SetWindowLong (pWnd->m_hWnd, GWL_WNDPROC, (DWORD) OldWndProc);
if (idCommand >= MIN_ID && idCommand <= MAX_ID) // see if returned idCommand belongs to shell menu entries
{
InvokeCommand (pContextMenu, idCommand - MIN_ID); // execute related command
idCommand = 0;
}
pContextMenu->Release();
g_IContext2 = NULL;
g_IContext3 = NULL;
return (idCommand);
}
示例5: ShowContextMenu
UINT CShellContextMenu::ShowContextMenu(CWnd *pWnd, POINT pt)
{
int iMenuType = 0; // to know which version of IContextMenu is supported
LPCONTEXTMENU pContextMenu; // common pointer to IContextMenu and higher version interface
if (!GetContextMenu ((void**) &pContextMenu, iMenuType))
return (0); // something went wrong
if (!m_Menu)
{
delete m_Menu;
m_Menu = NULL;
m_Menu = new CMenu;
m_Menu->CreatePopupMenu ();
m_Menu->AppendMenu(MF_STRING, WM_MENU_FILE,_T("打开文件所在目录"));
// lets fill the our popupmenu
pContextMenu->QueryContextMenu(m_Menu->m_hMenu, m_Menu->GetMenuItemCount(), MIN_ID, MAX_ID, CMF_NORMAL | CMF_EXPLORE);
}
if (iMenuType > 1) // only subclass if its version 2 or 3
{
if (iMenuType == 2)
g_IContext2 = (LPCONTEXTMENU2) pContextMenu;
else // version 3
g_IContext3 = (LPCONTEXTMENU3) pContextMenu;
}
UINT idCommand = m_Menu->TrackPopupMenu (TPM_RETURNCMD | TPM_LEFTALIGN, pt.x, pt.y, pWnd);
if (idCommand >= MIN_ID && idCommand <= MAX_ID) // see if returned idCommand belongs to shell menu entries
{
InvokeCommand (pContextMenu, idCommand - MIN_ID); // execute related command
idCommand = 0;
}
pContextMenu->Release();
g_IContext2 = NULL;
g_IContext3 = NULL;
return (idCommand);
}
示例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
//.........这里部分代码省略.........
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;
DWORD dwHotKey;
HANDLE hIcon;
} CMINVOKECOMMANDINFO, *LPCMINVOKECOMMANDINFO;
Contains information about a context menu command.
cbSize - Contains the size of this structure, in bytes.
fMask - Zero, or one or more of the following flags:
CMIC_MASK_HOTKEY - The dwHotKey member is valid.
CMIC_MASK_ICON - The hIcon member is valid.
CMIC_MASK_FLAG_NO_UI- The system is prevented from
displaying user interface
elements (for example, error
messages) while carrying out
a command.
hwnd - Handle of the window that is the owner of the context
menu. An extension can also use this handle as the
owner of any message boxes or dialog boxes it displays.
lpVerb - A 32-bit value that contains zero in the high-order
word and a menu-identifier offset of the command to
carry out in the low-order word. The shell specifies
this value (using the MAKEINTRESOURCE macro) when the
user chooses a menu command. If the high-order word
is not zero, this member is the address of a
null-terminated string specifying the
language-independent name of the command to carry out.
This member is typically a string when a command is
being activated by an application. The system provides
predefined constant values for the following command
strings.
Value String
CMDSTR_NEWFOLDER "NewFolder"
CMDSTR_VIEWDETAILS "ViewDetails"
CMDSTR_VIEWLIST "ViewList"
lpParameters - Optional parameters. This member is always NULL for
menu items inserted by a shell extension.
lpDirectory - Optional working directory name. This member is always
NULL for menu items inserted by a shell extension.
nShow - Set of SW_ values to pass to the ShowWindow function
if the command displays a window or starts an
application.
dwHotKey - Optional hot key to assign to any application
activated by the command. If the fMask parameter does
not specify CMIC_MASK_HOTKEY, this member is ignored.
hIcon - Icon to use for any application activated by the
command. If the fMask member does not specify
CMIC_MASK_ICON, this member is ignored.
The shell calls this method when the user chooses a command that the handler added
to a context menu. This method may also be called by an application without any
corresponding user action.
*/
HMENU hMenu=::CreatePopupMenu();
if(hMenu==NULL)
{
TRACE(_T("COXShellNamespaceNavigator::GetObjectContextMenu: CreatePopupMenu() failed\n"));
return NULL;
}
hResult=lpcm->QueryContextMenu(hMenu,0,1,0x7fff,dwFlags);
if(FAILED(hResult))
{
TRACE(_T("COXShellNamespaceNavigator::GetObjectContextMenu: QueryContextMenu() failed\n"));
::DestroyMenu(hMenu);
return NULL;
}
hResult=lpcm->InvokeCommand(&cmici);
::DestroyMenu(hMenu);
lpcm->Release();
if(FAILED(hResult))
{
TRACE(_T("COXShellNamespaceNavigator::InvokeCommand: InvokeCommand() failed\n"));
return FALSE;
}
return TRUE;
}
示例9: GetUIObjectOf
HMENU COXShellNamespaceNavigator::
GetObjectContextMenu(const LPSHELLFOLDER lpParentFolder,
const LPITEMIDLIST lpRelativeIDL, DWORD dwFlags) const
{
// 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 NULL;
// Use IContextMenu::QueryContextMenu method to get handle to popup menu.
//
/*
HRESULT QueryContextMenu(
HMENU hmenu,
UINT indexMenu,
UINT idCmdFirst,
UINT idCmdLast,
UINT uFlags
);
Adds menu items to the specified menu. The menu items should be inserted in the menu
at the position specified by indexMenu, and their menu item identifiers must be
between the idCmdFirst and idCmdLast parameter values.
Returns an HRESULT structure in which, if the method is successful, the code member
contains the menu identifier of the last menu item added plus one.
hmenu - Handle to the menu. The handler should specify this handle when
adding menu items.
indexMenu - Zero-based position at which to insert the first menu item.
idCmdFirst - Minimum value that the handler can specify for a menu item identifier.
idCmdLast - Maximum value that the handler can specify for a menu item identifier.
uFlags - Optional flags specifying how the context menu can be changed. Can be
any combination of the following values:
CMF_CANRENAME - This flag is set if the calling application
supports renaming of items. A context menu
extension or drag-and-drop handler should
ignore this flag. A namespace extension should
add a rename item to the menu if applicable.
CMF_DEFAULTONLY - This flag is set when the user is activating
the default action, typically by
double-clicking. This flag provides a hint for
the context menu extension to add nothing if
it does not modify the default item in the
menu. A context menu extension or
drag-and-drop handler should not add any menu
//.........这里部分代码省略.........