From 38a6b07f2e3ca05147f8066ac4828d67735fdc5e Mon Sep 17 00:00:00 2001 From: Nguyen Duy Date: Thu, 9 May 2024 07:11:34 +0700 Subject: [PATCH] Move drop shadow helper --- app/Helper.cs | 30 ++++++++++++++++++++++++++++++ app/MainWindow.xaml.cs | 2 +- app/ParsecVDisplay.csproj | 1 - app/Shadow.cs | 38 -------------------------------------- 4 files changed, 31 insertions(+), 40 deletions(-) delete mode 100644 app/Shadow.cs diff --git a/app/Helper.cs b/app/Helper.cs index 5b56f80..e6275e0 100644 --- a/app/Helper.cs +++ b/app/Helper.cs @@ -75,5 +75,35 @@ namespace ParsecVDisplay [DllImport("kernel32.dll")] static extern int SetThreadExecutionState(uint esFlags); + + public static void EnableDropShadow(IntPtr hwnd) + { + var v = 2; + DwmSetWindowAttribute(hwnd, 2, ref v, 4); + + var margins = new MARGINS + { + bottomHeight = 0, + leftWidth = 0, + rightWidth = 0, + topHeight = 1 + }; + DwmExtendFrameIntoClientArea(hwnd, ref margins); + } + + [DllImport("dwmapi.dll")] + static extern int DwmSetWindowAttribute(IntPtr hwnd, int attr, ref int attrValue, int attrSize); + + [StructLayout(LayoutKind.Sequential)] + struct MARGINS + { + public int leftWidth; + public int rightWidth; + public int topHeight; + public int bottomHeight; + } + + [DllImport("dwmapi.dll")] + static extern int DwmExtendFrameIntoClientArea(IntPtr hWnd, ref MARGINS pMarInset); } } \ No newline at end of file diff --git a/app/MainWindow.xaml.cs b/app/MainWindow.xaml.cs index 12bb698..790262a 100644 --- a/app/MainWindow.xaml.cs +++ b/app/MainWindow.xaml.cs @@ -38,7 +38,7 @@ namespace ParsecVDisplay base.OnSourceInitialized(e); var hwnd = new WindowInteropHelper(this).EnsureHandle(); - Shadow.ApplyShadow(hwnd); + Helper.EnableDropShadow(hwnd); } protected override void OnClosing(CancelEventArgs e) diff --git a/app/ParsecVDisplay.csproj b/app/ParsecVDisplay.csproj index 88931c7..af75408 100644 --- a/app/ParsecVDisplay.csproj +++ b/app/ParsecVDisplay.csproj @@ -86,7 +86,6 @@ - diff --git a/app/Shadow.cs b/app/Shadow.cs deleted file mode 100644 index dd81ec6..0000000 --- a/app/Shadow.cs +++ /dev/null @@ -1,38 +0,0 @@ -using System; -using System.Runtime.InteropServices; - -namespace ParsecVDisplay -{ - internal static class Shadow - { - [DllImport("dwmapi.dll")] - static extern int DwmSetWindowAttribute(IntPtr hwnd, int attr, ref int attrValue, int attrSize); - - [StructLayout(LayoutKind.Sequential)] - struct MARGINS - { - public int leftWidth; - public int rightWidth; - public int topHeight; - public int bottomHeight; - } - - [DllImport("dwmapi.dll")] - static extern int DwmExtendFrameIntoClientArea(IntPtr hWnd, ref MARGINS pMarInset); - - public static void ApplyShadow(IntPtr hwnd) - { - var v = 2; - DwmSetWindowAttribute(hwnd, 2, ref v, 4); - - var margins = new MARGINS - { - bottomHeight = 0, - leftWidth = 0, - rightWidth = 0, - topHeight = 1 - }; - DwmExtendFrameIntoClientArea(hwnd, ref margins); - } - } -} \ No newline at end of file