原贴

一 c++ COM接口

  1. void addMenuThroughCom()
  2. {
  3. AutoCAD::IAcadApplication *pAcad;
  4. AutoCAD::IAcadMenuBar *pMenuBar;
  5. AutoCAD::IAcadMenuGroups *pMenuGroups;
  6. AutoCAD::IAcadMenuGroup *pMenuGroup;
  7. AutoCAD::IAcadPopupMenus *pPopUpMenus;
  8. AutoCAD::IAcadPopupMenu *pPopUpMenu;
  9. AutoCAD::IAcadPopupMenuItem *pPopUpMenuItem;
  10. HRESULT hr = NOERROR;
  11. LPUNKNOWN pUnk = NULL;
  12. LPDISPATCH pAcadDisp = acedGetIDispatch(TRUE);
  13. if(pAcadDisp==NULL)
  14. return;
  15. hr = pAcadDisp->QueryInterface(AutoCAD::IID_IAcadApplication,(void**)&pAcad);
  16. pAcadDisp->Release();
  17. if (FAILED(hr))
  18. return;
  19. pAcad->put_Visible(true);
  20. pAcad->get_MenuBar(&pMenuBar);
  21. pAcad->get_MenuGroups(&pMenuGroups);
  22. pAcad->Release();
  23. long numberOfMenus;
  24. pMenuBar->get_Count(&numberOfMenus);
  25. pMenuBar->Release();
  26. VARIANT index;
  27. VariantInit(&index);
  28. V_VT(&index) = VT_I4;
  29. V_I4(&index) = 0;
  30. pMenuGroups->Item(index, &pMenuGroup);
  31. pMenuGroups->Release();
  32. pMenuGroup->get_Menus(&pPopUpMenus);
  33. pMenuGroup->Release();
  34. WCHAR wstrMenuName[256];
  35. #ifdef UNICODE
  36. _tcscpy(wstrMenuName, L"AsdkComAccess");
  37. #else // !UNICODE
  38. MultiByteToWideChar(CP_ACP, 0, "AsdkComAccess", -1, wstrMenuName, 256);
  39. #endif // !UNICODE
  40. // Enables the menu to be loaded/unloaded with the same command.
  41. if (!bIsMenuLoaded) {
  42. pPopUpMenus->Add(wstrMenuName, &pPopUpMenu);
  43. if (pPopUpMenu != NULL) {
  44. WCHAR wstrMenuItemName[256];
  45. WCHAR wstrMenuItemMacro[256];
  46. #ifdef UNICODE
  47. _tcscpy(wstrMenuItemName, L"&Add A ComCircle");
  48. _tcscpy(wstrMenuItemMacro, L"AsdkComCircle ");
  49. #else // !UNICODE
  50. MultiByteToWideChar(CP_ACP, 0, "&Add A ComCircle", -1, wstrMenuItemName, 256);
  51. MultiByteToWideChar(CP_ACP, 0, "AsdkComCircle ", -1, wstrMenuItemMacro, 256);
  52. #endif // !UNICODE
  53. VariantInit(&index);
  54. V_VT(&index) = VT_I4;
  55. V_I4(&index) = 0;
  56. pPopUpMenu->AddMenuItem(index, wstrMenuItemName, wstrMenuItemMacro, &pPopUpMenuItem);
  57. VariantInit(&index);
  58. V_VT(&index) = VT_I4;
  59. V_I4(&index) = 1;
  60. pPopUpMenu->AddSeparator(index, &pPopUpMenuItem);
  61. #ifdef UNICODE
  62. _tcscpy(wstrMenuItemName, L"Auto&LISP Example");
  63. _tcscpy(wstrMenuItemMacro, L"(prin1 \"Hello\") ");
  64. #else // !UNICODE
  65. MultiByteToWideChar(CP_ACP, 0, "Auto&LISP Example", -1, wstrMenuItemName, 256);
  66. MultiByteToWideChar(CP_ACP, 0, "(prin1 \"Hello\") ", -1, wstrMenuItemMacro, 256);
  67. #endif // !UNICODE
  68. VariantInit(&index);
  69. V_VT(&index) = VT_I4;
  70. V_I4(&index) = 2;
  71. pPopUpMenu->AddMenuItem(index, wstrMenuItemName, wstrMenuItemMacro, &pPopUpMenuItem);
  72. VariantInit(&index);
  73. V_VT(&index) = VT_I4;
  74. V_I4(&index) = numberOfMenus - 2;
  75. pPopUpMenu->InsertInMenuBar(index);
  76. pPopUpMenuItem->Release();
  77. bIsMenuLoaded = true;
  78. } else {
  79. acutPrintf(_T("\nMenu not created."));
  80. }
  81. } else {
  82. VariantInit(&index);
  83. V_VT(&index) = VT_BSTR;
  84. V_BSTR(&index) = wstrMenuName;
  85. pPopUpMenus->RemoveMenuFromMenuBar(index);
  86. VariantClear(&index);
  87. bIsMenuLoaded = false;
  88. }
  89. pPopUpMenus->Release();
  90. }

