一、环境
系统 环境:麒麟V10 SP1 虚拟机系统 + 中望CAD2023/2024.
编程环境:QTCreate 5.12.8库
二、代码
加入头文件
#include "ZwRibbonRoot.h"
#include "RibbonRoot.h"
#include "PopMenuRoot.h"
#include "arxHeaders.h"
#include "OpCommon.h"
#include <QFile>
#include <QDomDocument>
#include <QDomElement>
#include <qstring.h>
加入命令反应类
//命令接口类
class CClassicsMenuCommand :public ICommand
{
public:
CClassicsMenuCommand()
{
}
~CClassicsMenuCommand()
{
}
virtual bool CanExecute()
{
return true;
}
//命令执行函数
virtual void Execute(CuiObject* obj)
{
PopMenuItem *item = dynamic_cast<PopMenuItem*>(obj);
if (item)
{
QString strCmd = item->getUID() + " ";
wchar_t strCmdW[1024] = { 0 };
strCmd.toWCharArray(strCmdW);
AcApDocument* pDoc = acDocManager->curDocument();
acDocManager->sendStringToExecute(pDoc,strCmdW,true,false,false);
return;
}
}
};
添加菜单代码
//获取菜单表
CClassicsMenuCommand *handler = new CClassicsMenuCommand();
ZwMenuControl *pMenuCtrl = ZwMenuControl::GetMenuControl();
if (!pMenuCtrl)
{
return;
}
//添加主菜单项目
PopMenu *pMenuMain = new PopMenu(NULL);
pMenuMain->setId("MAIN-1");
pMenuMain->init();
pMenuMain->setText("主菜单");
pMenuCtrl->AddMenu(pMenuMain);
//加入大项-1
{
PopMenu *pMenuBig = new PopMenu(NULL);
pMenuBig->init();
pMenuBig->setId("BIGMENU-0");
pMenuBig->setText("菜单大项-0");
pMenuBig->setImagePath(":/ZWCADRes/ZWCAD/IDR_MAINFRAME");
pMenuMain->addItem(pMenuBig);
{//子项
PopMenuItem *item0 = new PopMenuItem(NULL);
item0->setUserCmd(handler);
item0->setImagePath(":/ZWCADRes/ZWCAD/IDR_MAINFRAME");
item0->init();
item0->setId("SMALL-0");
item0->setUID("测试命令0");
item0->setText("子菜单0");
pMenuBig->addItem(item0);
//分隔符
PopMenuItem *itemSp = new PopMenuItem(NULL);
itemSp->init();
itemSp->setIsSeparator(true);
pMenuBig->addItem(itemSp);
PopMenuItem *item1 = new PopMenuItem(NULL);
item1->setUserCmd(handler);
item1->setImagePath(":/ZWCADRes/ZWCAD/IDR_MAINFRAME");
item1->init();
item1->setId("SMALL-1");
item1->setUID("测试命令1");
item1->setText("子菜单1");
pMenuBig->addItem(item1);
}
}