How would one poll windows to see what monitors are attached and what resolution they are running at?
In C#: Screen
Class Represents a display device or multiple display devices on a single system. You want the Bounds
attribute.
foreach(var screen in Screen.AllScreens)
{
// For each screen, add the screen properties to a list box.
listBox1.Items.Add("Device Name: " + screen.DeviceName);
listBox1.Items.Add("Bounds: " + screen.Bounds.ToString());
listBox1.Items.Add("Type: " + screen.GetType().ToString());
listBox1.Items.Add("Working Area: " + screen.WorkingArea.ToString());
listBox1.Items.Add("Primary Screen: " + screen.Primary.ToString());
}
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.
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_8fjn.asp. GetSystemMetrics is a handy function you frequently need to use, and new stuff appears with every version of Windows.
System.Windows.Forms.SystemInformation
class likely contains a majority. –
Dragnet © 2022 - 2024 — McMap. All rights reserved.
foreach (Screen screen in Screen.AllScreens)
this looks even better. – Postlude