二 C++基于MFC的

  1. void
  2. addMenuThroughMfcCom()
  3. {
  4. TRY
  5. {
  6. CAcadApplication IAcad(acedGetAcadWinApp()->GetIDispatch(TRUE));
  7. CAcadMenuBar IMenuBar(IAcad.get_MenuBar());
  8. long numberOfMenus;
  9. numberOfMenus = IMenuBar.get_Count();
  10. CAcadMenuGroups IMenuGroups(IAcad.get_MenuGroups());
  11. VARIANT index;
  12. VariantInit(&index);
  13. V_VT(&index) = VT_I4;
  14. V_I4(&index) = 0;
  15. CAcadMenuGroup IMenuGroup(IMenuGroups.Item(index));
  16. CAcadPopupMenus IPopUpMenus(IMenuGroup.get_Menus());
  17. CString cstrMenuName = _T("AsdkComAccess");
  18. VariantInit(&index);
  19. V_VT(&index) = VT_BSTR;
  20. V_BSTR(&index) = cstrMenuName.AllocSysString();
  21. IDispatch* pDisp=NULL;
  22. //see if the menu is already there
  23. TRY{pDisp = IPopUpMenus.Item(index); pDisp->AddRef();} CATCH(COleDispatchException,e){}END_CATCH;
  24. if (pDisp==NULL) {
  25. //create it
  26. CAcadPopupMenu IPopUpMenu(IPopUpMenus.Add(cstrMenuName));
  27. VariantInit(&index);
  28. V_VT(&index) = VT_I4;
  29. V_I4(&index) = 0;
  30. IPopUpMenu.AddMenuItem(index, _T("&Add A ComCircle"), _T("_AsdkMfcComCircle "));
  31. VariantInit(&index);
  32. V_VT(&index) = VT_I4;
  33. V_I4(&index) = 1;
  34. IPopUpMenu.AddSeparator(index);
  35. VariantInit(&index);
  36. V_VT(&index) = VT_I4;
  37. V_I4(&index) = 2;
  38. IPopUpMenu.AddMenuItem(index, _T("Auto&LISP Example"), _T("(prin1 \"Hello\") "));
  39. pDisp = IPopUpMenu.m_lpDispatch;
  40. pDisp->AddRef();
  41. }
  42. CAcadPopupMenu IPopUpMenu(pDisp);
  43. if (!IPopUpMenu.get_OnMenuBar())
  44. {
  45. VariantInit(&index);
  46. V_VT(&index) = VT_I4;
  47. V_I4(&index) = numberOfMenus - 2;;
  48. IPopUpMenu.InsertInMenuBar(index);
  49. }
  50. else
  51. {
  52. VariantInit(&index);
  53. V_VT(&index) = VT_BSTR;
  54. V_BSTR(&index) = cstrMenuName.AllocSysString();
  55. IPopUpMenus.RemoveMenuFromMenuBar(index);
  56. VariantClear(&index);
  57. }
  58. pDisp->Release();
  59. }
  60. CATCH(COleDispatchException,e)
  61. {
  62. e->ReportError();
  63. e->Delete();
  64. }
  65. END_CATCH;
  66. }

