明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 1710|回复: 2

求助:关于创建AutoCAD菜单的疑问

[复制链接]
发表于 2003-9-6 16:39:00 | 显示全部楼层 |阅读模式
第一次运行时没有问题,但后来再运行时不知道为什么“Public Sub DeleteMenu()”段就运行不了,说是方法“Item"作用于"IAcadPopupmenus"失败。我将菜单名改为中文时也会出现错误。

Public Sub CreateMenu()

    Dim curMenuGroup As AcadMenuGroup
    Set curMenuGroup = ThisDrawing.Application.MenuGroups.Item(0)
   
    Dim newMenu As AcadPopupMenu
    Set newMenu = curMenuGroup.Menus.Add("Te" + Chr(Asc("&")) + "stMenu1")
   
   
    Dim openMacro As String
    Dim saveMacro As String
    Dim editMacro As String

    openMacro = Chr(3) + Chr(3) + Chr(95) + "open" + Chr(32) '即VBA中的ESC ESC _Open
    saveMacro = Chr(3) + Chr(3) + Chr(95) + "save" + Chr(32) '即VBA中的ESC ESC _Save
    editMacro = Chr(3) + Chr(3) + Chr(95) + "edit" + Chr(32) '即VBA中的ESC ESC _Edit
   
    Dim openMenuItem As AcadPopupMenuItem
    Dim saveMenuItem As AcadPopupMenuItem
    Dim editMenuItem As AcadPopupMenuItem
    Dim sepaMenuItem As AcadPopupMenuItem
   
    Set openMenuItem = newMenu.AddMenuItem _
         (newMenu.Count + 1, Chr(Asc("&")) + "Open", openMacro)
    Set sepaMenuItem = newMenu.AddSeparator(newMenu.Count + 1)
    Set saveMenuItem = newMenu.AddMenuItem _
         (newMenu.Count + 1, Chr(Asc("&")) + "Save", saveMacro)
    Set sepaMenuItem = newMenu.AddSeparator(newMenu.Count + 1)
    Set editMenuItem = newMenu.AddMenuItem _
         (newMenu.Count + 1, Chr(Asc("&")) + "Edit", editMacro)
   
        Dim saveasSubMenu As AcadPopupMenu
        Set saveasSubMenu = newMenu.AddSubMenu(newMenu.Count + 1, "SaveAsFile")
        Dim subMenuItem As AcadPopupMenuItem
        Dim subMacro As String
        subMacro = Chr(3) + Chr(3) + Chr(95) + "SaveAs" + Chr(32)
        Set subMenuItem = saveasSubMenu.AddMenuItem _
                  (saveasSubMenu.Count + 1, "SaveAs", subMacro)
   
    editMenuItem.Enable = False

    newMenu.InsertInMenuBar (ThisDrawing.Application.MenuBar.Count + 1)

End Sub



Public Sub CreateShortCutMenu()
   
    Dim curMenuGroup As AcadMenuGroup
    Set curMenuGroup = ThisDrawing.Application.MenuGroups.Item(0)
    '
    Dim scMenu As AcadPopupMenu
    Dim entMenu As AcadPopupMenu
   
    For Each entMenu In curMenuGroup.Menus
      If entMenu.ShortcutMenu = True Then
        Set scMenu = entMenu
      Else
        Exit Sub
      End If
    Next entMenu
   
    Dim scMenuItem As AcadPopupMenuItem
    Dim openMacro As String
    openMacro = Chr(3) + Chr(3) + Chr(95) + "open" + Chr(32)
    '
    Set scMenuItem = scMenu.AddMenuItem _
               (scMenu.Count + 1, Chr(Asc("&")) + "OpenDWG", openMacro)

End Sub

Public Sub DeleteMenu()

    Dim curMenuGroup As AcadMenuGroup
    Set curMenuGroup = ThisDrawing.Application.MenuGroups.Item(0)
   
    Dim oldMenu As AcadPopupMenu
    Set oldMenu = curMenuGroup.Menus.Item("Te" + Chr(Asc("&")) + "stMenu")
   
     oldMenu.RemoveFromMenuBar

End Sub
 楼主| 发表于 2003-9-6 16:44:00 | 显示全部楼层
这也许是个非常简单的问题,不过我实在是刚开始学,什么也不懂,还是要指高人指点^_^
发表于 2003-9-6 17:50:00 | 显示全部楼层
你少了一个1怎么能删除呢。
    Set oldMenu = curMenuGroup.Menus.Item("Te" + Chr(Asc("&")) + "stMenu1")
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2024-11-28 14:54 , Processed in 0.168052 second(s), 22 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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