ObjectARX动态添加AutoCAD传统下拉菜单入门篇(一)
ObjectARX动态添加传统下拉菜单入门篇 图文by edata , 转载注明出处 http://www.cnblogs.com/edata
AutoCAD 添加传统下拉菜单有很多种方式,比较典型的就是制作菜单文件mnu文本,加载(下拉菜单有的可能需要写弹出代码才能添加到菜单栏才能显示,工具条加载就能显示)。
还有另外一种方式就是使用com接口来动态添加,而com接口的使用在objectARX编程中主要有两种应用方式,代码编写不同。
下面介绍的就是com接口的第二种方式,使用#import导入tlb类型库,这种方式不用加入额外的cpp文件。
以下参考arxdev.chm的相关章节完成 ,编程测试环境,vs2010+vs2008,AutoCAD2011。
图文开始:












此处的波浪线也是因为vs还未导入tlb类型库,编译后会将tlb导出一个tlh文件,就不会提示波浪线了










后记:com虽然可以动态添加菜单,但是现在的CAD菜单都是带有图标的,貌似这种动态不能实现。
篇幅有限,仅仅概述了com动态加载菜单的一种方式,该代码还有一些问题,如有机会,再详细介绍。
附源码一份
// (C) Copyright 2002-2007 by Autodesk, Inc.
//
// Permission to use, copy, modify, and distribute this software in
// object code form for any purpose and without fee is hereby granted,
// provided that the above copyright notice appears in all copies and
// that both that copyright notice and the limited warranty and
// restricted rights notice below appear in all supporting
// documentation.
//
// AUTODESK PROVIDES THIS PROGRAM "AS IS" AND WITH ALL FAULTS.
// AUTODESK SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTY OF
// MERCHANTABILITY OR FITNESS FOR A PARTICULAR USE. AUTODESK, INC.
// DOES NOT WARRANT THAT THE OPERATION OF THE PROGRAM WILL BE
// UNINTERRUPTED OR ERROR FREE.
//
// Use, duplication, or disclosure by the U.S. Government is subject to
// restrictions set forth in FAR 52.227-19 (Commercial Computer
// Software - Restricted Rights) and DFAR 252.227-7013(c)(1)(ii)
// (Rights in Technical Data and Computer Software), as applicable.
// //-----------------------------------------------------------------------------
//----- acrxEntryPoint.cpp
//-----------------------------------------------------------------------------
#include "StdAfx.h"
#include "resource.h" //-----------------------------------------------------------------------------
#define szRDS _RXST("sk_") static bool bIsMenuLoaded = false; #import "acax18ENU.tlb" no_implementation raw_interfaces_only named_guids //-----------------------------------------------------------------------------
//----- ObjectARX EntryPoint
class CArxUseComCreateMenuApp : public AcRxArxApp { public:
CArxUseComCreateMenuApp () : AcRxArxApp () {} virtual AcRx::AppRetCode On_kInitAppMsg (void *pkt) {
// TODO: Load dependencies here // You *must* call On_kInitAppMsg here
AcRx::AppRetCode retCode =AcRxArxApp::On_kInitAppMsg (pkt) ; // TODO: Add your initialization code here return (retCode) ;
} virtual AcRx::AppRetCode On_kUnloadAppMsg (void *pkt) {
// TODO: Add your code here // You *must* call On_kUnloadAppMsg here
AcRx::AppRetCode retCode =AcRxArxApp::On_kUnloadAppMsg (pkt) ; // TODO: Unload dependencies here return (retCode) ;
} virtual void RegisterServerComponents () {
} // - sk_ArxUseComCreateMenu.AdeskComMenu command (do not rename)
static void sk_ArxUseComCreateMenuAdeskComMenu(void)
{
// Add your code for command sk_ArxUseComCreateMenu.AdeskComMenu here
AutoCAD::IAcadApplication *pAcad;
AutoCAD::IAcadMenuBar *pMenuBar;
AutoCAD::IAcadMenuGroups *pMenuGroups;
AutoCAD::IAcadMenuGroup *pMenuGroup;
AutoCAD::IAcadPopupMenus *pPopUpMenus;
AutoCAD::IAcadPopupMenu *pPopUpMenu;
AutoCAD::IAcadPopupMenuItem *pPopUpMenuItem;
HRESULT hr = NOERROR;
LPUNKNOWN pUnk = NULL;
LPDISPATCH pAcadDisp = acedGetIDispatch(TRUE);
hr = pAcadDisp->QueryInterface(AutoCAD::IID_IAcadApplication,(void**)&pAcad);
pAcadDisp->Release();
if (FAILED(hr))
return;
pAcad->put_Visible(true);
pAcad->get_MenuBar(&pMenuBar);
pAcad->get_MenuGroups(&pMenuGroups);
pAcad->Release();
long numberOfMenus;
pMenuBar->get_Count(&numberOfMenus);
pMenuBar->Release();
VARIANT index;
VariantInit(&index);
V_VT(&index) = VT_I4;
V_I4(&index) = 0;
pMenuGroups->Item(index, &pMenuGroup);
pMenuGroups->Release();
pMenuGroup->get_Menus(&pPopUpMenus);
pMenuGroup->Release();
WCHAR wstrMenuName[256];
MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, "AsdkComAccess", -1, wstrMenuName, 256);
if (!bIsMenuLoaded)
{
pPopUpMenus->Add(wstrMenuName, &pPopUpMenu);
if (pPopUpMenu != NULL)
{
pPopUpMenu->put_Name(wstrMenuName);
WCHAR wstrMenuItemName[256];
MultiByteToWideChar(CP_ACP, 0,"&Add A ComCircle",-1, wstrMenuItemName, 256);
WCHAR wstrMenuItemMacro[256];
MultiByteToWideChar(CP_ACP, 0, "AsdkComCircle ",-1, wstrMenuItemMacro, 256);
VariantInit(&index); V_VT(&index) = VT_I4; V_I4(&index) = 0;
pPopUpMenu->AddMenuItem(index, wstrMenuItemName,wstrMenuItemMacro, &pPopUpMenuItem);
VariantInit(&index);
V_VT(&index) = VT_I4;
V_I4(&index) = 1;
pPopUpMenu->AddSeparator(index, &pPopUpMenuItem);
MultiByteToWideChar(CP_ACP, 0,"Auto&LISP Example", -1,wstrMenuItemName, 256);
MultiByteToWideChar(CP_ACP, 0,"(prin1 \"Hello\") ", -1,wstrMenuItemMacro, 256);
VariantInit(&index);
V_VT(&index) = VT_I4;
V_I4(&index) = 2;
pPopUpMenu->AddMenuItem(index, wstrMenuItemName,wstrMenuItemMacro, &pPopUpMenuItem);
VariantInit(&index);
V_VT(&index) = VT_I4;
V_I4(&index) = numberOfMenus - 2;
pPopUpMenu->InsertInMenuBar(index);
pPopUpMenu->Release();
pPopUpMenuItem->Release();
bIsMenuLoaded = true;
}
else
{
acutPrintf(_T("\nMenu not created."));
}
}
else
{
VariantInit(&index);
V_VT(&index) = VT_BSTR;
V_BSTR(&index) = wstrMenuName;
pPopUpMenus->RemoveMenuFromMenuBar(index);
VariantClear(&index);
bIsMenuLoaded = false;
}
pPopUpMenus->Release();
}
} ; //-----------------------------------------------------------------------------
IMPLEMENT_ARX_ENTRYPOINT(CArxUseComCreateMenuApp) ACED_ARXCOMMAND_ENTRY_AUTO(CArxUseComCreateMenuApp, sk_ArxUseComCreateMenu, AdeskComMenu, ComMenu, ACRX_CMD_TRANSPARENT, NULL)
ObjectARX动态添加AutoCAD传统下拉菜单入门篇(一)的更多相关文章
- PropertyGrid控件动态生成属性及下拉菜单 (转)
http://blog.sina.com.cn/s/blog_6f14b7010101b91b.html https://msdn.microsoft.com/zh-cn/library/ms1718 ...
- Android_(控件)动态添加或删除Spinner下拉菜单
使用ArrayList动态数组的依赖性实现动态增减Spinner下拉菜单选项功能. 设置一个EditText输入框,当用户输入了文字并单击[添加]按钮的同时,就会将输入的值添加Spinner至下拉菜单 ...
- jQuery 实现无限任意添加下拉菜单
新学jQuery还有很多没学,今天做了个下拉菜单,按照自己的思想结合学的基础效果实现一款可以任意添加层数的下拉菜单,如果有什么建议,欢迎指教啦啦啦 我喜欢备注细一些,这样给自己也是一种理解和方便回顾哈 ...
- 关于Eclipse插件开发(四)-------给视图加下拉菜单和按钮和加入编辑器.
本例将给视图加入下拉菜单和按钮,同时再为列表添加一个右键菜单. 创建ActionGroup类 加入菜单和按钮的方法与SWT和JFace组件的一样,先创建一个ActionGroup代码如下: MyAct ...
- bootstrap多级下拉菜单
只需为下拉菜单的任意 <li> 元素添加 .dropdown-submenu 的类,并在该 <li> 元素下添加 .dropdown-menu 类的列表,就可以为该菜单项添加一 ...
- select 下拉菜单Option对象使用add(elements,index)方法动态添加
原生js 的add函数为下拉菜单增加选项 1.object.add(oElement [, iIndex]) index 可选参数:指定元素放置所在的索引号,整形值.如果没有指定值,将添加到集合的最后 ...
- 【Excle】动态更新数据下拉菜单
现在我们制作了一个简单的下拉菜单,如下: 但是随着公司的逐渐扩大,部门也变得多了,目前我是把数据范围写死的 ,所有每次添加一个部门,就得修改数据范围,那么现在我们不想修改这个范围了,想让他每次添加部门 ...
- IOS第二天-新浪微博 - 添加搜索框,弹出下拉菜单 ,代理的使用 ,HWTabBar.h(自定义TabBar)
********HWDiscoverViewController.m(发现) - (void)viewDidLoad { [super viewDidLoad]; // 创建搜索框对象 HWSearc ...
- 黄聪:TinyMCE 4 增强 添加样式、按钮、字体、下拉菜单和弹出式窗口
我最喜欢 WordPress 3.9 的更新是使用了 TinyMCE 4.0 编辑器.新的 TinyMCE 看起来看起来更整洁(真正匹配WP仪表板),它有一些非常不错的附加功能.我的很多老主题和插件必 ...
随机推荐
- react-navigation的多次点击重复跳转同一页面、不在堆栈路由页面使用navigation方法的解决思路
一.react-navigation的初使用 createStackNavigator ==> createSwitchNavigator ==> createAppContaine ...
- Spring分配置文件开发
---------------------siwuxie095 Spring 分配置文件开发 Spring 分配置文件开 ...
- linux下,MySQL默认的数据文档存储目录为/var/lib/mysql。
0.说明 Linux下更改yum默认安装的mysql路径datadir. linux下,MySQL默认的数据文档存储目录为/var/lib/mysql. 假如要把MySQL目录移到/home/data ...
- Mybatis框架的输出映射类型
Mapper.xml映射文件中定义了操作数据库的sql,每个sql是一个statement,映射文件是mybatis的核心. resultType(输出类型) 1.输出简单类型 (1)我们在UserM ...
- mybatis框架中的输入映射
mybatis.xml映射文件中定义了操作数据库的sql,每个sql是一个statement,映射文件是mybatis的核心. 输入类型: 1.传递简单类型 可以参考我之前的对于数据库增删改查的博文. ...
- MongoHelper
/* @@decription mongodbHelper @@version 1.0 @@author think_fish&&dachie @@copyright think_fi ...
- 同台机器2个网卡配置同段IP
看个例子:1.on serverifconfig eth4 192.168.1.10/24 upifconfig eth5 192.168.1.11/24 up2.on clientifconfig ...
- qt5.7 安装
http://blog.csdn.net/liang19890820/article/details/53931813#安装-qt57 安装运行出错:qt vstool 指定qt安装路径 http:/ ...
- VC获取网页标题,解决乱码问题 学习
博主不让转载 仅记录下地址 稍后 放出自己的代码 http://blog.csdn.net/friendan/article/details/11821135
- LAMP环境配置踩坑2外网无法访问
理论上我们配置LAMP环境的时候都会对httpd.config进行更改 vi /etc/httpd/conf/httpd.conf 把override node改成override all 并且开启8 ...