Are there Menu Events using C++?

M

Mark Jailan

Hello,

I've created an Add-On using C++ and installed my own menu items using
some sample code. This code adds the "MyNewMenu" right after the
"Shape" menu, and creates the "MyNewMenuItem" item under it.

My question is, how do I write code to respond to this Event? I can't
find any documentation or sample code.


Here's the code 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);


Regards,
Mark
 
C

Chris Roth [ Visio MVP ]

The menu items have an action property. You set that to QUEUEMARKEREVENT,
then you set the menu Action arguments to something informative.

Then you synch with Visio's marker events and watch for your event to pass
by.

Check out queuemarkerevent in the developer's help or the Visio 2003 SDK, or
MSDN on-line help.

--

Hope this helps,

Chris Roth
Visio MVP
 
M

Mark Jailan

Thanks, but I still need a little more detail.

Using C++ do you mean use the "PutActionText" method on the MenuItem
object? Then set that to some unique string of my choosing (like
"QUEUEMARKEREVENT")?

Or do you mean use the "PutAddOnName" method, in which case I'm using
the QueueMarkerEvent Add-On? Where is that Add-On? Is it a .vsl
somewhere?


Regards,
Mark
 
M

Mark Jailan

Ok, I tried the PutAddOnName(_bstr_t("QueueMarkerEvent")) method which
calls thru the external AddOn. This ends up calling my
HandleVisioEvent method (after carefully setting it up).

My question now, is how do I get the string passed to QueueMarkerEvent
in my HandleVisioEvent method? There are a number of parameters passed
to this method, and I'm guessing that I can "somehow" get the string
out of the pSourceObj parameter.

Yes, no? How?


Regards,
Mark
 
D

David Parker [Visio MVP]

Check out the parseMarkerEvent function, and its usage, in the SDK sample
code.
 
R

Ronnie

typedef IDispEventSimpleImpl<1, CVisioAddinObj,
&__uuidof(Office::_CommandBarButtonEvents)> MyMenu;
make your class inherit above interface, then begin event map just like
following
//Declares the beginning of the event sink map
BEGIN_SINK_MAP(ClassName)
SINK_ENTRY_INFO(100, __uuidof(Office::_CommandBarButtonEvents), 0x01,
OnClickMenu, &OnClickMenuInfo)
END_SINK_MAP

in the end, in the OnConnection function, dispatch event for your menu
MyMenu::DispEventAdvise((IDispatch *)Application);

OnClickMenu is just your event handle function.

hopfully, it will be help to you
thanks
 
Z

zden

There is much simplier way.

You handle Visio events for example like this:

HandleVisioEvent ( IUnknown *ipSink, short nEventCode,
IDispatch *pSourceObj, long
nEventID,
long nEventSeqNum, IDispatch
*pSubjectObj,
VARIANT vMoreInfo, VARIANT
*pvResult )
{
...
}

Get EventInfo property of Application object, using visEvtIdMostRecent
constant:

HandleVisioEvent ( IUnknown *ipSink, short nEventCode,
IDispatch *pSourceObj, long
nEventID,
long nEventSeqNum, IDispatch
*pSubjectObj,
VARIANT vMoreInfo, VARIANT
*pvResult )
{
Visio::IVApplicationPtr visApp;

switch (nEventCode)
{
case ((short) visEvtApp | (short)visEvtMarker):
visApp = pSubjectObj;
_bstr_t contextString = visApp -> GetEventInfo (
visEvtIdMostRecent );

// parse contextString as you like

break;
}
}

Good luck!
 

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