Converting Visio coordinates to Windows

B

Big Dave

Hi

I am trying to position an activeX dialog on a Visio page, given a set
of Visio coordinates from the mouse events. I have found some
examples, but they do not seem to convert correctly. Maybe this is
because my page is quaite large and zoomed in. Does anyone have an
example of some code that works even if the page is larger than the
screen.

Thanks
 
J

JuneTheSecond

I clould not catch what is your problem. Would you mean that the mouse events
does not return exact coordinates when drawing is larger than the screen?
Would you tell us how large is the zoom , and how large is your drawing?
 
B

Big Dave

I clould not catch what is your problem. Would you mean that the mouse events
does not return exact coordinates when drawing is larger than the screen?
Would you tell us how large is the zoom , and how large is your drawing?

The mouse event does return the correct visio coordinates, my problem
is converting these to windows coordinates for an ActiveX window to be
displayed. I tried the SDK example, but using the windows coordinates
returned, the popup moves further right/down as i move across my
diagram. As I understand it, the visio coordinates are absolute for
the diagram, by that i mean it doesnt matter where i pan or zoom, when
i click on a shape i get the same visio coordinates. My diagram is A2
and i was at 100% zoom, i.e. not all the page is visible.
 
B

Big Dave

What i'm trying to do is have an ActiveX window appear adjacent to a
shape, the shape has been found by using a spatial search from the
visio coordinates returned by the mouse events.
 
C

Chris Pomerantz

I had a ton of problems with this also. It appears that the scroll bars get
in the way. I modified the SDK samples to take the scroll bars into account
and this is what I came up with:

public static System.Drawing.Point MapVisioToWindows(
Window referenceWindow,
double visioX,
double visioY)
{

// The drawing control object must be valid.
if (referenceWindow == null)
{

// Throw a meaningful error.
throw new ArgumentNullException("window");
}

int windowsX = 0;
int windowsY = 0;
double visioLeft;
double visioTop;
double visioWidth;
double visioHeight;
int pixelLeft;
int pixelTop;
int pixelWidth;
int pixelHeight;

// Get the window coordinates in Visio units.
referenceWindow.GetViewRect(out visioLeft, out visioTop,
out visioWidth, out visioHeight);

// Get the window coordinates in pixels.
referenceWindow.GetWindowRect(out pixelLeft, out pixelTop,
out pixelWidth, out pixelHeight);

// GetWindowRect does not take the scrollbar sizes into account
pixelWidth -=
System.Windows.Forms.SystemInformation.VerticalScrollBarWidth;
pixelHeight -=
System.Windows.Forms.SystemInformation.HorizontalScrollBarHeight;

// Convert the X coordinate by using pixels per inch from the
// width values.
windowsX = (int)(pixelLeft +
((pixelWidth / visioWidth) * (visioX - visioLeft)));

// Convert the Y coordinate by using pixels per inch from the
// height values and transform from a top-left origin (windows
// coordinates) to a bottom-left origin (Visio coordinates).
windowsY = (int)(pixelTop +
((pixelHeight / visioHeight) * (visioTop - visioY)));

return new System.Drawing.Point(windowsX, windowsY);
}

public static void MapWindowsToVisio(
Window referenceWindow,
int windowsX,
int windowsY,
out double visioX,
out double visioY)
{

// The drawing control object must be valid.
if (referenceWindow == null)
{

// Throw a meaningful error.
throw new ArgumentNullException("referenceWindow");
}

visioX = 0;
visioY = 0;
double visioLeft;
double visioTop;
double visioWidth;
double visioHeight;
int pixelLeft;
int pixelTop;
int pixelWidth;
int pixelHeight;

// Get the window coordinates in Visio units.
referenceWindow.GetViewRect(out visioLeft, out visioTop,
out visioWidth, out visioHeight);

// Get the window coordinates in pixels.
referenceWindow.GetWindowRect(out pixelLeft, out pixelTop,
out pixelWidth, out pixelHeight);

// GetWindowRect does not take the scrollbar sizes into account
pixelWidth -=
System.Windows.Forms.SystemInformation.VerticalScrollBarWidth;
pixelHeight -=
System.Windows.Forms.SystemInformation.HorizontalScrollBarHeight;

// Convert the X coordinate by using pixels per inch from the
// width values.
visioX = visioLeft +
((visioWidth / (double)pixelWidth) * (double)(windowsX - pixelLeft));

// Convert the Y coordinate by using pixels per inch from the
// height values and transform from a top-left origin (windows
// coordinates) to a bottom-left origin (Visio coordinates).
visioY = -(((visioHeight / (double)pixelHeight) * (double)(windowsY -
pixelTop)) - visioTop);
}

Hope this helps. By the way, the windows coordinates should be screen
coordinates.

- Chris
 

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