明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 2117|回复: 9

菜单重载问题请教

[复制链接]
发表于 2004-9-25 11:03:00 | 显示全部楼层 |阅读模式
菜单程序运行两遍的时候出现错误提示“无效的过程调用和参数”,有没有办法实现不管菜单程序运行多少遍都不出错?
发表于 2004-9-25 11:07:00 | 显示全部楼层
有呀,程序改一下,把你的程序贴出来呀。我这几天刚解决了这个问题
 楼主| 发表于 2004-9-25 11:20:00 | 显示全部楼层
Dim TestMenu As AcadPopupMenu
Set TestMenu = currMenuGroup.Menus.Add("软件")
'为菜单项声明变量,测试用10个
Dim newMenuItem(0 To 19) As AcadPopupMenuItem
Dim PopMenuMacro(0 To 19) As String '赋值宏字符串并创建菜单项
PopMenuMacro(0) = Chr(3) + Chr(3) + Chr(95) + "Excel_To_Map" + Chr(32)

Set newMenuItem(0) = TestMenu.AddMenuItem(TestMenu.Count + 1, "导入", PopMenuMacro(0))

' 在菜单条上显示菜单
currMenuGroup.Menus.InsertMenuInMenuBar "软件", ""
ThisDrawing.SendCommand "fileopen " & "futu.dwg" + vbCrLf
ZoomAll Exit Sub
End Sub
发表于 2004-9-26 14:27:00 | 显示全部楼层
不好意思,你的是VBA自动生成菜单,我还不太懂.我现在会CAD的菜单文件加载方法.也就是自己做一个*.MNU文件.自动加载并运行.
发表于 2004-9-26 16:15:00 | 显示全部楼层

回复

Public Sub test() Dim myMenuName As String
myMenuName = "软件" '--------------------------------------------------------
Dim currMenuGroups As AcadMenuGroups
Set currMenuGroups = ThisDrawing.Application.MenuGroups
Dim currMenuGroup As AcadMenuGroup

Dim i As Integer
Dim strMenuGrpName As String

For i = 0 To currMenuGroups.Count - 1
Set currMenuGroup = currMenuGroups.Item(i)
strMenuGrpName = currMenuGroup.Name
MsgBox strMenuGrpName
If StrComp(strMenuGrpName, "ACAD", vbTextCompare) = 0 Then
Dim popMenus As AcadPopupMenus
Set popMenus = currMenuGroup.Menus
Dim popMenu As AcadPopupMenu

Dim bExist As Boolean
bExist = False

Dim strMenuName As String

Dim j As Integer
For j = 0 To popMenus.Count - 1

Set popMenu = popMenus.Item(j)
strMenuName = popMenu.Name

If StrComp(strMenuName, myMenuName, vbTextCompare) = 0 Then
' If popMenu.OnMenuBar = True Then
' popMenus.RemoveMenuFromMenuBar (myMenuName)
' End If
bExist = True
Exit For
End If
Next

If bExist = False Then
' Create the new menu
Dim newMenu As AcadPopupMenu
Set newMenu = currMenuGroup.Menus.Add(myMenuName)

' Add a menu item to the new menu
Dim newMenuItem As AcadPopupMenuItem
Dim openMacro As String
' Assign the macro string the VB equivalent of "ESC ESC _open "
openMacro = Chr(3) & Chr(3) & Chr(95) & "open" & Chr(32)

Set newMenuItem = newMenu.AddMenuItem(newMenu.Count + 1, "Open", openMacro)

' Display the menu on the menu bar
popMenus.InsertMenuInMenuBar myMenuName, ""

End If

Exit For

End If
Next End Sub 现在不会有你说的问题了,但是有些疑问, popMenus.RemoveMenuFromMenuBar (myMenuName)不能彻底移除一个popMenu.
发表于 2004-9-26 16:31:00 | 显示全部楼层

回复

修改了一下. Public Sub test() Dim myMenuName As String
myMenuName = "软件" '--------------------------------------------------------
Dim currMenuGroups As AcadMenuGroups
Set currMenuGroups = ThisDrawing.Application.MenuGroups
Dim currMenuGroup As AcadMenuGroup

Dim i As Integer
Dim strMenuGrpName As String

For i = 0 To currMenuGroups.Count - 1
Set currMenuGroup = currMenuGroups.Item(i)
strMenuGrpName = currMenuGroup.Name
MsgBox strMenuGrpName
If StrComp(strMenuGrpName, "ACAD", vbTextCompare) = 0 Then
Dim popMenus As AcadPopupMenus
Set popMenus = currMenuGroup.Menus
Dim popMenu As AcadPopupMenu

Dim bExist As Boolean
bExist = False

Dim strMenuName As String

Dim j As Integer
For j = 0 To popMenus.Count - 1

Set popMenu = popMenus.Item(j)
strMenuName = popMenu.Name

If StrComp(strMenuName, myMenuName, vbTextCompare) = 0 Then
' Call clearPopupMenuItem(popMenu)
If popMenu.OnMenuBar = False Then
popMenus.InsertMenuInMenuBar myMenuName, ""
End If
bExist = True
Exit For
End If
Next

If bExist = False Then
' Create the new menu
Dim newMenu As AcadPopupMenu
Set newMenu = currMenuGroup.Menus.Add(myMenuName)

' Add a menu item to the new menu
Dim newMenuItem As AcadPopupMenuItem
Dim openMacro As String
' Assign the macro string the VB equivalent of "ESC ESC _open "
openMacro = Chr(3) & Chr(3) & Chr(95) & "open" & Chr(32)

Set newMenuItem = newMenu.AddMenuItem(newMenu.Count + 1, "Open", openMacro)

' Display the menu on the menu bar
popMenus.InsertMenuInMenuBar myMenuName, ""

End If

Exit For

End If
Next End Sub
 楼主| 发表于 2004-9-27 08:52:00 | 显示全部楼层
多谢斑竹,献花一朵
发表于 2004-9-28 11:24:00 | 显示全部楼层

为什么不能彻底移除一个popMenu?

本帖最后由 作者 于 2004-10-1 16:01:15 编辑

为什么不能彻底移除一个popMenu?



移除之后,下次循环还能找到?为什么?应该怎么做?
发表于 2004-10-1 16:04:00 | 显示全部楼层

[询问]如何删除popupmenu


再次请问如何彻底移除一个popMenu? popMenus.RemoveMenuFromMenuBar (myMenuName) 移除之后,下次执行程序循环AcadPopupMenus还能找到myMenuName,为什么?应该怎么做真正地删除?
发表于 2004-10-1 17:00:00 | 显示全部楼层
在AUtoCad的一次运行过程中无法移除,但是重新打开会消失
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2024-11-28 01:33 , Processed in 0.188452 second(s), 23 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表