views:

265

answers:

3

How would one poll windows to see what monitors are attached and what resolution they are running at?

+1  A: 

http://msdn.microsoft.com/en-us/magazine/cc301462.aspx

GetSystemMetrics is a handy function you can use to get all sorts of global dimensions, like the size of an icon or height of a window caption. In Windows 2000, there are new parameters like SM_CXVIRTUALSCREEN and SM_CYVIRTUALSCREEN to get the virtual size of the screen for multiple monitor systems. Windows newbies—and pros, too—should check out the documentation for GetSystemMetrics to see all the different system metrics (dimensions) you can get. See the Platform SDK for the latest at http://msdn.microsoft.com/library/en-us/sysinfo/sysinfo%5F8fjn.asp. GetSystemMetrics is a handy function you frequently need to use, and new stuff appears with every version of Windows.

somacore
+4  A: 

In C#: Screen Class Represents a display device or multiple display devices on a single system. You want the Bounds attribute.

int index;
int upperBound; 
Screen [] screens = Screen.AllScreens;
upperBound = screens.GetUpperBound(0);
for(index = 0; index <= upperBound; index++)
{
    // For each screen, add the screen properties to a list box.
    listBox1.Items.Add("Device Name: " + screens[index].DeviceName);
    listBox1.Items.Add("Bounds: " + screens[index].Bounds.ToString());
    listBox1.Items.Add("Type: " + screens[index].GetType().ToString());
    listBox1.Items.Add("Working Area: " + screens[index].WorkingArea.ToString());
    listBox1.Items.Add("Primary Screen: " + screens[index].Primary.ToString());
}
Joe Koberg
+1  A: 

Use the Screen class.

You can see all of the monitors in the Screen.AllScreens array, and check the resolution and position of each one using the Bounds property.

Note that some video cards will merge two monitors into a single very wide screen, so that Windows thinks that there is only one monitor. If you want to, you could check whether the width of a screen is more than twice its height; if so, it's probably a horizontal span and you can treat it as two equal screens. However, this is more complicated and you don't need to do it. Vertical spans are also supported but less common.

SLaks