public static IEnumerator UpdateWeirdOffset(UDDMonitor monitor, UwcWindow window) { WinNative.SetCursorPos(0, 0); WinNative.SetWindowPos(window.handle, 0, 0, 0, 0, 0, SetWindowPosFlags.SWP_NOSIZE); int size = Marshal.SizeOf(typeof(RECT)); WinNative.SetThreadDpiAwarenessContext(PROCESS_DPI_AWARENESS.PROCESS_PER_MONITOR_DPI_AWARE); RECT rect = new RECT(); RECT frame = new RECT(); WinNative.GetWindowRect(window.handle, ref rect); WinNative.DwmGetWindowAttribute(window.handle, DWMWINDOWATTRIBUTE.ExtendedFrameBounds, out frame, size); //rect should be `0, 0, 1280, 1024` //frame should be `7, 0, 1273, 1017` RECT border = new RECT(); border.Left = frame.Left - rect.Left; border.Top = frame.Top - rect.Top; border.Right = rect.Right - frame.Right; border.Bottom = rect.Bottom - frame.Bottom; Debug.Log(border.Left); yield return(new WaitForSeconds(0.1f)); WinNative.MoveOverWindow(window.handle, new Point(0, 0), true); WinNative.POINT curCursorPos = new WinNative.POINT(); WinNative.GetCursorPos(ref curCursorPos); //window.weirdOffset = Math.Abs(curCursorPos.x); yield break; while (true) { RECT yay = new RECT(); WinNative.GetWindowRect(window.handle, ref yay); Debug.Log(yay.Left); yield return(null); } //Debug.Log(window.weirdOffset); }
public static RECT GetExtensionSizeForWindow(UwcWindow window) { int size = Marshal.SizeOf(typeof(RECT)); WinNative.SetThreadDpiAwarenessContext(PROCESS_DPI_AWARENESS.PROCESS_PER_MONITOR_DPI_AWARE); RECT rect = new RECT(); RECT frame = new RECT(); WinNative.GetWindowRect(window.handle, ref rect); WinNative.DwmGetWindowAttribute(window.handle, DWMWINDOWATTRIBUTE.ExtendedFrameBounds, out frame, size); RECT border = new RECT(); border.Left = frame.Left - rect.Left; border.Top = frame.Top - rect.Top; border.Right = rect.Right - frame.Right; border.Bottom = rect.Bottom - frame.Bottom; return(border); }
public static UDDMonitor GetMonitor(UwcWindow window) { if (window.isIconic) { WinNative.ShowWindow(window.handle, ShowWindowCommands.ShowMaximized); } RECT rect = new RECT(); WinNative.GetWindowRect(window.handle, ref rect); UDDMonitor closestMonitor; int midX = 0, midY = 0; midX = window.rawX + (int)(window.rawWidth / 2f); midY = window.rawY + (int)(window.rawHeight / 2f); foreach (UDDMonitor monitor in monitors) { if (monitor.left > midX) { continue; } if (monitor.top > midY) { continue; } if (monitor.right <= midX) { continue; } if (monitor.bottom <= midY) { continue; } closestMonitor = monitor; return(closestMonitor); break; } //else, it failed, so return the biggest monitor: UDDMonitor biggestMonitor = null; foreach (UDDMonitor monitor in monitors) { if (biggestMonitor == null) { biggestMonitor = monitor; } if (monitor.width > biggestMonitor.width && monitor.height > biggestMonitor.height) { biggestMonitor = monitor; } } return(biggestMonitor); }