- UID
- 263615
- 积分
- 0
- 精华
- 贡献
-
- 威望
-
- 活跃度
-
- D豆
-
- 在线时间
- 小时
- 注册时间
- 2005-5-21
- 最后登录
- 1970-1-1
|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
×
我通过下面的代码在ARX中添加菜单,但是还有个问题没有解决,请教各位大虾:
在acad.rx文件中加入arx程序,CAD运行的时候加载该ARX,在On_kInitAppMsg消息中调用下面的代码调出菜单,但是菜单出不来,如果把菜单加载的代码放到一个command中,执行command,倒是可以调出菜单
我估计问题出在CAD运行的时候加载ARX,此时CAD本身的菜单还没有加载,当然程序中得不到对应的菜单对象,也就无法加载了
这个问题该如何解决?
- [FONT=courier new]
- AutoCAD::IAcadApplication *pAcad;
- AutoCAD::IAcadMenuBar *pMenuBar;
- AutoCAD::IAcadMenuGroups *pMenuGroups;
- AutoCAD::IAcadMenuGroup *pMenuGroup;
- AutoCAD::IAcadPopupMenus *pPopUpMenus;
- AutoCAD::IAcadPopupMenu *pPopUpMenu;
- AutoCAD::IAcadPopupMenuItem *pPopUpMenuItem;
- HRESULT hr = NOERROR;
- CLSID clsid;
- LPUNKNOWN pUnk = NULL;
- LPDISPATCH pAcadDisp = NULL;
- hr = ::CLSIDFromProgID(L"AutoCAD.Application", &clsid);
- if (FAILED(hr))
- return;
- if(::GetActiveObject(clsid, NULL, &pUnk) != S_OK)
- return;
- hr = pUnk->QueryInterface(IID_IDispatch, (LPVOID*) &pAcadDisp);
- pUnk->Release();
- if (FAILED(hr))
- return;
- hr = pAcadDisp->QueryInterface(AutoCAD::IID_IAcadApplication, (void**)&pAcad);
- pAcadDisp->Release();
- if (FAILED(hr))
- return;
- pAcad->put_Visible(true);
- pAcad->get_MenuBar(&pMenuBar);
- pAcad->get_MenuGroups(&pMenuGroups);
- pAcad->Release();
- long numberOfMenus;
- pMenuBar->get_Count(&numberOfMenus);
- pMenuBar->Release();
- pMenuGroups->Item(_variant_t(0), &pMenuGroup);
- pMenuGroups->Release();
- AfxMessageBox("begin Load Mneu");
- pMenuGroup->get_Menus(&pPopUpMenus);
- pMenuGroup->Release();
- if (isAdd)
- {
- AfxMessageBox("Load Mneu");
- // 创建菜单
- pPopUpMenus->Add(_bstr_t("规划管线"), &pPopUpMenu);
- // 添加菜单项
- if (pPopUpMenu != NULL)
- {
- pPopUpMenu->put_Name(_bstr_t("规划管线"));
- pPopUpMenu->AddMenuItem(_variant_t(0), _bstr_t("绘制管线"), _bstr_t("Gxline "), &pPopUpMenuItem);
- pPopUpMenu->AddSeparator(_variant_t(1), &pPopUpMenuItem);
- pPopUpMenu->AddMenuItem(_variant_t(2), _bstr_t("查询属性"), _bstr_t("getP"), &pPopUpMenuItem);
- pPopUpMenu->InsertInMenuBar(_variant_t(numberOfMenus - 2));
- pPopUpMenu->Release();
- pPopUpMenuItem->Release();
- }
- else
- {
- acutPrintf("\nMenu not created.");
- }
- }
- else
- {
- AfxMessageBox("UnLoad Mneu");
-
- pPopUpMenus->RemoveMenuFromMenuBar(_variant_t("规划管线"));
- }
- pPopUpMenus->Release();
- } [/FONT]
复制代码 |
|