- 积分
- 362
- 明经币
- 个
- 注册时间
- 2004-8-25
- 在线时间
- 小时
- 威望
-
- 金钱
- 个
- 贡献
-
- 激情
-
|
楼主 |
发表于 2004-10-22 17:04:00
|
显示全部楼层
因为加载菜单是在InitApplication()中做的.,程序一加载就产生菜单。
我把我的InitApplication()函数贴出来:
void InitApplication() { // NOTE: DO NOT edit the following lines. //{{AFX_ARX_INIT AddCommand("BS", "DRAWDLG", "DRAWDLG", ACRX_CMD_TRANSPARENT | ACRX_CMD_USEPICKSET, BSDrawDlg); //}}AFX_ARX_INIT //修改图标和标题 CMDIFrameWnd *pp; pp=acedGetAcadFrame(); pp->SetWindowText ("BSCAD2000"); HICON hIcon = AfxGetApp()->LoadIcon(IDI_ICON1); pp->SetIcon(hIcon,FALSE); pp->UpdateWindow ();
//数据库连接字符串
m_strConnect="driver={SQL Server};Server=Ren;DATABASE=study;UID=sa"; AfxOleInit(); //初始化 BOOL Result; Result=m_adoConnection.Connect (LPCTSTR(m_strConnect),NULL); // TODO: add your initialization functions
//创建菜单的函数,下面有 createSmartDrawMenu();
AcCmColor color; CString strLayername; // color.setColorIndex (5); strLayername="01"; newLayer (strLayername,color);//自己写的建层函数,下面有 // color.setColorIndex (6); strLayername="02"; newLayer (strLayername,color); // color.setColorIndex (7); strLayername="03"; newLayer (strLayername,color); // acdbLoadLineTypeFile ("CENTER","acadiso.lin",NULL); acdbLoadLineTypeFile ("PHANTOM","acadiso.lin",NULL); // color.setColorIndex (1); strLayername="05"; newLayer (strLayername,color,"CENTER"); //border color.setColorIndex (3); strLayername="06"; newLayer (strLayername,color,"PHANTOM"); }
////////////////////////// void newLayer( CString& layerName,AcCmColor color,CString linetypeName /* = "CONTINUOUS" */ ) { AcDbLayerTable* pLayerTbl; acdbHostApplicationServices()->workingDatabase()->getSymbolTable( pLayerTbl,AcDb::kForWrite ); if ( !pLayerTbl->has( layerName ) ) { AcDbLayerTableRecord* pLayerTblRcd = new AcDbLayerTableRecord; pLayerTblRcd->setName( layerName ); pLayerTblRcd->setIsFrozen( 0 ); pLayerTblRcd->setIsOff( 0 ); pLayerTblRcd->setVPDFLT( 0 ); pLayerTblRcd->setIsLocked( 0 ); // ²ãµÄÑÕÉ« pLayerTblRcd->setColor( color ); // ÉèÖÃÏßÐÍ AcDbLinetypeTable* pLinetypeTbl; AcDbObjectId lineId; acdbHostApplicationServices()->workingDatabase()->getSymbolTable( pLinetypeTbl,AcDb::kForRead ); if ( ( pLinetypeTbl->getAt( linetypeName,lineId ) ) != Acad::eOk ) { pLinetypeTbl->getAt( "CONTINUOUS",lineId ); } pLinetypeTbl->close(); pLayerTblRcd->setLinetypeObjectId( lineId ); pLayerTbl->add( pLayerTblRcd ); pLayerTblRcd->close(); pLayerTbl->close(); } else { pLayerTbl->close(); } } ///////////////////////////////////////////////////////////////////////
void createSmartDrawMenu () { TRY { IAcadApplication bsApp(acedGetAcadWinApp()->GetIDispatch(true)); IAcadMenuBar bsMenuBar(bsApp.GetMenuBar ()); long numberOfMenus; numberOfMenus = bsMenuBar.GetCount(); IAcadMenuGroups bsMenuGroups(bsApp.GetMenuGroups ()); VARIANT index; VariantInit(&index); index.vt=VT_I4; index.lVal=0; IAcadMenuGroup bsMenuGroup(bsMenuGroups.Item (index)); IAcadPopupMenus bsPopupMenus(bsMenuGroup.GetMenus ()); CString strMenuName="菜单名"; VariantInit(&index); index.vt=VT_BSTR; index.bstrVal=strMenuName.AllocSysString (); IDispatch* pDisp=NULL; TRY { pDisp=bsPopupMenus.Item (index); pDisp->AddRef (); } CATCH(COleDispatchException,e) {} END_CATCH; if(pDisp==NULL) { // IAcadPopupMenu bsPopupMenu(bsPopupMenus.Add(strMenuName)); int i=0;// VariantInit(&index); index.vt=VT_I4; index.lVal=i; bsPopupMenu.AddMenuItem (index,"画图(&D)...","_DRAWDLG\n"); i++; pDisp=bsPopupMenu.m_lpDispatch; pDisp->AddRef (); } IAcadPopupMenu bsPopupMenu(pDisp); if(!bsPopupMenu.GetOnMenuBar ()) { VariantInit(&index); index.vt=VT_I4; index.lVal=numberOfMenus-1; bsPopupMenu.InsertInMenuBar (index); } else { VariantInit(&index); index.vt=VT_BSTR; index.bstrVal=strMenuName.AllocSysString (); bsPopupMenus.RemoveMenuFromMenuBar (index); VariantClear(&index); } pDisp->Release (); } CATCH(COleDispatchException,e) { e->ReportError(); e->Delete(); } END_CATCH; } |
|