private void HandleDPI() { // Declare that this process is aware of per monitor DPI UnmanagedMethods.SetProcessDpiAwareness(UnmanagedMethods.PROCESS_DPI_AWARENESS.PROCESS_PER_MONITOR_DPI_AWARE); // Get the DPI for the main monitor, and set the scaling factor UnmanagedMethods.POINT pt = new UnmanagedMethods.POINT() { X = 1, Y = 1 }; var hMonitor = UnmanagedMethods.MonitorFromPoint(pt, UnmanagedMethods.MONITOR_DEFAULTTONEAREST); // TODO: Check for failure uint dpix, dpiy; UnmanagedMethods.GetDpiForMonitor(hMonitor, UnmanagedMethods.MONITOR_DPI_TYPE.MDT_EFFECTIVE_DPI, out dpix, out dpiy); // Set scale based on x DPI scale = dpix / 100.0; }
private Point ScreenToClient(uint x, uint y) { var p = new UnmanagedMethods.POINT { X = (int)x, Y = (int)y }; UnmanagedMethods.ScreenToClient(_hwnd, ref p); return new Point(p.X, p.Y); }
public Point PointToScreen(Point point) { var p = new UnmanagedMethods.POINT { X = (int)point.X, Y = (int)point.Y }; UnmanagedMethods.ClientToScreen(_hwnd, ref p); return new Point(p.X, p.Y); }
private Point ScreenToClient(Point point) { var p = new UnmanagedMethods.POINT { X = (int)point.X, Y = (int)point.Y }; UnmanagedMethods.ScreenToClient(_hwnd, ref p); return new Point(p.X, p.Y); }