Customizing UI Menu Items in Visio 2003 using .NET

M

Mikk

I'm currently working on a VB.NET 2003 COM Add-in Project for Visio 2003.
I'm trying to add two new menu items to the View Menu. I've tried using the

Microsoft.Office.Interop.Visio namespace and the Microsoft.Office.Core
namespace and moth methods failed.

Using the Microsoft.Office.Interop.Visio method I was able to add two new
Menu Items using the Visio.UIObject and Document.SetCustomMenus(). The method
worked and I created a custom UI that would add two menu items uder the View
Menu. The problem is I can't customize the picture displayed on the left side
of Menu as an Icon before the Menu Item Caption.

Following is the code I've used:
===============[ Code Begin ] ==========================

Dim AUIObject As Microsoft.Office.Interop.Visio.UIObject
Dim AMenuSet As Microsoft.Office.Interop.Visio.MenuSet
Dim AMenu As Microsoft.Office.Interop.Visio.Menu
Dim AMenuItem As Microsoft.Office.Interop.Visio.MenuItem

AUIObject = myVisioApp.BuiltInMenus
AMenuItem = AUIObject.MenuSets(0).Menus(2).MenuItems.AddAt(6)
AMenuItem.Caption = "Action Tables Window"
AMenuItem.Enabled = True
AMenuItem.Visible = True
AMenuItem.Style = visio.VisUIButtonStyle.visButtonIconandCaption
AMenuItem.FaceID = -1
AMenuItem.IconFileName("c:\work\myPrj\images\test.ico")

doc.SetCustomMenus(AUIObject)
AUIObject.UpdateUI()

===============[ Code End ] ============================

** Note:
doc is a Visio.Document and myVisioApp is a reference to the visio
application that my addin connects to. The code above sits inside the
DocumentCreated handler.

The result is a new menu item under the View Menu that has a black box
instead of an image.

** Note:

I've also tried to use the Microsoft.Office.Core.CommandBar and
Microsoft.Office.Core.CommandBarButton classes to get a reference to the menu
items i have just created and to use them to set a menu item icon. That did
not work either. Code is provided as follows:
===============[ Code Begin ] ============================

cbrs = CType(myVisioApp.CommandBars,
_Microsoft.Office.Core.CommandBars)

cb = cbrs("Menu Bar")
cb.Protection = office.MsoBarProtection.msoBarNoMove

myCBBActionTables = CType(cb.Controls("View"),
_office.CommandBarPopup).Controls("Action Tables
Window")

myCBBActionTables.Picture = aPic
myCBBActionTables.Mask = aPic

===============[ Code End ] ============================

**Note:
The code references the Menu Item succesfully as I can verify properties
such as the caption and assign handlers for the click event but assiging the
Pciture and Mask don't work either. The aPic is an object of type:
stdole.IPictureDisp.
 
W

Wei-Dong XU [MSFT]

Hi Mikk,

Thank you for using this newsgroup!

We are currently researching this issue for you. If there is any idea, we
will post back as soon as possible.

Best Regards,
Wei-Dong XU (WD.XU)
Microsoft Product Support Services
Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 
W

Wei-Dong XU [MSFT]

Hi Mikk,

From my test, your code looks well. However, based on my test, we can only
add button into built-in menu; at the same time, we can't insert the ico
icon both in .Net and VBA. I have recorded it at internal bug system.
Greatly appreciate your reporting this to Microsoft!

For your scenario, I'd suggest you can create one new menu and add the icon
button into it. This way, the ico file can be added as expected. Please see
my VBA sample code below:
'-------------------------------------------------------------------
Sub InsertCustomMenu()

Dim vsoUIObject As Visio.UIObject
Dim vsoMenuSet As Visio.MenuSet
Dim vsoMenu As Visio.Menu
Dim vsoMenuItem As Visio.MenuItem

Set vsoUIObject = ThisDocument.CustomMenus
Set vsoMenuSet = vsoUIObject.MenuSets(0)
Set vsoMenu = vsoMenuSet.Menus.Add
vsoMenu.Caption = "custom"

Set vsoMenuItem = vsoMenu.MenuItems.Add
With vsoMenuItem
Caption = "Test"
Style = visButtonIconandCaption
IconFileName "g:\download\favicon.ico"
Enabled = True
Visible = True
End With

vsoUIObject.UpdateUI
End Sub
'-------------------------------------------------------------------

Please feel free to let me know if you have any question.

Best Regards,
Wei-Dong XU (WD.XU)
Microsoft Product Support Services
Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 

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