开发者

IContextMenu::QueryContextMenu being called, but IContextMenu::InvokeCommand doesn't

开发者 https://www.devze.com 2023-04-12 03:26 出处:网络
In my implementation of IContextMenu COM server, the QueryContextMenu gets called (can see it with logging) but InvokeCommand doesn\'t. Here is the QueryContextMenu:开发者_开发问答

In my implementation of IContextMenu COM server, the QueryContextMenu gets called (can see it with logging) but InvokeCommand doesn't. Here is the QueryContextMenu:开发者_开发问答

HRESULT ContexMenuImp::QueryContextMenu(HMENU hmenu,UINT indexMenu,UINT idCmdFirst,
    UINT idCmdLast,UINT uFlags)
{
    if (uFlags & CMF_DEFAULTONLY) {
        // shouldn't handle this situation:
        LOG("IContextMenu::QueryContextMenu:    (...,CMF_DEFAULTONLY)");
        return MAKE_HRESULT(SEVERITY_SUCCESS,FACILITY_NULL,0);
    }else if (InsertMenuItem(hmenu,indexMenu,TRUE,&globals.menuItemInfo) == FALSE){
        // error occurred:
        LOG("IContextMenu::QueryContextMenu:    Error: %d",GetLastError());
        return MAKE_HRESULT(SEVERITY_SUCCESS,FACILITY_NULL,0);
    } else{
        // the desired situation: add item to the menu:
        LOG("IContextMenu::QueryContextMenu(hMenu,indexMenu:%u,idCmdFirst:%u,idCmdLast:%u,0x%x):    All set...",
            indexMenu,idCmdFirst,idCmdLast,uFlags);
        return MAKE_HRESULT(SEVERITY_SUCCESS,FACILITY_NULL,1/*handle only a single item*/);
    }
}

Any idea why ?


You forgot to honor the idCmdFirst when you inserted the menu.

globals.menuItemInfo.wID = idCmdFirst;
globals.menuItemInfo.fMask |= MIIM_ID;

(So I was right: You added your menu items with the wrong ID.)

Note that since each context menu may have a different ID, you should not use a global.

0

精彩评论

暂无评论...
验证码 换一张
取 消