三 C#基于COM接口

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using System.Diagnostics;
  5. using System.Runtime.InteropServices;
  6. using Autodesk.AutoCAD.Interop;
  7. using Autodesk.AutoCAD.Interop.Common;
  8. using Autodesk.AutoCAD.ApplicationServices;
  9. using Autodesk.AutoCAD.Runtime;
  10. namespace CSharpCOM
  11. {
  12. public class Class1
  13. {
  14. public Class1() { }
  15. [CommandMethod("AM")]
  16. public static void AddMenuCom()
  17. {
  18. AcadApplication app = (AcadApplication)Marshal.GetActiveObject("AutoCAD.Application.17");
  19. AcadMenuBar menuBar = app.MenuBar;
  20. AcadMenuGroup menuGroup = app.MenuGroups.Item(0);
  21. AcadPopupMenus menus = menuGroup.Menus;
  22. AcadPopupMenu mymenu = menus.Add("MyMenu");
  23. mymenu.AddMenuItem(0, "Hello", "hello");
  24. mymenu.AddSeparator(1);
  25. mymenu.AddMenuItem(2, "Hello2", "hello");
  26. AcadPopupMenu ext = mymenu.AddSubMenu(3, "Ext");
  27. ext.AddMenuItem(0, "Hello", "hello");
  28. ext.AddSeparator(1);
  29. ext.AddMenuItem(2, "Hello2", "hello");
  30. mymenu.InsertInMenuBar(menuBar.Count - 2);
  31. }
  32. [CommandMethod("hello")]
  33. public static void Hello()
  34. {
  35. AcadApplication app = (AcadApplication)Marshal.GetActiveObject("AutoCAD.Application.17");
  36. app.ActiveDocument.Utility.Prompt("Hello\n");
  37. }
  38. }
  39. }

