分享
 
 
 

在ARX中通过COM在ACAD中添加菜单和工具条

王朝other·作者佚名  2006-01-09
窄屏简体版  字體: |||超大  

代码如下:

extern "C" AcRx::AppRetCode

acrxEntryPoint(AcRx::AppMsgCode msg, void* pkt)

{

switch (msg) {

case AcRx::kInitAppMsg:

// Comment out the following line if your

// application should be locked into memory

acrxDynamicLinker->unlockApplication(pkt);

acrxDynamicLinker->registerAppMDIAware(pkt);

InitApplication();

addMenuThroughMfcCom();

break;

case AcRx::kUnloadAppMsg:

UnloadApplication();

break;

}

return AcRx::kRetOK;

}

void addMenuThroughMfcCom()

{

TRY

{

IAcadApplication IAcad(acedGetAcadWinApp()->GetIDispatch(TRUE));

IAcadMenuBar IMenuBar(IAcad.GetMenuBar());

long numberOfMenus;

numberOfMenus = IMenuBar.GetCount();

IAcadMenuGroups IMenuGroups(IAcad.GetMenuGroups());

VARIANT index;

VariantInit(&index);

V_VT(&index) = VT_I4;

V_I4(&index) = 0;

IAcadMenuGroup IMenuGroup(IMenuGroups.Item(index));

IAcadPopupMenus IPopUpMenus(IMenuGroup.GetMenus());

CString cstrMenuName = "灵宇断面(&L)";

VariantInit(&index);

V_VT(&index) = VT_BSTR;

V_BSTR(&index) = cstrMenuName.AllocSysString();

IDispatch* pDisp=NULL;

//see if the menu is already there

TRY{pDisp = IPopUpMenus.Item(index); pDisp->AddRef();} CATCH(COleDispatchException,e){}END_CATCH;

VariantClear(&index);

if (pDisp==NULL) {

//create it

IAcadPopupMenu IPopUpMenu(IPopUpMenus.Add(cstrMenuName));

VariantInit(&index);

V_VT(&index) = VT_I4;

V_I4(&index) = 0;

IPopUpMenu.AddMenuItem(index, "横断面成图(&H)", "HDM ");

VariantInit(&index);

V_VT(&index) = VT_I4;

V_I4(&index) = 1;

IPopUpMenu.AddMenuItem(index, "纵断面成图(&Z)", "ZDM ");

VariantInit(&index);

V_VT(&index) = VT_I4;

V_I4(&index) = 2;

IPopUpMenu.AddSeparator(index);

VariantInit(&index);

V_VT(&index) = VT_I4;

V_I4(&index) = 3;

IPopUpMenu.AddMenuItem(index, "灵宇断面帮助(&B)", "DMHELP ");

pDisp = IPopUpMenu.m_lpDispatch;

pDisp->AddRef();

}

IAcadPopupMenu IPopUpMenu(pDisp);

if (!IPopUpMenu.GetOnMenuBar())

{

VariantInit(&index);

V_VT(&index) = VT_I4;

V_I4(&index) = numberOfMenus - 2;;

IPopUpMenu.InsertInMenuBar(index);

}

else

{

VariantInit(&index);

V_VT(&index) = VT_BSTR;

V_BSTR(&index) = cstrMenuName.AllocSysString();

IPopUpMenus.RemoveMenuFromMenuBar(index);

VariantClear(&index);

}

pDisp->Release();

}

CATCH(COleDispatchException,e)

{

e->ReportError();

e->Delete();

}

END_CATCH;

}

也可以用相同的方法添加工具条,这样加入的工具条和CAD本身的完全相同。代码如下:

void AddDMToolbar()

