Customizing the UI in Visio 2003. Adding Menu Items to the Toolbar

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.
 
J

junethesecond

i simply translated your first code into VBA.
it really works well,icon and caption are on the menu.

the ending code,
ThisDocument.SetCustomMenus (AUIObject)
got compile error in VBA, so changed to,
ThisDocument.SetCustomMenus AUIObject.
 
M

Mikk

Thanks, but VBA doesn't help a lot.
My working environment is VS .NET 2003. In particular VB.NET. My project is
managed code and so I'm using the wrappers provided by Microsoft for Office
COM Interoperabiliy: Microsoft.Office.Core and Microsoft.Office.Interop... It
would be very helpful if someone knew how to make it work in my working
environment.

Also this is not the first time COM interoperability is weakly supported by
Microsoft, both in documentation and in code. A lot of the old functionality
doesn't work or you have to find workarounds to achieve your goals.

I'm somewhat dissapointed.
 

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