static PointF GetPhysicalMonitorSize(string targetDeviceID) { List <DISPLAY_DEVICE> displays = GetDisplayList(); PointF size = new PointF(-1.0f, -1.0f); for (int i = 0; i < displays.Count; i++) { DISPLAY_DEVICE d = displays[i]; string deviceHashID = SuperFastHashSimple.Hash(Encoding.ASCII.GetBytes(d.DeviceName)).ToString(); // If the DeviceID is empty and matches our target ID, the following object is a connected monitor // if the following objects DeviceID starts with "MONTIOR" or "DISPLAY" if (d.DeviceID == "" && deviceHashID == targetDeviceID) { DISPLAY_DEVICE m = displays[i + 1]; if (m.DeviceID.ToUpper().IndexOf("DISPLAY") != -1 || m.DeviceID.ToUpper().IndexOf("MONITOR") != -1) { string InstanceID = GetInstanceIDFromDevicePath(m.DeviceID); size = GetMonitorSizeUsingEDID(InstanceID); return(size); } } else if (deviceHashID == targetDeviceID) { string InstanceID = GetInstanceIDFromDevicePath(d.DeviceID); size = GetMonitorSizeUsingEDID(InstanceID); return(size); } } return(size); }
static PointF GetScreenResolution(string targetScreenID) { PointF resPt = new PointF(-1.0f, -1.0f); foreach (var screen in Screen.AllScreens) { string deviceHashID = SuperFastHashSimple.Hash(Encoding.ASCII.GetBytes(screen.DeviceName)).ToString(); if (deviceHashID == targetScreenID) { Rectangle resRect = screen.Bounds; resPt.X = resRect.Width; resPt.Y = resRect.Height; } } return(resPt); }