[DllImport("user32.dll", CharSet=CharSet.Unicode))]
static extern bool EnumDisplayDevices(string lpDevice, uint iDevNum,
ref DISPLAY_DEVICE lpDisplayDevice, uint dwFlags);
None.
Please add some!
// This method will return the size of the complete desktop area, taking all attached devices into account.
public Size GetDesktopSize()
{
Rectangle desktop = new Rectangle();
DISPLAY_DEVICE device = new DISPLAY_DEVICE();
device.cb = System.Runtime.InteropServices.Marshal.SizeOf(typeof(DISPLAY_DEVICE));
device.DeviceName = new string(' ', 32);
device.DeviceString = new string(' ', 128);
device.DeviceKey = new string(' ', 128);
device.DeviceID = new string(' ', 128);
for(uint i = 0; ; i++)
{
if (!Win32.EnumDisplayDevices(null, i, ref device, 0))
break;
// If it's not connected to the desktop, then ignore it.
if ((device.StateFlags & 1) == 0)
continue;
// Get the settings of the current display mode for this device.
DEVMODE devMode = new DEVMODE();
if (!Win32.EnumDisplaySettings(device.DeviceName, uint.MaxValue, ref devMode))
continue;
// This is the rectangle defined by this device
Rectangle deviceRect = new Rectangle(devMode.dmPosition.x, devMode.dmPosition.y,
devMode.dmPelsWidth, devMode.dmPelsHeight);
// Update the "desktop" rectangle with the new device
if (desktop.Left > deviceRect.Left)
desktop.Location = new Point(deviceRect.Left, desktop.Y);
if (desktop.Top > deviceRect.Top)
desktop.Location = new Point(desktop.X, deviceRect.Top);
if (desktop.Right < deviceRect.Right)
desktop.Size = new Size(deviceRect.Width, desktop.Height);
if (desktop.Bottom < deviceRect.Bottom)
desktop.Size = new Size(desktop.Width, deviceRect.Height);
}
// And return the size of the total desktop.
return desktop.Size;
}
Do you know one? Please contribute it!