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