Menus and submenus using Visio-API

K

KemnitzerH

Hi there.

I've got a question building custom menubars in visio 2003. I'm using the
Visio-API, generating the menubar
with "BuiltInMenus"
I've created a Visio COM-AddIn with Visio 2003 SDK using Visual Studio
(VB.NET) - it's working fine. The Menu
will be created by opening/creating a new Visio-Document. But - the problem
is: I want to build Menu and Sub-Menu
(hierarchical). The code is only creating the menu (not the submenu).
So I decided to test the code in VBA - it works! So, where is my problem.
Where is my error in the code? I'm happy
getting any kind of answer.

###################################################
Public Sub CreateMenus(ByVal visioDocument As
Microsoft.Office.Interop.Visio.Document)

Dim visioApplication As Microsoft.Office.Interop.Visio.Application
Dim visioUIObject As Microsoft.Office.Interop.Visio.UIObject
Dim visioMenuSetsObject As Microsoft.Office.Interop.Visio.MenuSets
Dim visioMenuSetObject As Microsoft.Office.Interop.Visio.MenuSet
Dim visioMenusObject As Microsoft.Office.Interop.Visio.Menus
Dim visioMenuObject As Microsoft.Office.Interop.Visio.Menu
Dim visioMenuItemsObject As Microsoft.Office.Interop.Visio.MenuItems
Dim visioMenuItemObject As Microsoft.Office.Interop.Visio.MenuItem

visioApplication = CType(visioDocument.Application, _
Microsoft.Office.Interop.Visio.Application)

If Not (visioApplication Is Nothing) Then
visioUIObject = visioApplication.BuiltInMenus
visioMenuSetsObject = visioUIObject.MenuSets
visioMenuSetObject = visioMenuSetsObject.ItemAtID _

(Microsoft.Office.Interop.Visio.VisUIObjSets.visUIObjSetDrawing)
visioMenusObject = visioMenuSetObject.Menus
visioMenuObject = visioMenusObject.AddAt(7)

visioMenuObject.Caption = "Menu"

visioMenuItemsObject = visioMenuObject.MenuItems
visioMenuItemObject = visioMenuItemsObject.Add
visioMenuItemObject.Caption = "Caption 1"
visioMenuItemObject.CmdNum =
Microsoft.Office.Interop.Visio.VisUICmds.visCmdHierarchical
visioMenuItemObject.ActionText = "Caption 1"
visioMenuItemObject.Enabled = True
visioMenuItemObject.BeginGroup = True

visioMenuItemsObject = visioMenuObject.MenuItems
visioMenuItemObject = visioMenuItemsObject.Add
visioMenuItemObject.Caption = "Submenu under Caption 1"
visioMenuItemObject.CmdNum = 0
visioMenuItemObject.AddOnName = "QUEUEMARKEREVENT"
visioMenuItemObject.AddOnArgs = GetAction("IntializeRoom",
visioDocument.Name)
visioMenuItemObject.Enabled = True
visioMenuItemObject.BeginGroup = True

visioMenuItemObject = visioMenuItemsObject.Add
visioMenuItemObject.Caption = "Submenu under Caption 1"
visioMenuItemObject.CmdNum = 0
visioMenuItemObject.AddOnName = "QUEUEMARKEREVENT"
visioMenuItemObject.AddOnArgs = GetAction("IntializeRoom",
visioDocument.Name)
visioMenuItemObject.Enabled = True
visioMenuItemObject.BeginGroup = True

visioApplication.SetCustomMenus(visioUIObject)

End If

End Sub
############################################
 
B

Brian Willard [MSFT]

Howdey,
You might try using this code:
Public Sub CreateMenus(ByVal visioApplication As
Microsoft.Office.Interop.Visio.Application)



Dim visioUIObject As Microsoft.Office.Interop.Visio.UIObject

Dim visioMenuSetsObject As Microsoft.Office.Interop.Visio.MenuSets

Dim visioMenuSetObject As Microsoft.Office.Interop.Visio.MenuSet

Dim visioMenusObject As Microsoft.Office.Interop.Visio.Menus

Dim visioMenuObject As Microsoft.Office.Interop.Visio.Menu

Dim visioMenuItemsObject As Microsoft.Office.Interop.Visio.MenuItems

Dim visioParentMenuItemObject As Microsoft.Office.Interop.Visio.MenuItem

Dim visioChildMenuItemObject As Microsoft.Office.Interop.Visio.MenuItem

Dim visioDocument As Microsoft.Office.Interop.Visio.Document



If Not (visioApplication Is Nothing) Then

MsgBox("Creating menus")

visioUIObject = visioApplication.BuiltInMenus

visioMenuSetsObject = visioUIObject.MenuSets

visioMenuSetObject =
visioMenuSetsObject.ItemAtID(Microsoft.Office.Interop.Visio.VisUIObjSets.visUIObjSetDrawing)

visioMenusObject = visioMenuSetObject.Menus

visioMenuObject = visioMenusObject.AddAt(7)

visioMenuObject.Caption = "Menu"

visioMenuItemsObject = visioMenuObject.MenuItems

visioParentMenuItemObject = visioMenuItemsObject.Add

visioParentMenuItemObject.Caption = "Caption 1"

visioParentMenuItemObject.CmdNum =
Microsoft.Office.Interop.Visio.VisUICmds.visCmdHierarchical

visioParentMenuItemObject.ActionText = "Caption 1"

visioParentMenuItemObject.Enabled = True





visioChildMenuItemObject = visioParentMenuItemObject.MenuItems.Add

visioChildMenuItemObject.Caption = "Submenu under Caption 1"

visioChildMenuItemObject.CmdNum = 0

visioChildMenuItemObject.AddOnName = "QUEUEMARKEREVENT"

'visioMenuItemObject.AddOnArgs = GetAction("IntializeRoom",
visioDocument.Name)

visioChildMenuItemObject.Enabled = True

'visioChildMenuItemObject.BeginGroup = True

visioChildMenuItemObject = visioParentMenuItemObject.MenuItems.Add

visioChildMenuItemObject.Caption = "Submenu under Caption 1"

visioChildMenuItemObject.CmdNum = 0

visioChildMenuItemObject.AddOnName = "QUEUEMARKEREVENT"

'visioChildMenuItemObject.AddOnArgs = GetAction("IntializeRoom",
visioDocument.Name)

visioChildMenuItemObject.Enabled = True



visioApplication.SetCustomMenus(visioUIObject)

End If

End Sub





It works for me.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top