Event Sink for an Action

S

Scott Metzger

Hi,

Ok, I have figured out how to add right click menus to my shapes. Now
how can I create an event sink or filter for these events?

For example if I add Action ojects in my shapesheet for my shape I can
run an add on. But I want to run a function in my .exe that launched
Visio. How do I do that?

Looking at the documentation for events I don't see anything that would
be aplicable.

Thanks,
Scott Metzger
 
S

Scott Metzger

Yeah, those are all pretty kludgey. The real way to do this is to is a
CommandBar. However, I can't find any C++ examples for using the
CommandBar. The VB example for adding a menu via CommandBar is...
Dim cbrCmdBar As CommandBar
'Create a toolbar.
Set cbrCmdBar = Application.CommandBars.Add(Name:= "MyNewToolbar")

'Create temporary toolbar that doesn't
'persist between application sessions.
Set cbrCmdBar = Application.CommandBars.Add(Name:=
"MyNewToolbar",Temporary:=True)

'Create a menu bar.
Set cbrCmdBar = Application.CommandBars.Add(Name:= "MyNewMenuBar",
Position:=msoBarMenuBar)

'Create a pop-up menu.
Set cbrCmdBar = Application.CommandBars.Add(Name:= "MyNewPopupMenu",
Position:=msoBarPopup)

But I can't find the CommandBar object in C++.
If anyone could translate the above code snippet into C++ that would be
a great help.

Thanks,
Scott
 
M

Michael J. Hunter [MS]

Scott,

The simplest way to do CommandBars from C++ (assuming of course you're using
Visual C++ <g/>) is to #import MSO.DLL into your project. This
auto-generates smart pointer wrappers for the entire type library (thus
removing the need to AddRef/Release all those COM objects yourself, which
may or may not be a good thing, depending on your point of view). The
really nifty aspect of this is that these wrappers you use these *almost
exactly* like you would use the corresponding VB objects:

// VBA:
// Application.Documents(1).Pages(1).Shapes(1).DrawRectangle(0, 0, 1, 1)
// C++ (doing this from memory, so syntax possibly slightly incorrect):

Application->Documents->Item[1]->Pages->Item[1]->Shapes->Item[1]->DrawRectan
gle(0, 0, 1, 1);

This works for any type library, so you can #import Visio's type library as
well.

I believe Visio's SDK has sample code demonstrating this in more detail.

Alternatively, if you're using MFC and don't mind going through wizards, KB
article 180625
(http://support.microsoft.com/default.aspx?scid=http://support.microsoft.com
:80/support/KB/Articles/Q180/6/25.asp&NoWebContent=1) covers using
automation to modify Office menus. This article was written for Office
2000, but it should still work.

Michael J. Hunter
Microsoft
michhu-at-online-dot-microsoft-dot-com

Developing Microsoft Visio Solutions:
http://msdn.microsoft.com/library/en-us/devref/HTML/DVS_Copyright_1270.asp
Developer Resources for Microsoft Visio:
http://msdn.microsoft.com/library/default.asp?url=/nhp/Default.asp?contentid=28000456

This posting is provided "AS IS" with no warranties, and confers no rights.
Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm
 

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