1

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 ?

4

1 回答 1

7

idCmdFirst当您插入菜单时,您忘记兑现了。

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

(所以我是对的:您使用错误的 ID 添加了菜单项。)

请注意,由于每个上下文菜单可能有不同的 ID,因此不应使用全局。

于 2011-10-10T17:31:30.370 回答