//加载菜单 void loadMenu() { // 取得AutoCAD应用程序对象 IAcadApplication *acadApp = NULL; LPDISPATCH pDisp = NULL;
if (!getApplication(&pDisp)) { acadApp->Release(); return; } HRESULT hr = S_OK;
hr = pDisp->QueryInterface(IID_IAcadApplication, (LPVOID*)&acadApp); if (FAILED(hr)) { acadApp->Release(); return; } // 取得所有菜单组 IAcadMenuGroups *mnuGrps = NULL; long cnt = 0; hr = acadApp->get_MenuGroups(&mnuGrps); if (FAILED(hr)) { acadApp->Release(); return; } acadApp->Release(); // 菜单组个数 mnuGrps->get_Count(&cnt); IAcadMenuGroup *mnuGrp = NULL; // 循环所有菜单组,寻找[fan]菜单组,if false, load "fan.mnu". VARIANT vtName; vtName.vt = VT_I4; BSTR grpName; bool found = false; for (long i = 0; i < cnt; i++) { vtName.lVal = i; hr = mnuGrps->Item(vtName, &mnuGrp); if (FAILED(hr)) return; hr = mnuGrp->get_Name(&grpName); CString cgrpName(grpName); if (cgrpName.CompareNoCase("fan") == 0) { found = true; break; } } mnuGrps->Release(); if (found == false) { // CommandB(); CString mac = "(COMMAND \"_MENULOAD\" \"fan.mnu\")"; if (acDocManager->curDocument()) { acedPostCommand(mac); //如果P12不存在,则新载入的菜单加到当前菜单最后面 acedPostCommand("(menucmd \"P11=+fan.pop1\")"); } // CommandE(); } mnuGrp->Release(); return; }
bool getApplication(LPDISPATCH * pVal) { LPDISPATCH pDispatch = acedGetAcadWinApp()->GetIDispatch(TRUE); if (pDispatch == NULL) return false; *pVal = pDispatch; return true; }
另外loadmenu函数要加入到入口函数的case AcRx::kInitAppMsg:下面,这样AutoCAD可以自动加载它
再加上下面两个头文件(很大的头文件,我也不知道可不可以加小一点的头文件)
#include "acad15.h" #include "acad15_i.c" |