- UID
- 134234
- 积分
- 0
- 精华
- 贡献
-
- 威望
-
- 活跃度
-
- D豆
-
- 在线时间
- 小时
- 注册时间
- 2004-5-7
- 最后登录
- 1970-1-1
|
发表于 2004-8-30 20:55:48
|
显示全部楼层
用COM加载的菜单年
void YHLloadmenu()
{
// TODO: Implement the command
try
{
IAcadApplication bsApp( acedGetAcadWinApp()->GetIDispatch( TRUE ) );
IAcadMenuBar bsMenuBar( bsApp.GetMenuBar() );
long numofMenus;
numofMenus = bsMenuBar.GetCount();
IAcadMenuGroups bsGroups( bsApp.GetMenuGroups() );
VARIANT index;
::VariantInit( &index );
index.vt = VT_I4;
index.lVal = 0;
IAcadMenuGroup bsGroup( bsGroups.Item( index ) );
IAcadPopupMenus bsppMenus( bsGroup.GetMenus() );
CString strMenuName = "绘制各段(&K)";
CString strName = "拖拽图块(&Z)";
VARIANT item;
::VariantInit( &item );
item.vt = VT_BSTR;
item.bstrVal = strMenuName.AllocSysString();
IDispatch* pDisp = NULL;
TRY
{
pDisp = bsppMenus.Item( COleVariant( strMenuName ) );
pDisp->AddRef();
}
CATCH ( COleDispatchException,e )
{
}
END_CATCH;
IDispatch* pDisp2 = NULL;
VARIANT item2;
::VariantInit( &item2 );
item2.vt = VT_BSTR;
item2.bstrVal = strName.AllocSysString();
TRY
{
pDisp2 = bsppMenus.Item( COleVariant( strName ) );
pDisp2->AddRef();
}
CATCH ( COleDispatchException,e )
{
}
END_CATCH;
// 加载第一个菜单
if ( NULL == pDisp )
{
IAcadPopupMenu bsppMenu( bsppMenus.Add( strMenuName ) );
::VariantInit( &index );
index.vt = VT_I4;
index.lVal = 0;
bsppMenu.AddMenuItem( index,"混合过滤段(&H)","_drawingHHGLD\n" );
::VariantInit( &index );
index.vt = VT_I4;
index.lVal = 1;
bsppMenu.AddMenuItem( index,"盘管加湿段(&P)","_drawingHHGLD\n" );
::VariantInit( &index );
index.vt = VT_I4;
index.lVal = 2;
bsppMenu.AddMenuItem( index,"风机段(&F)","_drawingHHGLD\n" );
::VariantInit( &index );
index.vt = VT_I4;
index.lVal = 3;
bsppMenu.AddMenuItem( index,"中效过滤段(&M)","_drawingHHGLD\n" );
::VariantInit( &index );
index.vt = VT_I4;
index.lVal = 4;
bsppMenu.AddMenuItem( index,"送风段(&S)","_drawingHHGLD\n" );
pDisp = bsppMenu.m_lpDispatch;
pDisp->AddRef();
}
IAcadPopupMenu bsppMenu( pDisp );
if ( !bsppMenu.GetOnMenuBar() )
{
::VariantInit( &index );
index.vt = VT_I4;
index.lVal = numofMenus - 1;
bsppMenu.InsertInMenuBar( index );
}
else
{
bsppMenus.RemoveMenuFromMenuBar( item );
}
pDisp->Release();
// 加载第二个菜单
if ( NULL == pDisp2 )
{
IAcadPopupMenu bsppMenu( bsppMenus.Add( strName ) );
::VariantInit( &index );
index.vt = VT_I4;
index.lVal = 0;
bsppMenu.AddMenuItem( index,"过滤器主视图(&M)","_TKGLQMAIN\n" );
::VariantInit( &index );
index.vt = VT_I4;
index.lVal = 1;
bsppMenu.AddMenuItem( index,"过滤器俯视图(&G)","_TKGLQDOWN\n" );
::VariantInit( &index );
index.vt = VT_I4;
index.lVal = 2;
bsppMenu.AddSeparator( index );
::VariantInit( &index );
index.vt = VT_I4;
index.lVal = 3;
bsppMenu.AddMenuItem( index,"风机(&F)","_TKFJMAIN\n" );
::VariantInit( &index );
index.vt = VT_I4;
index.lVal = 4;
bsppMenu.AddMenuItem( index,"照明灯(&D)","_TKZMDMAIN\n" );
::VariantInit( &index );
index.vt = VT_I4;
index.lVal = 5;
bsppMenu.AddSeparator( index );
::VariantInit( &index );
index.vt = VT_I4;
index.lVal = 6;
bsppMenu.AddMenuItem( index,"检查门(&C)","_TKJCMCIRCLE\n" );
::VariantInit( &index );
index.vt = VT_I4;
index.lVal = 7;
bsppMenu.AddMenuItem( index,"检查门(&R)","_TKJCMREC\n" );
pDisp2 = bsppMenu.m_lpDispatch;
pDisp2->AddRef();
}
IAcadPopupMenu bsppMenu2( pDisp2 );
if ( !bsppMenu2.GetOnMenuBar() )
{
::VariantInit( &index );
index.vt = VT_I4;
index.lVal = numofMenus - 1;
bsppMenu2.InsertInMenuBar( index );
}
else
{
bsppMenus.RemoveMenuFromMenuBar( item );
}
pDisp2->Release();
::VariantClear( &index );
::VariantClear( &item );
}
catch ( COleDispatchException& e )
{
e.ReportError();
e.Delete();
}
catch (...)
{
// do nothing
}
} |
|