IContextMenu3 HandleMenuMsg2 is never called
I'm trying to implement a shell extension that extends IContextMenu3
and IShellExtInit
, and i'm inserting menu items using the method described in section HBMMENU_CALLBACK method but in my project the method HandleMenuMsg2
or the HandleMenuMsg
is never called.
Can anyone please explain me what is required to receive the HandleMenuMsg2
calls?
My ATL object is implemented like that:
// CTestPlugin
class ATL_NO_VTABLE CTestPlugin :
public CComObjectRootEx<CComMultiThreadModel>,
public CComCoClass<CTestPlugin, &CLSID_CTestPlugin>,
public IShellExtInit,
public IContextMenu3
{
public:
CTestPlugin();
~CTestPlugin();
HRESULT FinalConstruct();
void FinalRelease();
public:
DECLARE_REGISTRY_RESOURCEID(IDR_TESTPLUGIN)
DECLARE_NOT_AGGREGATABLE(CTestPlugin)
BEGIN_COM_MAP(CTestPlugin)
COM_INTERFACE_ENTRY(IShellExtInit)
COM_INTERFACE_ENTRY(IContextMenu)
COM_INTERFACE_ENTRY(IContextMenu2)
COM_INTERFACE_ENTRY(IContextMenu3)
END_COM_MAP()
DECLARE_PROTECT_FINAL_CONSTRUCT()
...
// IShellExtInit
STDMETHODIMP Initialize(LPCITEMIDLIST, LPDATAOBJECT, HKEY);
// IContextMenu
STDMETHODIMP GetCommandString(UINT, UINT, UINT*, LPSTR, UINT)
{ return S_OK; }
STDMETHODIMP InvokeCommand(LPCMINVOKECOMMANDINFO);
STDMETHODIMP QueryContextMenu(HMENU, UINT, UINT, UINT, UINT);
// IContextMenu2
STDMETHODIMP HandleMenuMsg(UINT uMsg, WPARAM wParam, LPARAM lParam);
// IContextMenu3
STDMETHODIMP HandleMenuMsg2(UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT *pResult);
And i'm inserting menu items like described in the nanoANT page:
bool CTestPlugin::AddNewMenuItem(HMENU hmenu, UINT un_menu_text_id, UINT un_menu_index, UINT icon, UINT& uCmdID)
{
TCHAR chText[MAX_PATH];
::LoadString(
_AtlModule.m_hResInstance,
un_menu_text_id,
chText,
MAX_PATH);
MENUITEMINFO menuiteminfo;
ZeroMemory(&menuiteminfo, sizeof(menuiteminfo));
menuiteminfo.cbSize = sizeof(menuiteminfo);
menuiteminfo.fMask = MIIM_FTYPE | MIIM_ID | MIIM_SUBMENU | MIIM_DATA | MIIM_BITMAP | MIIM_STRING;
menuiteminfo.fType = MFT_STRING;
menuiteminfo.dwTypeData = chText;
menuiteminfo.cch = _tcslen(chText);
if (icon) {
menuiteminfo.hbmpItem =
SysInfo::Instance().IsVistaOrLater()
?
_AtlModule.m_iconBitmapUtils.IconToBitmapPARGB32(_AtlModule.m_hResInstance, icon)
:
HBMMENU_CALLBACK;
}
menuiteminfo.wID = (UINT)uCmdID++;
m_mapIdToIcon[menuiteminfo.wID] = icon;
return (TRUE==InsertMenuItem(hmenu, un开发者_运维技巧_menu_index, TRUE, &menuiteminfo));
}
STDMETHODIMP CTestPlugin::HandleMenuMsg(UINT uMsg, WPARAM wParam, LPARAM lParam)
{
LRESULT res;
return HandleMenuMsg2(uMsg, wParam, lParam, &res);
}
STDMETHODIMP CTestPlugin::HandleMenuMsg2(UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT *pResult)
{
...
}
With all this the menu entries apear in explorer context menu but no images are displayed, both methods HandleMenuMsg
and HandleMenuMsg2
are never called, and the system that i'm testing is WinXP (in vista all is ok because we use the hbmpItem
).
I'm missing some inicialization or what? can anyone explain me?
Thanks
I happen to have been working on this today, and ran across your question. As I use pure WinAPI, I am not sure about the MFC semantics, but my best guess is that your QueryInterface()
probably does not handle a request for the IContextMenu3 interface.
(Although you probably solved this problem a long time ago. Still, others might find a use to knowing.)
menuiteminfo.fMask = MIIM_FTYPE | MIIM_ID | MIIM_SUBMENU | MIIM_DATA | MIIM_BITMAP | MIIM_STRING;
The fmask specifies what type of item you are inserting. On that line you say that the item is a bitmap string submenu.
Also, you specify MIIM_DATA but dont set dwMenuData
.
精彩评论