- 积分
- 58
- 明经币
- 个
- 注册时间
- 2020-6-20
- 在线时间
- 小时
- 威望
-
- 金钱
- 个
- 贡献
-
- 激情
-
|
addMenuThroughMfcCom()
{
TRY
{
CAcadApplication IAcad(acedGetAcadWinApp()->GetIDispatch(TRUE));
CAcadMenuBar IMenuBar(IAcad.get_MenuBar());
long numberOfMenus;
numberOfMenus = IMenuBar.get_Count();
acutPrintf(L"numberOfMenus=%d",numberOfMenus);
CAcadMenuGroups IMenuGroups(IAcad.get_MenuGroups());
VARIANT index;
VariantInit(&index);
V_VT(&index) = VT_I4;
V_I4(&index) = 0;
CAcadMenuGroup IMenuGroup(IMenuGroups.Item(index));
CAcadPopupMenus IPopUpMenus(IMenuGroup.get_Menus());
CString cstrMenuName = _T("AsdkComAccess");
VariantInit(&index);
V_VT(&index) = VT_BSTR;
V_BSTR(&index) = cstrMenuName.AllocSysString();
IDispatch* pDisp=NULL;
//see if the menu is already there
TRY{pDisp = IPopUpMenus.Item(index); pDisp->AddRef();} CATCH(COleDispatchException,e){}END_CATCH;
if (pDisp==NULL) {
//create it
CAcadPopupMenu IPopUpMenu(IPopUpMenus.Add(cstrMenuName));
VariantInit(&index);
V_VT(&index) = VT_I4;
V_I4(&index) = 0;
IPopUpMenu.AddMenuItem(index, _T("&Add A ComCircle"), _T("_AsdkMfcComCircle "));
VariantInit(&index);
V_VT(&index) = VT_I4;
V_I4(&index) = 1;
IPopUpMenu.AddSeparator(index);
VariantInit(&index);
V_VT(&index) = VT_I4;
V_I4(&index) = 2;
IPopUpMenu.AddMenuItem(index, _T("Auto&LISP Example"), _T("(prin1 \"Hello\") "));
pDisp = IPopUpMenu.m_lpDispatch;
pDisp->AddRef();
}
CAcadPopupMenu IPopUpMenu(pDisp);
if (!IPopUpMenu.get_OnMenuBar())
{
VariantInit(&index);
V_VT(&index) = VT_I4;
V_I4(&index) = numberOfMenus +1;;
IPopUpMenu.InsertInMenuBar(index);
}
else
{
VariantInit(&index);
V_VT(&index) = VT_BSTR;
V_BSTR(&index) = cstrMenuName.AllocSysString();
IPopUpMenus.RemoveMenuFromMenuBar(index);
VariantClear(&index);
}
pDisp->Release();
}
CATCH(COleDispatchException,e)
{
e->ReportError();
e->Delete();
}
END_CATCH;
}
这是objectarx带的添加菜单的例子,它在menugroups 中序号为0的menugroup菜单组中添加下拉菜单。而序号为0的menugroup是custom,不是Acad(menuload可以查看到),当前菜单是acad.cui,为什么上面的代码仍然起作用,添加进去了(添加进acad并显示,而不是显示custom.cui)
|
|