Visio 2003 drawing control adding events

A

andrewLLL

H

I am using Visio 2003 activeX control for my VB project. I have trouble creating Shape Connection events using AddAdvise method. Following the tutorial in Visio website, the code is

in my VB class named clsVisEventSink

Implements Visio.IVisEventPro
Private Function IVisEventProc_VisEventProc(
ByVal nEventCode As Integer,
ByVal pSourceObj As Object,
ByVal nEventID As Long,
ByVal nEventSeqNum As Long,
ByVal pSubjectObj As Object,
ByVal vMoreInfo As Variant) As Varian

Dim strMessage As Strin

' Determine if mouse up event fired
If nEventCode = visEvtAdd + visEvtConnect The
'call my procedur
End I

End Functio

To add this event, using this method in my VB form
Private Sub CreateCustomEventList(
Dim eventsObj As Visio.EventLis
Dim eventObj As Visio.Even
Dim g_Sink As clsVisEventSin

'Get the EventList collection of this document
Set eventsObj = myControl.Window.EventLis

Set g_Sink = New clsVisEventSin

'Add Event objects that will send notifications
'Add an Event object for the add connection event
Set eventObj = eventsObj.AddAdvise(visEvtAdd + visEvtConnect, g_Sink, "", "Connection Added..."

End Su

This routine gave an automation error. Anybody knows why and how to make it work? Thanks

Andrew
 
C

Chris Roth

There was historically a problem in the type library with visEvtAdd,
something about it being out of range of VB integers or something. I never
studied the problem in full. However, the recommendation is to define your
own visEvtAdd const. I usually redefine the whole lot of them, since they
can be rather long to type. Here's my VB.NET code, not much different than
VB:


Const visEvtAdd As Int16 = -32768 '<-- this is the magic

Const visEvtShapeAdded As Short = CType(Visio.VisEventCodes.visEvtShape,
Short) + visEvtAdd

...
visEvent = evtsPage.AddAdvise(visEvtShapeAdded, m_eventsink, "", "Shape
added...")

--

Hope this helps,

Chris Roth
Visio MVP
visioguy @ extremely warm mail.com



andrewLLL said:
Hi

I am using Visio 2003 activeX control for my VB project. I have trouble
creating Shape Connection events using AddAdvise method. Following the
tutorial in Visio website, the code is
 
A

andrewLLL

Thanks Chris!
I redifined visEvtAdd too as a public const.

I found out the problem and it was because I was using
the wrong events list:

Set eventsObj = myControl.Window.EventList

it should be:
Set eventsObj = myControl.Window.document.EventList

Andrew
 

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