- 积分
- 10513
- 明经币
- 个
- 注册时间
- 2002-6-3
- 在线时间
- 小时
- 威望
-
- 金钱
- 个
- 贡献
-
- 激情
-
|
发表于 2002-10-25 17:15:00
|
显示全部楼层
Re: 在问一个问题
本帖最后由 作者 于 2002-10-25 17:15:08 编辑
函数如下:
'锁定菜单项
Public Sub ClockMenu(ByVal Name As String, ByVal bEnable As Boolean)
Dim PMenuObj As AcadPopupMenu
Dim EntObj As AcadPopupMenuItem
Dim s As String
On Error GoTo ErrTrap
If Name = "" Then Exit Sub
If InStr(Name, "...") <> 0 Then '"..."及之后的内容不考虑
Name = Left(Name, InStr(Name, "...") - 1)
End If
If InStr(Name, "Ctrl") Then '快捷键不考虑
Name = Left(Name, InStr(Name, "Ctrl") - 1)
End If
Name = Trim(Name)
For Each PMenuObj In Application.MenuBar
For Each EntObj In PMenuObj
s = EntObj.Caption
If InStr(s, "...") <> 0 Then
s = Left(s, InStr(s, "...") - 1)
End If
If InStr(s, "Ctrl") Then
s = Left(s, InStr(s, "Ctrl") - 1)
End If
s = Trim(s)
If StrComp(s, Name, vbTextCompare) = 0 Then
EntObj.Enable = bEnable
Exit For
End If
Next
Next
Set EntObj = Nothing
Set PMenuObj = nohting
Exit Sub
ErrTrap:
If Not (EntObj Is Nothing) Then Set EntObj = Nothing
If Not (PMenuObj Is Nothing) Then Set PMenuObj = nohting
On Error GoTo 0
End Sub
使用方法:
Sub Main()
ClockMenu "新建(&N)", False
End Sub |
|