【发布时间】:2011-12-04 11:35:05
【问题描述】:
在我的IContextMenu COM 服务器实现中,QueryContextMenu 被调用(可以通过日志记录看到)但InvokeCommand 没有。这里是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*/);
}
}
知道为什么吗?
【问题讨论】:
-
不知道。你的代码是什么样的?
-
我的超能力告诉我,您返回的是 S_OK 而不是所需的 MAKE_HRESULT,或者您添加的菜单项 ID 错误。
-
@DavidHeffernan:添加了代码。
-
@RaymondChen:这里的直觉不好 :-) 会很高兴进行更多尝试。
标签: c++ windows com atl com-server