아래는 메뉴를 생성하는 샘플코드입니다.
try
{
CComPtr pDisp;
pDisp = acedGetAcadWinApp()->GetIDispatch(TRUE);
CComPtr pComApp;
HRESULT hr = pDisp->QueryInterface(IID_IAcadApplication,(void**)&pComApp);
if(FAILED(hr)) return;
CComPtr pMenuGrps = NULL;
if(FAILED(pComApp->get_MenuGroups(&pMenuGrps))) return;
CComPtr pMenuGrp = NULL;
if(FAILED(pMenuGrps->Item(_variant_t((short)0),&pMenuGrp))) return;
CComPtr pPopupMenus = NULL;
//add a menu item to the first loaded menu group by name "AddedFromArx"
if(FAILED(pMenuGrp->get_Menus(&pPopupMenus))) return;
CComPtr pPopupMenu = NULL;
if(FAILED(pPopupMenus->Add(_bstr_t("PWPID"),&pPopupMenu))) return;
CComPtr pPopupMenuItem = NULL;
pPopupMenu->AddMenuItem(_variant_t((short)0),_bstr_t("New Project"),_bstr_t("PWPID_NEWPROJECT\n"),&pPopupMenuItem);
pPopupMenu->AddMenuItem(_variant_t((short)1),_bstr_t("Open Project"),_bstr_t("PWPID_OPENPROJECT\n"),&pPopupMenuItem);
pPopupMenu->AddSeparator(_variant_t((short)2),&pPopupMenuItem);
CComPtr pSubMenu = NULL;
pPopupMenu->AddSubMenu(_variant_t((short)3),_bstr_t("Utilities"),&pSubMenu);
pSubMenu->AddMenuItem(_variant_t((short)0),_bstr_t("Change Object Type"),_bstr_t("PWPID_CHANGEOBJECTTYPE\n"),&pPopupMenuItem);
pSubMenu->AddMenuItem(_variant_t((short)1),_bstr_t("Change Pipe Size"),_bstr_t("PWPID_CHANGEPIPESIZE\n"),&pPopupMenuItem);
pPopupMenu->AddSeparator(_variant_t((short)4),&pPopupMenuItem);
pPopupMenu->AddMenuItem(_variant_t((short)5),_bstr_t("Exit"),_bstr_t("PWPID_EXIT\n"),&pPopupMenuItem);
CComPtr pMenuBar;
pComApp->get_MenuBar(&pMenuBar);
long lCount=0L; pMenuBar->get_Count(&lCount);
pPopupMenu->InsertInMenuBar(_variant_t((long)(lCount)));
/*
//you can opt to save the menu file in compiled form
//pMenuGrp->Save((AcMenuFileType)0); //AcMenuFileType::acMenuFileCompiled
*/
}catch(_com_error &es){
//some error handling
}
댓글
댓글 쓰기