Visio 2003 ActiveX control

A

andrweLLL

Using this control in a VB form, can we

(1) double click a shape and call my own procedure?

(2) Right click a shape, click my own custom menu and do something special?

From Microsoft website, seems we can do neither of them. Anybody knows a work around?

Andrew
 
M

Matt

Hi Andrew

Have you read this article?
http://www.msdn.microsoft.com/office/understanding/visio/techarticles/defaul
t.aspx?pull=/library/en-us/odc_vis2003_ta/html/odc_vsprogrammingwithvisioact
ivexcontrol.asp

It tells you how set/catch mouseevents.

At the moment I try to get an answer how to catch doubleclicks with VBA in
the microsoft.public.visio.developer newsgroup.
There is already a thread for dbl-click in the active-x control but they
give only an example for C++
(just search the other NG for "DoubleClick")

With this code you trigger a right button mouseclick:

Private Sub myDrawingControl_MouseDown(ByVal Button As Long, _
ByVal KeyButtonState As Long, ByVal x As Double, _
ByVal y As Double, CancelDefault As Boolean)

If Button = 2 Then

MsgBox "you right-clicked"

End Sub


Hope this helps
Regards
Matt
 
A

andrewLLL

Thanks Matt!

What I want is I double click a shape, I can see my menu
in the list, e.g. "MyMenu", and then click this menu item
to invoke my procedure. I could do this easily through
Action Cell and "CALLTHIS" function or through
Automation. But seems ActiveX doesn't allow this.

Andrew
 
M

Matt

Hi Andrew

You really should read the article with the link I posted first . It gives
you a better understanding how the drawingcontrol (ActiveX control) works.
It won't let you execute any VBA in it but you can reach the objects
(shapes, pages, documents etc.) very good from your outside host
application.
Pls. also have a look in the other newsgroup I mentioned before - meanwhile
I found a solution how to create dbl-clicks in the control (it's a bit of a
hack and I'm still waiting for some feedback from the Pros, but so far it
works really good for me).
Instead of the msgbox, I'm calling in this procedure you could call your
custom-menu or a form you might have designed as a context-menu (just define
it as popup without any closing, mini- and maximzing buttons)

Regards
MAtt
 
M

Mai-lan [MS]

Hi, there: Both of these scenarios are supported by the ActiveX control.
Here's some C# sample code to demonstrate this. Use Win32's "GetTickCount"
function from C++. VB6 has a Timer function. Spatial proximity may matter to
some folks. If so, they need to track the x and y from the events also.
C#:



private void axDrawingControl1_MouseDownEvent(object sender,
AxMicrosoft.Office.Interop.VisOcx.EVisOcx_MouseDownEvent e)

