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仪表板),它有一些非常不错的附加功能.我的很多老主题和插件必 ...
随机推荐
- Maven(八) Maven项目和testng结合应用
要想使maven结合testng只需要在pom.xml文件中加入如下信息: <build> <plugins> <!-- invoke testng.xm ...
- 话说C# 6.0之后
最想看到的:1. 加入脚本语言支持,可以解释运行,作为程序的二次开发语言(类似于vba,python).2. 可以自定义运算符,为了安全起见,自定义运算符应该特别予以说明(类似于数学表达式,多样式的运 ...
- python 安装pyqt4
yum install PyQt4-devel yum install qtwebkit-devel pip install PySide
- Oracle-11g-r2 实例囚笼(Instance Caging)配置
实例囚笼(Instance Caging)应用场合: 在单台多 CPU 的服务器上,经常出现同时运行多个数据库实例的情况,此方式有利于提高硬件的使用率. 但是多个数据库实例运行,将会互相争用服务器资源 ...
- ubuntu ufw防火墙
由于LInux原始的防火墙工具iptables过于繁琐,所以ubuntu默认提供了一个基于iptable之上的防火墙工具ufw. ubuntu 9.10默认的便是UFW防火墙,它已经支持界面操作了.在 ...
- oracle 求班级平均分
select * from ( selectclass 班级,subject,avg(grade) avg_gradefrom student_score group by class,subject ...
- Unity中的网格与材质球合并
http://blog.csdn.net/dardgen2015/article/details/51517860
- errorlevel 续2
-------siwuxie095 %ERRORLEVEL%值一览表: ATTRIB.EXE (a) Target file/folder not found = ER ...
- 理解数据库中的undo日志、redo日志、检查点
数据库存放数据的文件,本文称其为data file. 数据库的内容在内存里是有缓存的,这里命名为db buffer.某次操作,我们取了数据库某表格中的数据,这个数据会在内存中缓存一些时间.对这个数据的 ...
- c11时间库一个小例子
#pragma once #include <chrono> #include <string> #include <iostream> #include < ...