Shape's right click menu?

S

Scott Metzger

Hi,

I would like to add an entry to my shapes right click menu via
Automation. I found the "Example for Caption" VB sample code in the
Visio 2002 SDK Documentation help file. This shows how to use a
UIObject to get a MenuSets object and then get a MenuSet object passing
the constant visUIObjSetDrawing constant. This allows one to add a menu
to the main window. However, I can't figure out which constant is used
for the right click pop up menu for a shape; or even if I can use the
MenuSet object to get to that menu.

I tried the visUIObjSetCntx_DrawObjSel which has an explanation of
"Shortcut menu: Visio drawing shape.", but it didn't work. What does
the documentation mean by "Shortcut menu"?

Anyone know what constant I should be using?

Thanks,
Scott Metzger
 
R

Rmckenna

Set menuSetObj = menuSetsObj.ItemAtID(visUIObjSetCntx_DrawObjSel)
Set menuObj = menuSetObj.Menus(0)
Set menuItemObj = menuObj.MenuItems.AddAt(0)
 
S

Scott Metzger

Set menuSetObj = menuSetsObj.ItemAtID(visUIObjSetCntx_DrawObjSel)
Set menuObj = menuSetObj.Menus(0)

Shouldn't that be?
menusObj = menuSetObj.Menus(0)
Set menuItemObj = menuObj.MenuItems.AddAt(0)

Ok, here is my code which compiles, runs, and all functions return S_OK.
But no menu is added:

CVisioUIObject UIObj;
CVisioMenuSets menuSetsObj;
CVisioMenuSet menuSetObj;
CVisioMenus menusObj;
CVisioMenu menuObj;
CVisioMenuItems menuItemsObj;
CVisioMenuItem menuItemObj;

vsoApp.BuiltInMenus(UIObj);
UIObj.MenuSets(menuSetsObj);
menuSetsObj.ItemAtID(visUIObjSetCntx_DrawObjSel, menuSetObj);
menuSetObj.Menus(menusObj);
menusObj.AddAt(0, menuObj);
menuObj.putCaption( VBstr(_T("Demo")) );

// also tried with the next 3 line commented out
menuObj.MenuItems(menuItemsObj);
menuItemsObj.AddAt(0, menuItemObj);
menuItemObj.putCaption( VBstr(_T("Demo")) );
//////////

CVisioDocument active_document;
vsoApp.ActiveDocument(active_document);
active_document.SetCustomMenus(UIObj);

Any ideas?

Thanks,
Scott Metzger
 
R

Rmckenna

Option Explicit

Public Sub AddMyMenu()
Dim AApp As Visio.Application
Dim UIObj As Visio.UIObject
Dim menuSetsObj As Visio.MenuSets
Dim menuSetObj As Visio.MenuSet
Dim menusObj As Visio.Menus
Dim menuObj As Visio.Menu
Dim menuItemsObj As Visio.MenuItems
Dim menuItemObj As Visio.MenuItem

Set AApp = Application

Set UIObj = AApp.BuiltInMenus

'get the MenuSets collection
Set menuSetsObj = UIObj.MenuSets
Set menuSetObj = menuSetsObj.ItemAtID(visUIObjSetCntx_DrawObjSel)

Set menuObj = menuSetObj.Menus(0)
Set menuItemObj = menuObj.MenuItems.AddAt(0)
menuItemObj.Caption = "My Context Menu"

AApp.SetCustomMenus UIObj

End Sub
 
G

GMorris

Hello,

I read the posts in this thread, but I couldn't help wondering why you
don't just write
to the shape's ShapeSheet cells, something like:

ActiveWindow.Selection(1).Cells("Actions.Action[1]").Formula =
"=NOT(""Actions.Action[1]"")"

or something similar? This always works great 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