public static Eto.Drawing.PointF ScreenToLogical(this sd.Point point, swf.Screen sdscreen = null) { sdscreen = sdscreen ?? swf.Screen.FromPoint(point); var location = sdscreen.GetLogicalLocation(); var pixelSize = sdscreen.GetLogicalPixelSize(); var sdscreenBounds = sdscreen.GetBounds(); var x = location.X + (point.X - sdscreenBounds.X) / pixelSize; var y = location.Y + (point.Y - sdscreenBounds.Y) / pixelSize; // Console.WriteLine($"In: {point}, out: {x},{y}"); return(new Drawing.PointF(x, y)); }
public static Eto.Drawing.RectangleF ScreenToLogical(this Eto.Drawing.Rectangle rect, swf.Screen screen) { screen = screen ?? swf.Screen.FromPoint(rect.Location.ToSD()); var location = screen.GetLogicalLocation(); var pixelSize = screen.GetLogicalPixelSize(); var screenBounds = screen.GetBounds(); return(new Eto.Drawing.RectangleF( location.X + (rect.X - screenBounds.X) / pixelSize, location.Y + (rect.Y - screenBounds.Y) / pixelSize, rect.Width / pixelSize, rect.Height / pixelSize )); }
public static Rectangle GetWorkArea(this Screen screen, out double screenFactor, out double dpiFactor, out int barEdge) { RECT barRect = new RECT(); var bounds = screen.GetBounds(); string[] tbClassNames = new string[] { "Shell_TrayWnd", "Shell_SecondaryTrayWnd" }; if (screen.Primary == false) { tbClassNames = new string[] { "Shell_SecondaryTrayWnd", "Shell_TrayWnd" }; } IntPtr taskbarHandle; Rectangle logicBounds; Rectangle bRect; screenFactor = 1; dpiFactor = 1; barEdge = 3; foreach (var className in tbClassNames) { taskbarHandle = FindWindowEx(IntPtr.Zero, IntPtr.Zero, className, null); GetWindowRect(taskbarHandle, out barRect); var g = Graphics.FromHwnd(taskbarHandle); var h = g.GetHdc(); SafeDCHandle sh = new SafeDCHandle(taskbarHandle, h); int LogicalScreenHeight = Gdi32.GetDeviceCaps(sh, DeviceCap.VERTRES); int PhysicalScreenHeight = Gdi32.GetDeviceCaps(sh, DeviceCap.DESKTOPVERTRES); int logpixelsy = Gdi32.GetDeviceCaps(sh, DeviceCap.LOGPIXELSY); screenFactor = (float)PhysicalScreenHeight / (float)LogicalScreenHeight; dpiFactor = (float)logpixelsy / (float)96; sh.Dispose(); if (taskbarHandle == IntPtr.Zero) { return(bounds); } //} //else //{ // var data = new APPBARDATA(); // data.cbSize = Marshal.SizeOf(data); // var ret = SHAppBarMessage((int)ABMsg.ABM_GETTASKBARPOS, ref data); // barRect = data.rc; //} bRect = Rectangle.FromLTRB(barRect.left, barRect.top, barRect.right, barRect.bottom); var bRect2 = Rectangle.FromLTRB(barRect.left, barRect.top, barRect.right, barRect.bottom); bRect2.Inflate(-5, -5); var dx = 1; var dy = 1; logicBounds = new Rectangle(bounds.X, bounds.Y, (int)(bounds.Width * dx), (int)(bounds.Height * dy)); //var logicBounds = bounds; if (logicBounds.Contains(bRect2) == false) { continue; } barEdge = 3; var l = bounds.Left; var t = bounds.Top; var r = bounds.Right; var b = bounds.Bottom; if (Math.Abs(logicBounds.Right - bRect.Right) > 5) { barEdge = 0; l = (int)(bRect.Right / dx); } else if (Math.Abs(logicBounds.Bottom - bRect.Bottom) > 5) { barEdge = 1; t = (int)(bRect.Bottom / dy); } else if (Math.Abs(logicBounds.Left - bRect.Left) > 5) { barEdge = 2; r = (int)(bRect.Left / dx); } else if (Math.Abs(logicBounds.Top - bRect.Top) > 5) { barEdge = 3; b = (int)(bRect.Top / dy); } var clientBounds = Rectangle.FromLTRB(l, t, r, b); return(clientBounds); } return(bounds); }