views:

96

answers:

0

Hi,

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" (http://www.nanoant.com/programming/themed-menus-icons-a-complete-vista-xp-solution) 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