J
John
Hi there,
I've been trying this for days now.........I'm trying to add a simple menu
item at the bottom of the Tools menu using the UIObject and deployed using
VSTO SE, however I'm having rather intermitent success. It appears ok (is
visible) if there are no existing CustomMenus and it uses the BuiltIn copy,
but if it finds the CustomMenus object and then trys to clone it, it fails
to become visible. I say visible, because I can see it using Graham
Wideman's UIObject Browser tool under all circumstances.
I know I can use the CommandBars model instead but I'm intending to make Doc
level UI changes later on and so would like to stick with the UIObject if at
all possible. Has anyone else managed to use the UIObject with VSTO (I'm
only talking Debug mode at the moment)?
Any feedback would be gratefully accepted. Please find code (adapted from
Graham's book), which I've squeezed into the ThisAddIn code for simplicity
for the time being.
Best regards
John
(Current setup - Visio 2007 Pro / VS 2005 Pro / VSTO SE)
public class ThisAddIn
Private Sub ThisAddIn_Startup(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Startup
AddTestUIMenuItem
End Sub
Private Sub ThisAddIn_Shutdown(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Shutdown
RemoveTestUIMenuItem
End Sub
Private Sub AddTestUIMenuItem()
'-------------------------------------------
Dim UIObj As Visio.UIObject = Nothing
Dim NoDocsMenuSet As Visio.MenuSet = Nothing
Dim AMenu As Visio.Menu = Nothing
Dim AMenuItem As Visio.MenuItem = Nothing
Dim x As Integer
UIObj = GetMostCustomMenus()
' Get the No Docs context menuset
NoDocsMenuSet = UIObj.MenuSets.ItemAtID( _
Visio.VisUIObjSets.visUIObjSetNoDocument)
' Get the 'Tools' menu reference
For x = 0 To NoDocsMenuSet.Menus.Count - 1
If NoDocsMenuSet.Menus.Item(x).Caption = "&Tools" Then
AMenu = NoDocsMenuSet.Menus.Item(x)
Exit For
End If
Next
If (Not AMenu Is Nothing) Then
AMenuItem = AMenu.MenuItems.AddAt(AMenu.MenuItems.Count)
AMenuItem.Caption = "A Test Menu Item"
' Put Menus in place
Me.Application.SetCustomMenus(UIObj)
UIObj.UpdateUI()
End If
End Sub
'-------------------------------------------
Private Sub RemoveTestUIMenuItem()
'-------------------------------------------
Dim UIObj As Visio.UIObject = Nothing
Dim NoDocsMenuSet As Visio.MenuSet = Nothing
Dim AMenu As Visio.Menu = Nothing
Dim i As Integer
UIObj = GetMostCustomMenus()
If Not UIObj Is Nothing Then
' Get the Drawing context menuset
NoDocsMenuSet = UIObj.MenuSets.ItemAtID( _
Visio.VisUIObjSets.visUIObjSetNoDocument)
' Get the 'Tools' menu reference
For i = 0 To NoDocsMenuSet.Menus.Count - 1
If NoDocsMenuSet.Menus.Item(i).Caption = "&Tools" Then
AMenu = NoDocsMenuSet.Menus.Item(i)
Exit For
End If
Next
If (Not AMenu Is Nothing) Then
For i = AMenu.MenuItems.Count - 1 To 0 Step -1
If AMenu.MenuItems(i).Caption = "A Test Menu Item" Then
System.Diagnostics.Debug.WriteLine( _
AMenu.MenuItems(i).Caption)
AMenu.MenuItems(i).Delete()
' Put updated UIObject in place
Me.Application.SetCustomMenus(UIObj)
UIObj.UpdateUI()
Exit For
End If
Next
Else
'AMenu Is Nothing
End If
End If
End Sub
'-------------------------------------------
Private Function GetMostCustomMenus() As Visio.UIObject
'-------------------------------------------
' Only looks at App.Builtin and App.Custom as menu is
' added at application startup and so no docs exist
Dim UIObj As Visio.UIObject = Nothing
'On Error Resume Next
If Not Me.Application.CustomMenus Is Nothing Then
UIObj = Me.Application.CustomMenus.Clone
UIObj.Name = "FromCustom"
'System.Diagnostics.Debug.WriteLine("App custom menu is nothing")
End If
If UIObj Is Nothing Then
UIObj = Me.Application.BuiltInMenus
UIObj.Name = "FromBuiltIn"
End If
System.Diagnostics.Debug.WriteLine(UIObj.Name)
GetMostCustomMenus = UIObj
End Function
End class
I've been trying this for days now.........I'm trying to add a simple menu
item at the bottom of the Tools menu using the UIObject and deployed using
VSTO SE, however I'm having rather intermitent success. It appears ok (is
visible) if there are no existing CustomMenus and it uses the BuiltIn copy,
but if it finds the CustomMenus object and then trys to clone it, it fails
to become visible. I say visible, because I can see it using Graham
Wideman's UIObject Browser tool under all circumstances.
I know I can use the CommandBars model instead but I'm intending to make Doc
level UI changes later on and so would like to stick with the UIObject if at
all possible. Has anyone else managed to use the UIObject with VSTO (I'm
only talking Debug mode at the moment)?
Any feedback would be gratefully accepted. Please find code (adapted from
Graham's book), which I've squeezed into the ThisAddIn code for simplicity
for the time being.
Best regards
John
(Current setup - Visio 2007 Pro / VS 2005 Pro / VSTO SE)
public class ThisAddIn
Private Sub ThisAddIn_Startup(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Startup
AddTestUIMenuItem
End Sub
Private Sub ThisAddIn_Shutdown(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Shutdown
RemoveTestUIMenuItem
End Sub
Private Sub AddTestUIMenuItem()
'-------------------------------------------
Dim UIObj As Visio.UIObject = Nothing
Dim NoDocsMenuSet As Visio.MenuSet = Nothing
Dim AMenu As Visio.Menu = Nothing
Dim AMenuItem As Visio.MenuItem = Nothing
Dim x As Integer
UIObj = GetMostCustomMenus()
' Get the No Docs context menuset
NoDocsMenuSet = UIObj.MenuSets.ItemAtID( _
Visio.VisUIObjSets.visUIObjSetNoDocument)
' Get the 'Tools' menu reference
For x = 0 To NoDocsMenuSet.Menus.Count - 1
If NoDocsMenuSet.Menus.Item(x).Caption = "&Tools" Then
AMenu = NoDocsMenuSet.Menus.Item(x)
Exit For
End If
Next
If (Not AMenu Is Nothing) Then
AMenuItem = AMenu.MenuItems.AddAt(AMenu.MenuItems.Count)
AMenuItem.Caption = "A Test Menu Item"
' Put Menus in place
Me.Application.SetCustomMenus(UIObj)
UIObj.UpdateUI()
End If
End Sub
'-------------------------------------------
Private Sub RemoveTestUIMenuItem()
'-------------------------------------------
Dim UIObj As Visio.UIObject = Nothing
Dim NoDocsMenuSet As Visio.MenuSet = Nothing
Dim AMenu As Visio.Menu = Nothing
Dim i As Integer
UIObj = GetMostCustomMenus()
If Not UIObj Is Nothing Then
' Get the Drawing context menuset
NoDocsMenuSet = UIObj.MenuSets.ItemAtID( _
Visio.VisUIObjSets.visUIObjSetNoDocument)
' Get the 'Tools' menu reference
For i = 0 To NoDocsMenuSet.Menus.Count - 1
If NoDocsMenuSet.Menus.Item(i).Caption = "&Tools" Then
AMenu = NoDocsMenuSet.Menus.Item(i)
Exit For
End If
Next
If (Not AMenu Is Nothing) Then
For i = AMenu.MenuItems.Count - 1 To 0 Step -1
If AMenu.MenuItems(i).Caption = "A Test Menu Item" Then
System.Diagnostics.Debug.WriteLine( _
AMenu.MenuItems(i).Caption)
AMenu.MenuItems(i).Delete()
' Put updated UIObject in place
Me.Application.SetCustomMenus(UIObj)
UIObj.UpdateUI()
Exit For
End If
Next
Else
'AMenu Is Nothing
End If
End If
End Sub
'-------------------------------------------
Private Function GetMostCustomMenus() As Visio.UIObject
'-------------------------------------------
' Only looks at App.Builtin and App.Custom as menu is
' added at application startup and so no docs exist
Dim UIObj As Visio.UIObject = Nothing
'On Error Resume Next
If Not Me.Application.CustomMenus Is Nothing Then
UIObj = Me.Application.CustomMenus.Clone
UIObj.Name = "FromCustom"
'System.Diagnostics.Debug.WriteLine("App custom menu is nothing")
End If
If UIObj Is Nothing Then
UIObj = Me.Application.BuiltInMenus
UIObj.Name = "FromBuiltIn"
End If
System.Diagnostics.Debug.WriteLine(UIObj.Name)
GetMostCustomMenus = UIObj
End Function
End class