四 CSharp基于ACUI.DLL接口的

  1. // Copyright 2005-2007 by Autodesk, Inc.
  2. //
  3. //Permission to use, copy, modify, and distribute this software in
  4. //object code form for any purpose and without fee is hereby granted,
  5. //provided that the above copyright notice appears in all copies and
  6. //that both that copyright notice and the limited warranty and
  7. //restricted rights notice below appear in all supporting
  8. //documentation.
  9. //
  10. //AUTODESK PROVIDES THIS PROGRAM "AS IS" AND WITH ALL FAULTS.
  11. //AUTODESK SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTY OF
  12. //MERCHANTABILITY OR FITNESS FOR A PARTICULAR USE. AUTODESK, INC.
  13. using System;
  14. using System.IO;
  15. using System.Runtime.InteropServices;
  16. using System.Text;
  17. using Autodesk.AutoCAD.Runtime;
  18. using Autodesk.AutoCAD.ApplicationServices;
  19. using Autodesk.AutoCAD.EditorInput;
  20. using Autodesk.AutoCAD.DatabaseServices;
  21. using Autodesk.AutoCAD.Customization;
  22. namespace CuiSamp
  23. {
  24. /// <summary>
  25. /// Summary description for Class1.
  26. /// </summary>
  27. public class CuiSamp
  28. {
  29. #region members
  30. // All Cui files (main/partial/enterprise) have to be loaded into an object of class
  31. // CustomizationSection
  32. // cs - main AutoCAD CUI file
  33. CustomizationSection cs;
  34. CustomizationSection entCs;
  35. CustomizationSection[] partials;
  36. int numPartialFiles;
  37. YesNoIgnoreToggle yes = YesNoIgnoreToggle.yes;
  38. YesNoIgnoreToggle no = YesNoIgnoreToggle.no;
  39. // True when enterprise CUI file is loaded successfully
  40. bool entCsLoaded;
  41. // ed - access to the AutoCAD Command Line
  42. // Allows us to write messages or Issue Commands in the interface
  43. Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
  44. #endregion
  45. //Default Constructor
  46. public CuiSamp()
  47. {
  48. // retrieve the location of, and open the ACAD Main CUI File
  49. string mainCuiFile = (string)Application.GetSystemVariable("MENUNAME");
  50. mainCuiFile += ".cui";
  51. cs = new CustomizationSection(mainCuiFile);
  52. string entCuiFile = (string)Application.GetSystemVariable("ENTERPRISEMENU");
  53. if (entCuiFile.Equals("."))
  54. entCsLoaded = false;
  55. else
  56. {
  57. entCs = new CustomizationSection(entCuiFile);
  58. entCsLoaded = true;
  59. }
  60. // Code for loading all partial CUI's listed in the main CUI file
  61. partials = new CustomizationSection[cs.PartialCuiFiles.Count];
  62. int i = 0;
  63. foreach (string fileName in cs.PartialCuiFiles)
  64. {
  65. if (File.Exists(fileName))
  66. {
  67. partials[i] = new CustomizationSection(fileName);
  68. i++;
  69. }
  70. }
  71. numPartialFiles = i;
  72. }
  73. // Command: savecui
  74. // This Command saves all open CUI Files that have been modified
  75. [CommandMethod("savecui")]
  76. public void saveCui()
  77. {
  78. // Save all Changes made to the CUI file in this session.
  79. // If changes were made to the Main CUI file - save it
  80. // If changes were made to teh Partial CUI files need to save them too
  81. if (cs.IsModified)
  82. cs.Save();
  83. for (int i = 0; i < numPartialFiles; i++)
  84. {
  85. if (partials[i].IsModified)
  86. partials[i].Save();
  87. }
  88. if (entCsLoaded && entCs.IsModified)
  89. entCs.Save();
  90. // Here we unload and reload the main CUI file so the changes to the CUI file could take effect immediately.
  91. //string flName = cs.CUIFileBaseName;
  92. //Application.SetSystemVariable("FILEDIA", 0);
  93. //Application.DocumentManager.MdiActiveDocument.SendStringToExecute("cuiunload " + flName + " ", false, false, false);
  94. //Application.DocumentManager.MdiActiveDocument.SendStringToExecute("cuiload " + flName + " filedia 1 ", false, false, false);
  95. //Application.SetSystemVariable("FILEDIA", 1);
  96. }
  97. // Command: addmenu
  98. // This Command adds a new menu to all workspaces called Custom Menu, which contains 2 sub items
  99. // The Menu is first added to the Main CUI File and then added to all it's workspaces.
  100. [CommandMethod("addmenu")]
  101. public void addMenu()
  102. {
  103. if (cs.MenuGroup.PopMenus.IsNameFree("CustomMenu"))
  104. {
  105. System.Collections.Specialized.StringCollection pmAliases = new System.Collections.Specialized.StringCollection();
  106. pmAliases.Add("POP12");
  107. PopMenu pm = new PopMenu("CustomMenu", pmAliases, "CustomMenu", cs.MenuGroup);
  108. addItemsToPM(pm);
  109. addMenu2Workspaces(pm);
  110. }
  111. else
  112. ed.WriteMessage("CustomMenu already Exists\n");
  113. }
  114. // Add new Items to a PopMenu
  115. private void addItemsToPM(PopMenu pm)
  116. {
  117. PopMenuItem pmi = new PopMenuItem(pm, -1);
  118. pmi.MacroID = "ID_AUGI"; pmi.Name = "Autodesk User Group International";
  119. pmi = new PopMenuItem(pm, -1);
  120. pmi = new PopMenuItem(pm, -1);
  121. pmi.MacroID = "ID_CustomSafe"; pmi.Name = "Online Developer Center";
  122. }
  123. // Add the menu to all the workspaces
  124. private void addMenu2Workspaces(PopMenu pm)
  125. {
  126. foreach (Workspace wk in cs.Workspaces)
  127. {
  128. WorkspacePopMenu wkpm = new WorkspacePopMenu(wk, pm);
  129. wkpm.Display = 1;
  130. }
  131. }
  132. // Command: remmenu
  133. // This Command deletes the menu added above from the Main CUI File and any
  134. // workspaces that it was added to.
  135. [CommandMethod("remmenu")]
  136. public void remMenu()
  137. {
  138. // Find Index of the desired MenuItem
  139. // Remove it from all Workspaces that it exists in
  140. // Omitting this step leaves nasty left-overs in the Workspace files
  141. // Remove it from the Cui files' Menu List
  142. PopMenu pm = cs.MenuGroup.PopMenus.FindPopWithAlias("POP12");
  143. if (pm != null)
  144. {
  145. foreach (Workspace wk in cs.Workspaces)
  146. {
  147. WorkspacePopMenu wkPm = wk.WorkspacePopMenus.FindWorkspacePopMenu(pm.ElementID, pm.Parent.Name);
  148. if (wkPm != null)
  149. wk.WorkspacePopMenus.Remove(wkPm);
  150. }
  151. cs.MenuGroup.PopMenus.Remove(pm); // Deletes the Menu from ACAD Menu Group
  152. }
  153. }
  154. // Command: addtoolbar
  155. // Creates a new toolbar called "New Toolbar", and adds it to all workspaces.
  156. // This toolbar contains a Toolbar control for named view, button for drawing
  157. // a pline, and a flyout that uses the "Draw" tool bar.
  158. [CommandMethod("addtoolbar")]
  159. public void addToolbar()
  160. {
  161. Toolbar newTb = new Toolbar("New Toolbar", cs.MenuGroup);
  162. newTb.ToolbarOrient = ToolbarOrient.floating;
  163. newTb.ToolbarVisible = ToolbarVisible.show;
  164. ToolbarControl tbCtrl = new ToolbarControl(ControlType.NamedViewControl, newTb, -1);
  165. ToolbarButton tbBtn = new ToolbarButton(newTb, -1);
  166. tbBtn.Name = "PolyLine";
  167. tbBtn.MacroID = "ID_Pline";
  168. ToolbarFlyout tbFlyout = new ToolbarFlyout(newTb, -1);
  169. tbFlyout.ToolbarReference = "DRAW";
  170. foreach (Workspace wk in cs.Workspaces)
  171. {
  172. WorkspaceToolbar wkTb = new WorkspaceToolbar(wk, newTb);
  173. wk.WorkspaceToolbars.Add(wkTb);
  174. wkTb.Display = 1;
  175. }
  176. }
  177. // Command: remtoolbar
  178. // This Command removes the toolbar added above from the Main CUI File and any
  179. // workspaces that it was added to.
  180. [CommandMethod("remtoolbar")]
  181. public void remToolbar()
  182. {
  183. Toolbar tbr = cs.MenuGroup.Toolbars.FindToolbarWithName("New Toolbar");
  184. if (tbr != null)
  185. {
  186. foreach (Workspace wk in cs.Workspaces)
  187. {
  188. WorkspaceToolbar wkTb = wk.WorkspaceToolbars.FindWorkspaceToolbar(tbr.ElementID, tbr.Parent.Name);
  189. if (wkTb != null)
  190. wk.WorkspaceToolbars.Remove(wkTb);
  191. }
  192. cs.MenuGroup.Toolbars.Remove(tbr); // Deletes the toolbar from ACAD Menu Group
  193. }
  194. }
  195. // Command: cuiall
  196. // Issuing this command will run the methods to make all changes to the UI
  197. // This will add the custom menu, toolbar, and shortcut, as well as
  198. // dock the Properties palette on the right side.
  199. [CommandMethod("addcui")]
  200. public void AddMenuAndToobar()
  201. {
  202. addMenu();
  203. addToolbar();
  204. saveCui();
  205. }
  206. [CommandMethod("remcui")]
  207. public void RemMenuAndToolbar()
  208. {
  209. remMenu();
  210. remToolbar();
  211. saveCui();
  212. }
  213. }
  214. }