{

IAcadApplication acad;

IDispatch *pDisp = acedGetAcadWinApp()->

GetIDispatch(TRUE); //AddRef is called on the pointer

acad.AttachDispatch(pDisp); // does not call AddRef()

IAcadMenuGroups acMenuGroups ( acad.GetMenuGroups() );

IAcadMenuGroup acMenu;

CComVariant vt;

long cnt = acMenuGroups.GetCount();

for ( long i = 0; i < cnt; i++ )

{

vt = i;

acMenu = acMenuGroups.Item( vt );

CString cgrpName = acMenu.GetName();

if ( cgrpName.CompareNoCase( "Acad" ) == 0 )

{

break;

}

}

IAcadToolbars acToolbars (acMenu.GetToolbars());

CString sToolbarName = "断面";

IAcadToolbar acToolbar;

cnt = acToolbars.GetCount();

for ( i = 0; i < cnt; i++ )

{

vt = i;

acToolbar = acToolbars.Item( vt );

if( acToolbar.GetName() == sToolbarName )

{

return;

}

}

CString appFileName = acedGetAppName(); //取出完整的应用程序名称,含路径

char dir[_MAX_DIR], drive[_MAX_DRIVE], path[_MAX_PATH];

_splitpath(appFileName, drive, dir, NULL, NULL);

_makepath(path, drive, dir, NULL, NULL);

try

{

acToolbar = acToolbars.Add ( sToolbarName );

acToolbar.SetVisible( true );

acToolbar.Dock( 0 );

COleVariant flyOutButton;

IAcadToolbarItem acToolbarItem;

CString bmpFile;

vt = 0;

acToolbarItem = acToolbar.AddToolbarButton( vt, "横断面","绘制横断面图", "hdm ", flyOutButton );

bmpFile.Format( "%s%s", path, "hdm.bmp" );

acToolbarItem.SetBitmaps ( bmpFile, bmpFile );

vt = 1;

acToolbarItem = acToolbar.AddToolbarButton( vt, "纵断面","绘制纵断面图", "zdm ", flyOutButton );

bmpFile.Format( "%s%s", path, "zdm.bmp" );

acToolbarItem.SetBitmaps ( bmpFile, bmpFile );

vt = 2;

acToolbarItem = acToolbar.AddToolbarButton( vt, "帮助","显示软件帮助信息", "dmhelp ", flyOutButton );

bmpFile.Format( "%s%s", path, "help.bmp" );

acToolbarItem.SetBitmaps ( bmpFile, bmpFile );

}

catch(...)

{

//acutPrintf("\n创建断面工具条失败!");

//acutPrintf("\n请与作者联系");

return;

}

}

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
2023年上半年GDP全球前十五强
 百态   2023-10-24
美众议院议长启动对拜登的弹劾调查
 百态   2023-09-13
上海、济南、武汉等多地出现不明坠落物
 探索   2023-09-06
印度或要将国名改为“巴拉特”
 百态   2023-09-06
男子为女友送行,买票不登机被捕
 百态   2023-08-20
手机地震预警功能怎么开?
 干货   2023-08-06
女子4年卖2套房花700多万做美容:不但没变美脸,面部还出现变形
 百态   2023-08-04
住户一楼被水淹 还冲来8头猪
 百态   2023-07-31
女子体内爬出大量瓜子状活虫
 百态   2023-07-25
地球连续35年收到神秘规律性信号,网友:不要回答!
 探索   2023-07-21
全球镓价格本周大涨27%
 探索   2023-07-09
钱都流向了那些不缺钱的人,苦都留给了能吃苦的人
 探索   2023-07-02
倩女手游刀客魅者强控制(强混乱强眩晕强睡眠)和对应控制抗性的关系
 百态   2020-08-20
美国5月9日最新疫情:美国确诊人数突破131万
 百态   2020-05-09
荷兰政府宣布将集体辞职
 干货   2020-04-30
倩女幽魂手游师徒任务情义春秋猜成语答案逍遥观:鹏程万里
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案神机营:射石饮羽
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案昆仑山:拔刀相助
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案天工阁:鬼斧神工
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案丝路古道:单枪匹马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:与虎谋皮
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:李代桃僵
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:指鹿为马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:小鸟依人
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:千金买邻
 干货   2019-11-12
 
推荐阅读
 
 
 
>>返回首頁<<
 
靜靜地坐在廢墟上,四周的荒凉一望無際,忽然覺得,淒涼也很美
© 2005- 王朝網路 版權所有