From 965959cfac72d2a8794b0b698da11a119a4e01d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Przemys=C5=82aw=20K=C5=82ys?= Date: Tue, 17 Jun 2025 17:20:42 +0200 Subject: [PATCH] Replace literal flag and define constants --- Sources/DesktopManager/MonitorNativeMethods.cs | 6 ++++++ Sources/DesktopManager/WindowManager.cs | 8 +++----- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/Sources/DesktopManager/MonitorNativeMethods.cs b/Sources/DesktopManager/MonitorNativeMethods.cs index f62ef96..7433119 100644 --- a/Sources/DesktopManager/MonitorNativeMethods.cs +++ b/Sources/DesktopManager/MonitorNativeMethods.cs @@ -160,4 +160,10 @@ public static class MonitorNativeMethods { /// public const int WS_MINIMIZE = 0x20000000; public const int WS_MAXIMIZE = 0x01000000; + + /// + /// Window position flags + /// + public const int SWP_NOZORDER = 0x0004; + public const int SWP_NOSIZE = 0x0001; } diff --git a/Sources/DesktopManager/WindowManager.cs b/Sources/DesktopManager/WindowManager.cs index b17cd1b..f137f21 100644 --- a/Sources/DesktopManager/WindowManager.cs +++ b/Sources/DesktopManager/WindowManager.cs @@ -132,7 +132,7 @@ public void SetWindowPosition(WindowInfo windowInfo, int left, int top) { top, -1, -1, - 1)) { + MonitorNativeMethods.SWP_NOZORDER | MonitorNativeMethods.SWP_NOSIZE)) { throw new InvalidOperationException("Failed to set window position"); } } @@ -146,11 +146,9 @@ public void SetWindowPosition(WindowInfo windowInfo, int left, int top) { /// The width of the window. Use -1 to keep current width. /// The height of the window. Use -1 to keep current height. public void SetWindowPosition(WindowInfo windowInfo, int left, int top, int width = -1, int height = -1) { - const int SWP_NOZORDER = 0x0004; const int SWP_NOMOVE = 0x0002; - const int SWP_NOSIZE = 0x0001; - int flags = SWP_NOZORDER; + int flags = MonitorNativeMethods.SWP_NOZORDER; // If position is -1, don't move if (left < 0 && top < 0) { @@ -159,7 +157,7 @@ public void SetWindowPosition(WindowInfo windowInfo, int left, int top, int widt // If size is -1, don't resize if (width < 0 && height < 0) { - flags |= SWP_NOSIZE; + flags |= MonitorNativeMethods.SWP_NOSIZE; } if (!MonitorNativeMethods.SetWindowPos(