好的!所以我决定改变我的方法!我已经创建了包含工具栏和按钮的. mnu文件。菜单保存得很好,工具栏也一样,但是由于某种原因,按钮在acad重新启动后不会像以前一样停留。
- Option Explicit
- Private Declare Function GetUserName Lib "advapi32.dll" Alias _
- "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long
- Public Function User_Name()
- Dim sBuffer As String
- Dim lSize As Long
- 'Get User Name
- sBuffer = Space$(255)
- lSize = Len(sBuffer)
- Call GetUserName(sBuffer, lSize)
- If lSize > 0 Then
- User_Name = Left$(sBuffer, lSize)
- Else
- User_Name = vbNullString
- End If
- End Function
- '//*** "C:\Documents and Settings" & Replace(User_Name, Chr(0), "") & "\Application Data\Autodesk\AutoCAD 2004\R16.0\enu\Support\My_NewCustom_Menu.mnu"
- Public Function SaveT(sFiletxt As String, sFilePath As String)
- On Error Resume Next
- Open sFilePath For Output As #1
- Print #1, sFiletxt
- Close #1
- End Function
- Public Function CreateMenu() As Boolean
- Dim strFiletxt As String
- Dim strTBName As String
- Dim varSettings As Variant
- Dim intcnt As Integer
- Dim strRet As String
- Dim strMenuPath As String
- strTBName = frmCreateTB.TextBox1.Text
-
- strFiletxt = "***MENUGROUP=VBAAPPS" & vbCrLf & vbCrLf
- strFiletxt = strFiletxt & "***TOOLBARS" & vbCrLf
- strFiletxt = strFiletxt & "**" & strTBName & vbCrLf
- '& "ID_" & strTBName & "_0" & vbTab
- strFiletxt = strFiletxt & "[_Toolbar(""" & strTBName & """, _Top, _Show, 0, 0, 1)]" & vbCrLf
- For intcnt = 0 To frmCreateTB.ListBox2.ListCount - 1
- If FindRecord(frmCreateTB.ListBox2.List(intcnt), strRet) = True Then
- 'If objToolbar Is Not Nothing Then
- 'CreateButton objToolbar, strRet
- 'End If
- '0 = Name
- '1 = Description
- '2 = Macro
- '3 = Icon
- varSettings = Split(strRet, "|")
- '& "ID_" & Replace(varSettings(0), " ", "") & "_0" & vbTab
- strFiletxt = strFiletxt & "[_Button(""" & varSettings(0) & """, """ & varSettings(3) & """, """ & varSettings(3) & """)]" & "_" & varSettings(2) & vbCrLf
- End If
- Next
- strFiletxt = strFiletxt & vbCrLf
- strFiletxt = strFiletxt & "***HELPSTRINGS" & vbCrLf
- For intcnt = 0 To frmCreateTB.ListBox2.ListCount - 1
- If FindRecord(frmCreateTB.ListBox2.List(intcnt), strRet) = True Then
- varSettings = Split(strRet, "|")
- strFiletxt = strFiletxt & "ID_" & Replace(varSettings(0), " ", "") & "_0" & vbTab & "[" & varSettings(1) & "]" & vbCrLf
- End If
-
- Next
- strMenuPath = "C:\Documents and Settings" & Replace(User_Name, Chr(0), "") & "\Application Data\Autodesk\AutoCAD 2004\R16.0\enu\Support\My_NewCustom_Menu.mnu"
- SaveT strFiletxt, strMenuPath
-
- If IsMenuLoaded(strMenuPath) = False Then
- MsgBox "Error Loading Menu"
- End If
-
- End Function
- Public Function IsMenuLoaded(sPath As String) As Boolean
- On Error Resume Next
- ThisDrawing.Application.MenuGroups.Load sPath
-
- If Err.Number 0 Then
- IsMenuLoaded = True
- Err.Clear
- 'ThisDrawing.Application.MenuGroups.Item.MenuFileName
-
- Else
- IsMenuLoaded = True
- End If
-
-
- End Function
|