COM Addin and MarkerEvent


U

unerklarlich

Hi,

I am writing a COM Addin for Visio in C#. The test code is connecting to
Visio and Loading a custom toolbar.

I now need to be able to trigger my COM Addin from the shapesheet of the
shapes in my stencil. I am using RUNADDONWARG in the Shape Sheet cell to run
the QUEUEMARKEREVENT Addon.

I then came across some code
(http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vmt/VMT_Lesson_2_3365.asp)
which illustrates how the COM Addin should listen to a MarkerEvent.

Does anyone know how this line of code would translate to C#?

Private WithEvents visioApplication As Application

Thanks,
Mayank
 
Ad

Advertisements

M

Mark Nelson [MS]

This is a great question and one that we should try to provide more detailed
sample code for in the SDK.

If you have Visio 2003, you fire a Marker event from the Shapesheet using
the QueueMarkerEvent function. You do not need RunAddonWarg. You pass an
argument string in QueueMarkerEvent that your Addin can recognize when it
gets the Marker event. This is how you know that the Marker event is from
your shape and not some other Marker event.

Next you need to register for the Marker event in your addin. Visio
provides two mechanisms for signing up for an event. First is the
"WithEvents" approach which is similar to the Windows Forms model of writing
code behind specific events for controls - like Command Buttons. This is
the easier approach for languages like VB or VBA, but it is not very
performant. I believe you can do something similar in C# using delegates,
but I don't know the code to achieve that.

The second mechanism is "AddAdvise" and is the recommended approach for C++
and managed code or wherever performance is critical. Here you get the
EventList of the Visio application object and call AddAdvise to sign up for
the Marker event (event code = visEvtApp+visEvtMarker). As part of the
process, you implement the IVisEventProc interface in order to expose a
function that Visio will call when the event is fired. There is sample code
for AddAdvise in the SDK that should make this much clearer.

We are in the process of creating more documentation around COM Addin
development using managed code. Please let me know what is still confusing,
and I'll try to get some answers.

--
Mark Nelson
Office Graphics - Visio
Microsoft Corporation

This posting is provided "AS IS" with no warranties, and confers no rights.
 
U

unerklarlich

The entire process of queueing marker events and setting up a MarkerEvent
EventHandler took some time for me to understand. Just understood the whole
thing :). Thanks for that info about the QueueMarkerEvent function. I am now
being able to send events to my C# code from the shapesheet :-D.

As you mentioned some more documentation would've been helpful, but alls
well that ends well :) ... that you for u're prompt response.

Regards,
Mayank

PS - If anyone one this Discussion Group comes across this thread and needs
help with some sample code then I can send it out ... just reply to this
thread :).
 
Ad

Advertisements

Joined
May 22, 2017
Messages
1
Reaction score
0
The entire process of queueing marker events and setting up a MarkerEvent
EventHandler took some time for me to understand. Just understood the whole
thing :). Thanks for that info about the QueueMarkerEvent function. I am now
being able to send events to my C# code from the shapesheet :-D.

As you mentioned some more documentation would've been helpful, but alls
well that ends well :) ... that you for u're prompt response.

Regards,
Mayank

PS - If anyone one this Discussion Group comes across this thread and needs
help with some sample code then I can send it out ... just reply to this
thread :).

"Mark Nelson [MS]" wrote:

> This is a great question and one that we should try to provide more detailed
> sample code for in the SDK.
>
> If you have Visio 2003, you fire a Marker event from the Shapesheet using
> the QueueMarkerEvent function. You do not need RunAddonWarg. You pass an
> argument string in QueueMarkerEvent that your Addin can recognize when it
> gets the Marker event. This is how you know that the Marker event is from
> your shape and not some other Marker event.
>
> Next you need to register for the Marker event in your addin. Visio
> provides two mechanisms for signing up for an event. First is the
> "WithEvents" approach which is similar to the Windows Forms model of writing
> code behind specific events for controls - like Command Buttons. This is
> the easier approach for languages like VB or VBA, but it is not very
> performant. I believe you can do something similar in C# using delegates,
> but I don't know the code to achieve that.
>
> The second mechanism is "AddAdvise" and is the recommended approach for C++
> and managed code or wherever performance is critical. Here you get the
> EventList of the Visio application object and call AddAdvise to sign up for
> the Marker event (event code = visEvtApp+visEvtMarker). As part of the
> process, you implement the IVisEventProc interface in order to expose a
> function that Visio will call when the event is fired. There is sample code
> for AddAdvise in the SDK that should make this much clearer.
>
> We are in the process of creating more documentation around COM Addin
> development using managed code. Please let me know what is still confusing,
> and I'll try to get some answers.
>
> --
> Mark Nelson
> Office Graphics - Visio
> Microsoft Corporation
>
> This posting is provided "AS IS" with no warranties, and confers no rights.
>
> "unerklarlich" <[email protected]> wrote in message
> news:[email protected]
> > Hi,

> >
> > I am writing a COM Addin for Visio in C#. The test code is connecting to
> > Visio and Loading a custom toolbar.
> >
> > I now need to be able to trigger my COM Addin from the shapesheet of the
> > shapes in my stencil. I am using RUNADDONWARG in the Shape Sheet cell to
> > run
> > the QUEUEMARKEREVENT Addon.
> >
> > I then came across some code
> > (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vmt/VMT_Lesson_2_3365.asp)
> > which illustrates how the COM Addin should listen to a MarkerEvent.
> >
> > Does anyone know how this line of code would translate to C#?
> >
> > Private WithEvents visioApplication As Application
> >
> > Thanks,
> > Mayank
>
>
>


Mayank,
I am trying to listen to a MarkerEvent which I have triggered in Visio using QUEUEMARKER function.
Can you please help me with how to I listen to the MarkerEvent in my COM AddIn and once the event is heard, trigger a function built in the COM Addin.
Thank you.
- Miki
 

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