How to get Multi-Monitor Position?

S

slowram

I know how to get the monitor dimensions, virtual monitor dimensions,
but how do I get the location of the second monitor in relationship to
the original?
On the desktop when I go into my property settings for the monitor I
can move around the monitors so if say the second monitor is lower
than the first I can position it accordingly. Are these values wrote
to the registry? Is there some way to get them?
For instance I'd like to know if the secondary monitor is above,
below, to the right, or left of the primary monitor? Say if it's to
the right and not aligned perfectly I'd like to know what Y coordinate
it starts/ends at compared to the primary monitor.
 
C

Chris R. Timmons

(e-mail address removed) wrote in
I know how to get the monitor dimensions, virtual monitor
dimensions, but how do I get the location of the second monitor
in relationship to the original?
On the desktop when I go into my property settings for the
monitor I can move around the monitors so if say the second
monitor is lower than the first I can position it accordingly.
Are these values wrote to the registry? Is there some way to
get them? For instance I'd like to know if the secondary monitor
is above, below, to the right, or left of the primary monitor?
Say if it's to the right and not aligned perfectly I'd like to
know what Y coordinate it starts/ends at compared to the primary
monitor.

(I don't have a multimonitor setup to test this idea with, so take
it with grain of salt...)

I think the Windows API GetMonitorInfo function will return the
information you're looking for.

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/gdi/monitor_27e7.asp

It returns a MONITORINFO structure that contains a rcMonitor RECT
data member. That rectangle is expressed in virtual screen coordinates.
From the documentation, it appears that the coordinates of secondary
monitors are expressed relative to the position of the primary screen.

Reflector (http://www.aisto.com/roeder/dotnet/) shows how the .Net
framework uses GetMonitorInfo in System.Windows.Forms.Screen,
as well as how it and the MONITORINFO structure are declared for
use with P/Invoke calls in C#.
 
P

Peter Rilling

What happens if you get the bounds for each monitor? Is the upper-left
always 0,0 or is the second monitor adjusted based on its position in
"virtual space"?

If the upper-left is relative, then you might be able to use this, along
with the width and height of each, to determine their relative position.
 

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