五 基于中望CAD2014 COM 制作工具栏(By 忘霄)

  1. //引用Interop.ZWCAD(ZWCAD.exe);ZwDatabaseMgd;ZwManaged
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Drawing;
  5. using System.IO;
  6. using ToolBar.Properties;
  7. using ZWCAD;
  8. using ZwSoft.ZwCAD.ApplicationServices;
  9. using ZwSoft.ZwCAD.Runtime;
  10. [assembly: ExtensionApplication(typeof(ToolBar.MyClass))] //启动时加载工具栏,注意typeof括号里的类库名
  11. namespace ToolBar
  12. {
  13. public partial class MyClass : IExtensionApplication //注意:重要
  14. {
  15. ZcadApplication cadApp = (ZcadApplication)Application.ZcadApplication;
  16. // atb = acadApp.MenuGroups.Item("ZWCAD").Toolbars.Add("您自己工具栏的名称");
  17. // //示例atbi = atb.AddToolbarButton(0, "工具栏名称", "帮助", "命令 ", false);
  18. // //命令后,紧跟一空格,否则处于等待状态
  19. // atbi = atb.AddToolbarButton(0, "数字文本求和", "数字文本求和", "Sum ", false);
  20. // //示例atbi.SetBitmaps(工具栏图片文件路径,工具栏图片文件路径);
  21. // atbi.SetBitmaps(acadApp.Path.Trim() + "\\***.bmp", acadApp.Path.Trim() + "\\***.bmp");
  22. // atbi = atb.AddToolbarButton(1, "批量转换", "批量转换", "dwgToPdf ", false);
  23. // atbi.SetBitmaps(acadApp.Path.Trim() + "\\***.bmp", acadApp.Path.Trim() + "\\***.bmp");
  24. // //工具栏靠右边停靠
  25. // atb.Dock(ZcToolbarDockStatus.zcToolbarDockRight);
  26. // 显示工具栏
  27. // atb.Visible = true;
  28. readonly BarItem[] AlDis = new BarItem[]
  29. {
  30. new BarItem(0, "水平左对齐", "对象水平左对齐:ATL","_ATL ", false, "aligntoleft"),
  31. new BarItem(1, "水平居中对齐", "对象水平居中对齐ATC:", "_ATC ", false, "aligntocenter"),
  32. new BarItem(2, "水平右对齐", "对象水平右对齐:ATR", "_ATR ", false, "aligntoright"),
  33. new BarItem(3, "垂直顶对齐", "对象垂直顶对齐:ALT", "_ALT ", false, "aligntotop"),
  34. new BarItem(4, "垂直居中对齐", "对象垂直居中对齐ATM:", "_ATM ", false, "aligntomiddle"),
  35. new BarItem(5, "垂直低对齐", "对象垂直低对齐:ATB", "_ATB ", false, "aligntobottom"),
  36. new BarItem(6, "水平左分布", "对象水平左分布:HDL", "_HDL ", false, "horizontaldistributionleft"),
  37. new BarItem(7, "水平居中分布", "对象水平居中分布:HDC", "_HDC ", false, "horizontaldistributioncenter"),
  38. new BarItem(8, "水平右分布", "对象水平右分布:HDR", "_HDR ", false, "horizontaldistributionright"),
  39. new BarItem(9, "垂直顶分布", "对象垂直顶分布:VDT", "_VDT ", false, "verticaldistributiontop"),
  40. new BarItem(10, "垂直居中分布", "对象垂直居中分布:VDM", "_VDM ", false, "verticaldistributioncenter"),
  41. new BarItem(11, "垂直底分布", "对象垂直底分布:VDB", "_VDB ", false, "verticaldistributionBottom"),
  42. new BarItem(12, "垂直分布间距", "对象垂直分布间距:VDS", "_VDS ", false, "verticaldistributionspacing"),
  43. new BarItem(13, "水平分布间距", "对象水平分布间距:HDS", "_HDS ", false, "horizontaldistributionspacing"),
  44. new BarItem(3),
  45. new BarItem(7),
  46. new BarItem(11),
  47. new BarItem(15)
  48. };
  49. public void Initialize()
  50. {
  51. ImgFileInitialization();
  52. CreatToolBar("对齐与分布", AlDis);//启时自动加载工具栏
  53. }
  54. public void Terminate()
  55. {
  56. //throw new NotImplementedException();
  57. }
  58. //加载工具栏
  59. public void CreatToolBar(string name, params BarItem[] toolitem)
  60. {
  61. ZcadMenuGroup currMenuGroup = cadApp.MenuGroups.Item(0);
  62. ZcadToolbar newToolBar;
  63. try
  64. {
  65. newToolBar = currMenuGroup.Toolbars.Item("对齐与分布");
  66. }
  67. catch
  68. {
  69. newToolBar = currMenuGroup.Toolbars.Add(name);
  70. foreach (BarItem item in toolitem)
  71. {
  72. ZcadToolbarItem newButton = null;
  73. if (item.isbtn)
  74. {
  75. newButton = newToolBar.AddToolbarButton(item.Index, item.Name, item.HelpString, item.Macro, item.FlyoutButton);
  76. newButton.SetBitmaps($"ZwCadToolBarBmp\\{item.SmallIconName}16.bmp", $"ZwCadToolBarBmp\\{item.LargeIconName}32.bmp");
  77. }
  78. else
  79. {
  80. newToolBar.AddSeparator(item.Index);
  81. }
  82. }
  83. currMenuGroup.Save(ZcMenuFileType.zcMenuFileSource);
  84. }
  85. //工具栏靠右边停靠
  86. //newToolBar.Dock(ZcToolbarDockStatus.zcToolbarDockRight);
  87. //显示工具条
  88. if (!newToolBar.Visible) newToolBar.Visible = true;
  89. }
  90. /// <summary>
  91. /// 图片资源初始化
  92. /// </summary>
  93. public void ImgFileInitialization()
  94. {
  95. List<string> zodiaclst = new List<string>() { "aligntobottom16", "aligntobottom32", "aligntocenter16", "aligntocenter32", "aligntoleft16", "aligntoleft32", "aligntomiddle16", "aligntomiddle32", "aligntoright16", "aligntoright32", "aligntotop16", "aligntotop32", "horizontaldistributioncenter16", "horizontaldistributioncenter32", "horizontaldistributionleft16", "horizontaldistributionleft32", "horizontaldistributionright16", "horizontaldistributionright32", "horizontaldistributionspacing16", "horizontaldistributionspacing32", "verticaldistributionBottom16", "verticaldistributionBottom32", "verticaldistributioncenter16", "verticaldistributioncenter32", "verticaldistributionspacing16", "verticaldistributionspacing32", "verticaldistributiontop16", "verticaldistributiontop32" };
  96. string localpath = $"{cadApp.Path}\\Support\\ZwCadToolBarBmp";
  97. Directory.CreateDirectory(localpath);
  98. foreach (string str in zodiaclst)
  99. {
  100. if (!File.Exists($"{localpath}\\{str}.bmp"))
  101. {
  102. Bitmap btm = (Bitmap)Resources.ResourceManager.GetObject(str, Resources.Culture);
  103. btm.Save($"{localpath}\\{str}.bmp");
  104. }
  105. }
  106. }
  107. }
  108. public partial class BarItem
  109. {
  110. public BarItem(object index, bool isbtn = false)
  111. {
  112. Index = index;
  113. this.isbtn = isbtn;
  114. }
  115. public BarItem(object index, string name, string helpString, string macro, object flyoutButton, string IconName, bool isbtn = true)
  116. {
  117. Index = index;
  118. Name = name;
  119. HelpString = helpString;
  120. Macro = macro;
  121. FlyoutButton = flyoutButton;
  122. SmallIconName = IconName;
  123. LargeIconName = IconName;
  124. this.isbtn = isbtn;
  125. }
  126. /// <summary>
  127. /// 索引值
  128. /// </summary>
  129. public object Index { set; get; }
  130. /// <summary>
  131. /// 名字/提示信息
  132. /// </summary>
  133. public string Name { set; get; }
  134. /// <summary>
  135. /// 说明
  136. /// </summary>
  137. public string HelpString { set; get; }
  138. /// <summary>
  139. /// 执行的命令
  140. /// </summary>
  141. public string Macro { set; get; }
  142. /// <summary>
  143. /// 是否是弹出式按钮
  144. /// </summary>
  145. public object FlyoutButton { set; get; }
  146. /// <summary>
  147. /// 小按钮图片
  148. /// </summary>
  149. public string SmallIconName { set; get; }
  150. /// <summary>
  151. /// 大按钮图片
  152. /// </summary>
  153. public string LargeIconName { set; get; }
  154. /// <summary>
  155. /// 是否是按钮
  156. /// </summary>
  157. public bool isbtn { set; get; }
  158. }
  159. }