How to respond to Menu items?

M

Mark Jailan

I followed the example VBA code and converted it to C++ to add a Menu
item to the Main Visio menu. I can't figure out how to respond when
that Menu item is selected. Any example code?

Here's what I used to add a menu item:

// Get a UIObject object that represents Visio built-in menus.
Visio::IVUIObjectPtr vsoUIObject = app->GetBuiltInMenus();

// Get the MenuSets collection.
Visio::IVMenuSetsPtr vsoMenuSets = vsoUIObject->GetMenuSets();

// Get the drawing window menu set.
Visio::IVMenuSetPtr vsoMenuSet =
vsoMenuSets->GetItemAtID(visUIObjSetDrawing);

// Get the Menus collection.
Visio::IVMenusPtr vsoMenus = vsoMenuSet->GetMenus();

// Add a new menu before the Window menu.
Visio::IVMenuPtr vsoMenu = vsoMenus->AddAt(7);
vsoMenu->PutCaption(_bstr_t("MyNewMenu"));

// Get the MenuItems collection.
Visio::IVMenuItemsPtr vsoMenuItems = vsoMenu->GetMenuItems();

// Add a menu item to the new menu.
Visio::IVMenuItemPtr vsoMenuItem = vsoMenuItems->Add();

// Set the Caption property for the new menu item.
vsoMenuItem->PutCaption(_bstr_t("&MyNewMenuItem"));

// Tell Visio to use the new UI when the document is active.

Visio::IVDocumentsPtr vsoDocuments = app->GetDocuments();
Visio::IVDocumentPtr vsoDocument =
vsoDocuments->GetItem(_variant_t(1));

vsoDocument->SetCustomMenus(vsoUIObject);



In VBA you'd assign a Function to the document, but how is that done in
C++?


Regards.
 
N

NAdir

Hello,
For the menu item there is a property 'AddOnName ' you can set to the name
of the add-on or procedure you want to execute when the item is selected. You
can also transmit arguments using 'AddonArgs' property.
Example : menuXX.AddOnName = "Myprocedure"
 
M

Mark Jailan

How to do that in C++?

The PutAddOn method in C++ appears to be for invoking another addon,
yet I already have an addon running (e.g. the code snippet above). In
order for a C++ app to register a callback, I'd need to pass Visio a
pointer to my class etc. There don't appear to be any callback
registration methods in the C++ automation interface. Yes, it looks
pretty straightforward in VB, but not in C++.
 

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