Article ID: 137038
Article Last Modified on 12/9/2003
Menu = Form.AddMenuTemplate(Name, Parent)
Form - A FormTemplate object
Name - A string specifying the Name property for the new menu
Parent - A ControlTemplate object representing the parent menu item
that the new menu item become a child of
Menu - A ControlTemplate object that will be set to the new menu
Set MyMenu = MyForm.AddMenuTemplate("mnuFile", Nothing)
Set MySubMenu = MyForm.AddMenuTemplate("mnuFileOpen", MyMenu)
MyMenu.Properties("&Caption").Value = "New Caption"
''' MODULE1.BAS
Option Explicit
#If Win16 Then
Declare Function WritePrivateProfileString Lib "KERNEL" ( _
ByVal AppName As String, ByVal KeyName As String, _
ByVal keydefault As String, ByVal FileName As String) As Integer
Declare Function GetPrivateProfileString Lib "KERNEL" ( _
ByVal AppName As String, ByVal KeyName As String, _
ByVal keydefault As String, ByVal ReturnString As String, _
ByVal NumBytes As Integer, ByVal FileName As String) As Integer
#ElseIf Win32 Then
Declare Function WritePrivateProfileString Lib "Kernel32" _
Alias "WritePrivateProfileStringA" (ByVal AppName As String, _
ByVal KeyName As String, ByVal keydefault As String, _
ByVal FileName As String) As Long
Declare Function GetPrivateProfileString Lib "Kernel32" _
Alias "GetPrivateProfileStringA" (ByVal AppName As String, _
ByVal KeyName As String, ByVal keydefault As String, _
ByVal ReturnString As String, ByVal NumBytes As Long, _
ByVal FileName As String) As Long
#End If
Sub Main()
#If Win16 Then
Const Section = "Add-Ins16"
#ElseIf Win32 Then
Const Section = "Add-Ins32"
#End If
Const BufSize = 255
Dim Ret As Variant
Dim RetStr As String
' Hide the Addin from the Task Manager
App.TaskVisible = False
' Check to see if the entry is already in the VB.ini file.
' Add if not.
RetStr = Space(BufSize)
Ret = GetPrivateProfileString(Section, "AddinExample.MenuControl", _
"NotFound", RetStr, BufSize, "VB.INI")
RetStr = Left(RetStr, Ret)
If RetStr = "NotFound" Then
WritePrivateProfileString Section, "AddinExample.MenuControl", _
"0", "VB.INI"
End If
End Sub
Property Value --------------------------------------- Instancing 1 - Creatable SingleUse Name MenuControl Public True
''' CLASS1.CLS
Option Explicit
Private ThisInstance As Object 'VBIDE.Application
Private AddInMenuLine As Object 'VBIDE.SubMenu
Private AddInID As Long
Public Sub ConnectAddIn(VBInstance As Object)
Set ThisInstance = VBInstance
Set AddInMenuLine = ThisInstance.AddInMenu.MenuItems.Add( _
"Menu Control Example")
AddInID = AddInMenuLine.ConnectEvents(Me)
End Sub
Public Sub DisconnectAddIn(Mode As Integer)
AddInMenuLine.DisconnectEvents AddInID
ThisInstance.AddInMenu.MenuItems.Remove AddInMenuLine
End Sub
Public Sub AfterClick()
Dim CurrentForm As Object 'VBIDE.FormTemplate
Dim mnuFile As Object 'VBIDE.ControlTemplate
Dim mnuFileOpen As Object 'VBIDE.ControlTemplate
Dim mnuFileSeparator As Object 'VBIDE.ControlTemplate
Dim mnuFileMRU As Object 'VBIDE.ControlTemplate
' Set a reference to the Active Form
Set CurrentForm = ThisInstance.ActiveProject.ActiveForm
' Create the top-level File menu
Set mnuFile = CurrentForm.AddMenuTemplate("mnuFile", Nothing)
mnuFile.Properties("Caption").Value = "&File"
' Add the Open menu under the File menu
Set mnuFileOpen = CurrentForm.AddMenuTemplate("mnuFileOpen", mnuFile)
mnuFileOpen.Properties("Caption").Value = "&Open"
mnuFileOpen.Properties("Shortcut").Value = vbMenuAccelCtrlO
' Add a separator
Set mnuFileSeparator = CurrentForm.AddMenuTemplate _
("mnuFileSeparator", mnuFile)
mnuFileSeparator.Properties("Caption").Value = "-"
' Add MRU under the File menu
Set mnuFileMRU = CurrentForm.AddMenuTemplate("mnuFileMRU", mnuFile)
mnuFileMRU.Properties("Caption").Value = "MRU"
mnuFileMRU.Properties("Visible").Value = False ' Make Invisible
mnuFileMRU.Properties("Index").Value = 0 ' Make into control array
End Sub
Option Value --------------------------------------- Startup Form Sub Main Project Name AddinExample StartMode OLE Server Error Trapping Break in Class Module
Additional query words: 4.00 vb4win vb4all
Keywords: KB137038