{

// Have a class member like this in the containing
form's class definition:

//

//private int m_previousMouseDownEvent= 0;



const int threshold= 200;



if (0!=m_previousMouseDownEvent &&
(System.Environment.TickCount-m_previousMouseDownEvent)<threshold)

{

// Two MouseDown events occurred within threshold
milliseconds

// of each other... Consider it a "double
click"...

//

System.Windows.Forms.MessageBox.Show("Double
clicked!");

}



m_previousMouseDownEvent = System.Environment.TickCount;

}



Here's some sample code demonstrating how to replace the default Visio RMA
with a custom menu with a single option (again in C#). Sorry, the formatting
got a little lost. I've also included a couple of helper functions too.

private void axDrawingControl1_MouseUpEvent(object sender,
AxVisOcx.EVisOcx_MouseUpEvent e)

{

if (e.button == (int) Visio.VisKeyButtonFlags.visMouseRight)

{


//need a reference to the shape that was clicked for the context menu

this.clickedShape = VisioUtility.GetClickedShape( VisPage, e.x, e.y );


if (this.clickedShape != null)

{

//cancel the default Visio RMA

e.cancelDefault = true;

//call utility function to translate Visio page units to pixels.

CtxMenuShape.Show(

this,

PageUnitsToPixels( ref axDrawingControl1, e.x, e.y));

}

}

}

public static Shape GetClickedShape( Page visioPage, double x, double y,
double tolerance )

{


try

{

Selection visSelection = visioPage.get_SpatialSearch(

x,

y,

(short) VisSpatialRelationCodes.visSpatialContainedIn,

tolerance,

(short) VisSpatialRelationFlags.visSpatialFrontToBack);

if (visSelection.Count > 0 )

{

// 1 based collection

Debug.WriteLine( visSelection[1].Name);

return (Shape) visSelection[1];


}

else

{

return null;

}

}

catch( Exception exp)

{

Debug.WriteLine( exp.Message );

throw exp;

}

}

private Point PageUnitsToPixels( ref
AxMicrosoft.Office.Interop.VisOcx.AxDrawingControl axDrawingControl, double
x, double y)

{

double vLeft, vTop, vWidth, vHeight;

axDrawingControl.Window.GetViewRect( out vLeft, out vTop, out vWidth, out
vHeight);

// calculate position

int xForm = (int) (axDrawingControl.Left +
(axDrawingControl.Width/vWidth)*(x-vLeft));

int yForm = (int) (axDrawingControl.Top +
(axDrawingControl.Height/vHeight)*(vTop-y));

return new Point( xForm, yForm );

}


Mai-lan
 
M

Matt

Mai-lan is there any chance that you provide us with the VBA version of your
code - please?
It seems to be more sophisticated than the solution I tried in the
visio.developer NG under "DoubleClick with Visio2003 ActiveX drawing
control".
I also found it difficult to distinguish between a rectangle and connector
beeing selected with the "spatialserach -containedIn" Method in a flowchart.
If it worked fine for the process-shape (rectangle) to be selected, I didn't
catch the connectors. Only after increase the tolerance (from 0.001 to 0.1)
and change from "ContainedIn" to "Touching" I caught the connector-shapes
(line with arrows) but then the process-shapes wern't recognized.
Is there a solution in VBA to rightclick any shape on the page and open a
context-menu related to that specific shape?
How would this look like in VBA?

An example would be really great help

Regards
Matt



Mai-lan said:
Hi, there: Both of these scenarios are supported by the ActiveX control.
Here's some C# sample code to demonstrate this. Use Win32's "GetTickCount"
function from C++. VB6 has a Timer function. Spatial proximity may matter to
some folks. If so, they need to track the x and y from the events also.
C#:



private void axDrawingControl1_MouseDownEvent(object sender,
AxMicrosoft.Office.Interop.VisOcx.EVisOcx_MouseDownEvent e)

{

// Have a class member like this in the containing
form's class definition:

//

//private int m_previousMouseDownEvent= 0;



const int threshold= 200;



if (0!=m_previousMouseDownEvent &&
(System.Environment.TickCount-m_previousMouseDownEvent)<threshold)

{

// Two MouseDown events occurred within threshold
milliseconds

// of each other... Consider it a "double
click"...

//

System.Windows.Forms.MessageBox.Show("Double
clicked!");

}



m_previousMouseDownEvent = System.Environment.TickCount;

}



Here's some sample code demonstrating how to replace the default Visio RMA
with a custom menu with a single option (again in C#). Sorry, the formatting
got a little lost. I've also included a couple of helper functions too.

private void axDrawingControl1_MouseUpEvent(object sender,
AxVisOcx.EVisOcx_MouseUpEvent e)

{

if (e.button == (int) Visio.VisKeyButtonFlags.visMouseRight)

{


//need a reference to the shape that was clicked for the context menu

this.clickedShape = VisioUtility.GetClickedShape( VisPage, e.x, e.y );


if (this.clickedShape != null)

{

//cancel the default Visio RMA

e.cancelDefault = true;

//call utility function to translate Visio page units to pixels.

CtxMenuShape.Show(

this,

PageUnitsToPixels( ref axDrawingControl1, e.x, e.y));

}

}

}

public static Shape GetClickedShape( Page visioPage, double x, double y,
double tolerance )

{


try

{

Selection visSelection = visioPage.get_SpatialSearch(

x,

y,

(short) VisSpatialRelationCodes.visSpatialContainedIn,

tolerance,

(short) VisSpatialRelationFlags.visSpatialFrontToBack);

if (visSelection.Count > 0 )

{

// 1 based collection

Debug.WriteLine( visSelection[1].Name);

return (Shape) visSelection[1];


}

else

{

return null;

}

}

catch( Exception exp)

{

Debug.WriteLine( exp.Message );

throw exp;

}

}

private Point PageUnitsToPixels( ref
AxMicrosoft.Office.Interop.VisOcx.AxDrawingControl axDrawingControl, double
x, double y)

{

double vLeft, vTop, vWidth, vHeight;

axDrawingControl.Window.GetViewRect( out vLeft, out vTop, out vWidth, out
vHeight);

// calculate position

int xForm = (int) (axDrawingControl.Left +
(axDrawingControl.Width/vWidth)*(x-vLeft));

int yForm = (int) (axDrawingControl.Top +
(axDrawingControl.Height/vHeight)*(vTop-y));

return new Point( xForm, yForm );

}


Mai-lan
--
Microsoft Corporation
This posting is provided "AS IS" with no warranties, and confers no rights.
Matt said:
Hi Andrew

You really should read the article with the link I posted first . It gives
you a better understanding how the drawingcontrol (ActiveX control) works.
It won't let you execute any VBA in it but you can reach the objects
(shapes, pages, documents etc.) very good from your outside host
application.
Pls. also have a look in the other newsgroup I mentioned before - meanwhile
I found a solution how to create dbl-clicks in the control (it's a bit
of
a
hack and I'm still waiting for some feedback from the Pros, but so far it
works really good for me).
Instead of the msgbox, I'm calling in this procedure you could call your
custom-menu or a form you might have designed as a context-menu (just define
it as popup without any closing, mini- and maximzing buttons)

Regards
MAtt
 
M

Mai-lan [MS]

Hi, Matt: I just tried to post a message about this but I don't know if the
mail server will let it through because I put a screenshot in it (whoops).

Anyway, there's two things that I wanted to point out:
1) you will not be able to use VBA with the Visio ActiveX control. The
drawing control does not execute VBA. If you load a document with VBA in it
in the ActiveX control, the VBA will not execute. The control is really
geared at working within a custom container (like a VB form) or in an
application container (like an Access form). Any code that you have in VBA
in your solution will have to be ported out to your drawing control
container or a COM addin. You can still program the ShapeSheet through
automation, though, which leads to my second point.

2) One of the Visio devs pointed out today that there is an easier approach
than the one I recommended, especially if you're a ShapeSheet developer. If
you use CALLTHIS or RUNADDONWARGS, consider using the QueueMarkerEvent
function (new to the ShapeSheet in Visio 2003, although similar
functionality was provided in Visio 2002 SR1. In the DlbClk event of the
ShapeSheet, you can call the QueueMarkerEvent function, passing in a
solution-specific string (like "MyDoubleClickEvent"). That fires an event
from your application and passes that string along to whomever is listening.
So your COM addin can be listening for that string and on the double-click
event firing, present a custom menu or whatever you prefer to do. If you
want to prototype this, you can do it in the Visio app. Just use that
function for a shape and then have some event handling code in VBA to listen
for that event marker string ("MyDoubleClickEvent") and pop up a message box
or something. If you are working with the ActiveX control, though, you'll
need to move that event handling code from VBA to your VB COM addin or
winform.

For VBA samples on event handling, the best place to look is Chapter 21
("Handling Visio Events") in Developing Microsoft Visio Solutions:
http://www.msdn.microsoft.com/libra...rary/en-us/devref/html/dvs_copyright_1270.asp

You can combine the QueueMarkerEvent function in the ShapeSheet with the
event handling code that's provided at the link.

Hope that helps,
Mai-lan

--
Microsoft Corporation
This posting is provided "AS IS" with no warranties, and confers no rights.
Matt said:
Mai-lan is there any chance that you provide us with the VBA version of your
code - please?
It seems to be more sophisticated than the solution I tried in the
visio.developer NG under "DoubleClick with Visio2003 ActiveX drawing
control".
I also found it difficult to distinguish between a rectangle and connector
beeing selected with the "spatialserach -containedIn" Method in a flowchart.
If it worked fine for the process-shape (rectangle) to be selected, I didn't
catch the connectors. Only after increase the tolerance (from 0.001 to 0.1)
and change from "ContainedIn" to "Touching" I caught the connector-shapes
(line with arrows) but then the process-shapes wern't recognized.
Is there a solution in VBA to rightclick any shape on the page and open a
context-menu related to that specific shape?
How would this look like in VBA?

An example would be really great help

Regards
Matt



Mai-lan said:
Hi, there: Both of these scenarios are supported by the ActiveX control.

Here's some C# sample code to demonstrate this. Use Win32's "GetTickCount"
function from C++. VB6 has a Timer function. Spatial proximity may
matter
to
some folks. If so, they need to track the x and y from the events also.
C#:



private void axDrawingControl1_MouseDownEvent(object sender,
AxMicrosoft.Office.Interop.VisOcx.EVisOcx_MouseDownEvent e)

{

// Have a class member like this in the containing
form's class definition:

//

//private int m_previousMouseDownEvent= 0;



const int threshold= 200;



if (0!=m_previousMouseDownEvent &&
(System.Environment.TickCount-m_previousMouseDownEvent)<threshold)

{

// Two MouseDown events occurred within threshold
milliseconds

// of each other... Consider it a "double
click"...

//

System.Windows.Forms.MessageBox.Show("Double
clicked!");

}



m_previousMouseDownEvent = System.Environment.TickCount;

}


(2) Right click a shape, click my own custom menu and
do something
special?

Here's some sample code demonstrating how to replace the default Visio RMA
with a custom menu with a single option (again in C#). Sorry, the formatting
got a little lost. I've also included a couple of helper functions too.

private void axDrawingControl1_MouseUpEvent(object sender,
AxVisOcx.EVisOcx_MouseUpEvent e)

{

if (e.button == (int) Visio.VisKeyButtonFlags.visMouseRight)

{


//need a reference to the shape that was clicked for the context menu

this.clickedShape = VisioUtility.GetClickedShape( VisPage, e.x, e.y );


if (this.clickedShape != null)

{

//cancel the default Visio RMA

e.cancelDefault = true;

//call utility function to translate Visio page units to pixels.

CtxMenuShape.Show(

this,

PageUnitsToPixels( ref axDrawingControl1, e.x, e.y));

}

}

}

public static Shape GetClickedShape( Page visioPage, double x, double y,
double tolerance )

{


try

{

Selection visSelection = visioPage.get_SpatialSearch(

x,

y,

(short) VisSpatialRelationCodes.visSpatialContainedIn,

tolerance,

(short) VisSpatialRelationFlags.visSpatialFrontToBack);

if (visSelection.Count > 0 )

{

// 1 based collection

Debug.WriteLine( visSelection[1].Name);

return (Shape) visSelection[1];


}

else

{

return null;

}

}

catch( Exception exp)

{

Debug.WriteLine( exp.Message );

throw exp;

}

}

private Point PageUnitsToPixels( ref
AxMicrosoft.Office.Interop.VisOcx.AxDrawingControl axDrawingControl, double
x, double y)

{

double vLeft, vTop, vWidth, vHeight;

axDrawingControl.Window.GetViewRect( out vLeft, out vTop, out vWidth, out
vHeight);

// calculate position

int xForm = (int) (axDrawingControl.Left +
(axDrawingControl.Width/vWidth)*(x-vLeft));

int yForm = (int) (axDrawingControl.Top +
(axDrawingControl.Height/vHeight)*(vTop-y));

return new Point( xForm, yForm );

}


Mai-lan
--
Microsoft Corporation
This posting is provided "AS IS" with no warranties, and confers no rights.
Matt said:
Hi Andrew

You really should read the article with the link I posted first . It gives
you a better understanding how the drawingcontrol (ActiveX control) works.
It won't let you execute any VBA in it but you can reach the objects
(shapes, pages, documents etc.) very good from your outside host
application.
Pls. also have a look in the other newsgroup I mentioned before - meanwhile
I found a solution how to create dbl-clicks in the control (it's a bit
of
a
hack and I'm still waiting for some feedback from the Pros, but so far it
works really good for me).
Instead of the msgbox, I'm calling in this procedure you could call your
custom-menu or a form you might have designed as a context-menu (just define
it as popup without any closing, mini- and maximzing buttons)

Regards
MAtt


Thanks Matt!

What I want is I double click a shape, I can see my menu
in the list, e.g. "MyMenu", and then click this menu item
to invoke my procedure. I could do this easily through
Action Cell and "CALLTHIS" function or through
Automation. But seems ActiveX doesn't allow this.

Andrew


-----Original Message-----
Hi Andrew

Have you read this article?
http://www.msdn.microsoft.com/office/understanding/visio/
techarticles/defaul
t.aspx?pull=/library/en-
us/odc_vis2003_ta/html/odc_vsprogrammingwithvisioact
ivexcontrol.asp

It tells you how set/catch mouseevents.

At the moment I try to get an answer how to catch
doubleclicks with VBA in
the microsoft.public.visio.developer newsgroup.
There is already a thread for dbl-click in the active-x
control but they
give only an example for C++
(just search the other NG for "DoubleClick")

With this code you trigger a right button mouseclick:

Private Sub myDrawingControl_MouseDown(ByVal Button As
Long, _
ByVal KeyButtonState As Long, ByVal x As Double, _
ByVal y As Double, CancelDefault As Boolean)

If Button = 2 Then

MsgBox "you right-clicked"

End Sub


Hope this helps
Regards
Matt



"andrweLLL" <[email protected]>
schrieb im Newsbeitrag
(e-mail address removed)...
Using this control in a VB form, can we

(1) double click a shape and call my own procedure?

(2) Right click a shape, click my own custom menu and
do something
special?

From Microsoft website, seems we can do neither of
them. Anybody knows a
work around?

Andrew


.
 
M

Matt

Hello Mai-lan
Thanks one more time - taking care of us.
I think there is a little misunderstanding:
I'm fully aware of the VBA-behavior in the control (thanks to your article
on MSDN)
But as you might recall from other discussions we both had, my present setup
is a drawingControl sitting on a form in MS-Access - very simple testing
setup and NO Com involved!
So I think I can't use the idea in your point 2) with queuemarker - or am I
wrong?

I just want to be able to dbl-click or just rightclick a shape on the
drawingcontrol which sits on an Access-form and open a new form or a custom
context menu related to the shape I clicked on.

I came up with the solution I posted to the visio.developer NG on Oct. 28th
(pasted that mail again below)

But with this spatialSearch-solution in the mousedown-event of the
drawing-control I'm afraid to cause to much traffic and I can only dbl-click
the process-shapes but NOT the connector-shapes in a flowchart (the selction
stays empty dbl-clicking the connector-shapes).

Is there a better solution for that in MS Access-VBA? Any help will be very
much appreciated!

Tia
Matt

=My mail of 28. Oct. for dlb-click in visio drawing
control=========================
OK I kept on trying and came up with the following which seems to work very
nice so far - any comments from the pros - do you see any probs with this
piece of VBA-code?

In the Form_Load Event of the Mainform (on which my drawingControl sits) I
put
Timer1 = 0
Timer2 =0

Then for the mousedown-event:

Private Sub MyDrawingControl_MouseDown(ByVal Button As Long, _
ByVal KeyButtonState As Long, ByVal x As Double, _
ByVal y As Double, CancelDefault As Boolean)
Dim Timer1 as Single
Dim Timer2 as Single
Dim mySel As Visio.Selection
Dim mySelShape As Visio.shape

Set mySel = myVisApp.ActivePage.SpatialSearch(x, y, visSpatialContainedIn, _
0.001, visSpatialFrontToBack)

If timer1 = timer2 Then
timer1 = Timer
Else
timer2 = Timer
If timer2 - timer1 < 1 Then 'if time difference in seconds is smaller then 1
Sec.

Set mySelShape = mySel.Item(1)
MsgBox (mySelShape.Text)
timer1 = timer2
Else
timer1 = timer2

End If
End If

End sub

If you think this code will create performance or other probs please give me
a hint. So far it works very nice but.

Regards
Matt
=========End of Mail ===================


Mai-lan said:
Hi, Matt: I just tried to post a message about this but I don't know if the
mail server will let it through because I put a screenshot in it (whoops).

Anyway, there's two things that I wanted to point out:
1) you will not be able to use VBA with the Visio ActiveX control. The
drawing control does not execute VBA. If you load a document with VBA in it
in the ActiveX control, the VBA will not execute. The control is really
geared at working within a custom container (like a VB form) or in an
application container (like an Access form). Any code that you have in VBA
in your solution will have to be ported out to your drawing control
container or a COM addin. You can still program the ShapeSheet through
automation, though, which leads to my second point.

2) One of the Visio devs pointed out today that there is an easier approach
than the one I recommended, especially if you're a ShapeSheet developer. If
you use CALLTHIS or RUNADDONWARGS, consider using the QueueMarkerEvent
function (new to the ShapeSheet in Visio 2003, although similar
functionality was provided in Visio 2002 SR1. In the DlbClk event of the
ShapeSheet, you can call the QueueMarkerEvent function, passing in a
solution-specific string (like "MyDoubleClickEvent"). That fires an event
from your application and passes that string along to whomever is listening.
So your COM addin can be listening for that string and on the double-click
event firing, present a custom menu or whatever you prefer to do. If you
want to prototype this, you can do it in the Visio app. Just use that
function for a shape and then have some event handling code in VBA to listen
for that event marker string ("MyDoubleClickEvent") and pop up a message box
or something. If you are working with the ActiveX control, though, you'll
need to move that event handling code from VBA to your VB COM addin or
winform.

For VBA samples on event handling, the best place to look is Chapter 21
("Handling Visio Events") in Developing Microsoft Visio Solutions:
http://www.msdn.microsoft.com/library/default.asp?url=/library/en-us/devref/
html/dvs_copyright_1270.asp

You can combine the QueueMarkerEvent function in the ShapeSheet with the
event handling code that's provided at the link.

Hope that helps,
Mai-lan

--
Microsoft Corporation
This posting is provided "AS IS" with no warranties, and confers no rights.
Matt said:
Mai-lan is there any chance that you provide us with the VBA version of your
code - please?
It seems to be more sophisticated than the solution I tried in the
visio.developer NG under "DoubleClick with Visio2003 ActiveX drawing
control".
I also found it difficult to distinguish between a rectangle and connector
beeing selected with the "spatialserach -containedIn" Method in a flowchart.
If it worked fine for the process-shape (rectangle) to be selected, I didn't
catch the connectors. Only after increase the tolerance (from 0.001 to 0.1)
and change from "ContainedIn" to "Touching" I caught the connector-shapes
(line with arrows) but then the process-shapes wern't recognized.
Is there a solution in VBA to rightclick any shape on the page and open a
context-menu related to that specific shape?
How would this look like in VBA?

An example would be really great help

Regards
Matt



Mai-lan said:
Hi, there: Both of these scenarios are supported by the ActiveX control.

(1) double click a shape and call my own procedure?
Here's some C# sample code to demonstrate this. Use Win32's "GetTickCount"
function from C++. VB6 has a Timer function. Spatial proximity may
matter
to
some folks. If so, they need to track the x and y from the events also.
C#:



private void axDrawingControl1_MouseDownEvent(object sender,
AxMicrosoft.Office.Interop.VisOcx.EVisOcx_MouseDownEvent e)

{

// Have a class member like this in the containing
form's class definition:

//

//private int m_previousMouseDownEvent= 0;



const int threshold= 200;



if (0!=m_previousMouseDownEvent &&
(System.Environment.TickCount-m_previousMouseDownEvent)<threshold)

{

// Two MouseDown events occurred within threshold
milliseconds

// of each other... Consider it a "double
click"...

//

System.Windows.Forms.MessageBox.Show("Double
clicked!");

}



m_previousMouseDownEvent = System.Environment.TickCount;

}



(2) Right click a shape, click my own custom menu and
do something
special?

Here's some sample code demonstrating how to replace the default Visio RMA
with a custom menu with a single option (again in C#). Sorry, the formatting
got a little lost. I've also included a couple of helper functions too.

private void axDrawingControl1_MouseUpEvent(object sender,
AxVisOcx.EVisOcx_MouseUpEvent e)

{

if (e.button == (int) Visio.VisKeyButtonFlags.visMouseRight)

{


//need a reference to the shape that was clicked for the context menu

this.clickedShape = VisioUtility.GetClickedShape( VisPage, e.x, e.y );


if (this.clickedShape != null)

{

//cancel the default Visio RMA

e.cancelDefault = true;

//call utility function to translate Visio page units to pixels.

CtxMenuShape.Show(

this,

PageUnitsToPixels( ref axDrawingControl1, e.x, e.y));

}

}

}

public static Shape GetClickedShape( Page visioPage, double x, double y,
double tolerance )

{


try

{

Selection visSelection = visioPage.get_SpatialSearch(

x,

y,

(short) VisSpatialRelationCodes.visSpatialContainedIn,

tolerance,

(short) VisSpatialRelationFlags.visSpatialFrontToBack);

if (visSelection.Count > 0 )

{

// 1 based collection

Debug.WriteLine( visSelection[1].Name);

return (Shape) visSelection[1];


}

else

{

return null;

}

}

catch( Exception exp)

{

Debug.WriteLine( exp.Message );

throw exp;

}

}

private Point PageUnitsToPixels( ref
AxMicrosoft.Office.Interop.VisOcx.AxDrawingControl axDrawingControl, double
x, double y)

{

double vLeft, vTop, vWidth, vHeight;

axDrawingControl.Window.GetViewRect( out vLeft, out vTop, out vWidth, out
vHeight);

// calculate position

int xForm = (int) (axDrawingControl.Left +
(axDrawingControl.Width/vWidth)*(x-vLeft));

int yForm = (int) (axDrawingControl.Top +
(axDrawingControl.Height/vHeight)*(vTop-y));

return new Point( xForm, yForm );

}


Mai-lan
--
Microsoft Corporation
This posting is provided "AS IS" with no warranties, and confers no rights.
Hi Andrew

You really should read the article with the link I posted first . It gives
you a better understanding how the drawingcontrol (ActiveX control) works.
It won't let you execute any VBA in it but you can reach the objects
(shapes, pages, documents etc.) very good from your outside host
application.
Pls. also have a look in the other newsgroup I mentioned before -
meanwhile
I found a solution how to create dbl-clicks in the control (it's a
bit
of
a
hack and I'm still waiting for some feedback from the Pros, but so
far
it
works really good for me).
Instead of the msgbox, I'm calling in this procedure you could call your
custom-menu or a form you might have designed as a context-menu (just
define
it as popup without any closing, mini- and maximzing buttons)

Regards
MAtt


Thanks Matt!

What I want is I double click a shape, I can see my menu
in the list, e.g. "MyMenu", and then click this menu item
to invoke my procedure. I could do this easily through
Action Cell and "CALLTHIS" function or through
Automation. But seems ActiveX doesn't allow this.

Andrew


-----Original Message-----
Hi Andrew

Have you read this article?
http://www.msdn.microsoft.com/office/understanding/visio/
techarticles/defaul
t.aspx?pull=/library/en-
us/odc_vis2003_ta/html/odc_vsprogrammingwithvisioact
ivexcontrol.asp

It tells you how set/catch mouseevents.

At the moment I try to get an answer how to catch
doubleclicks with VBA in
the microsoft.public.visio.developer newsgroup.
There is already a thread for dbl-click in the active-x
control but they
give only an example for C++
(just search the other NG for "DoubleClick")

With this code you trigger a right button mouseclick:

Private Sub myDrawingControl_MouseDown(ByVal Button As
Long, _
ByVal KeyButtonState As Long, ByVal x As Double, _
ByVal y As Double, CancelDefault As Boolean)

If Button = 2 Then

MsgBox "you right-clicked"

End Sub


Hope this helps
Regards
Matt



"andrweLLL" <[email protected]>
schrieb im Newsbeitrag
(e-mail address removed)...
Using this control in a VB form, can we

(1) double click a shape and call my own procedure?

(2) Right click a shape, click my own custom menu and
do something
special?

From Microsoft website, seems we can do neither of
them. Anybody knows a
work around?

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