Skip to content

Commit

Permalink
Manipulating window properties
Browse files Browse the repository at this point in the history
  • Loading branch information
airtaxi committed Feb 13, 2025
1 parent d7d7af3 commit 23139c9
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
22 changes: 20 additions & 2 deletions PinStats/Helpers/WindowHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ namespace PinStats.Helpers;
public static partial class WindowHelper
{
private const uint DWMWA_WINDOW_CORNER_PREFERENCE = 33;
private const uint DWMWA_TRANSITIONS_FORCEDISABLED = 3;
private const uint DWMWA_USE_IMMERSIVE_DARK_MODE = 20;

public enum DWM_WINDOW_CORNER_PREFERENCE
public enum DWM_WINDOW_CORNER_PREFERENCE
{
DWMWCP_DEFAULT = 0,
DWMWCP_DONOTROUND = 1,
Expand Down Expand Up @@ -40,5 +42,21 @@ public static void SetWindowCornerToRoundedCorner(Window window)
IntPtr hwnd = window.GetWindowHandle();
uint attribute = (uint)DWM_WINDOW_CORNER_PREFERENCE.DWMWCP_ROUND;
DwmSetWindowAttribute(hwnd, DWMWA_WINDOW_CORNER_PREFERENCE, ref attribute, sizeof(uint));
}
}

public static void DisableWindowAnimations(Window window)
{
IntPtr hwnd = window.GetWindowHandle();
uint disableAnimation = 1;
DwmSetWindowAttribute(hwnd, DWMWA_TRANSITIONS_FORCEDISABLED, ref disableAnimation, sizeof(uint));
}

public static void SetDarkModeWindow(Window window)
{
IntPtr hwnd = window.GetWindowHandle();
uint darkMode = 1;

DwmSetWindowAttribute(hwnd, DWMWA_USE_IMMERSIVE_DARK_MODE, ref darkMode, sizeof(uint));
}

}
8 changes: 7 additions & 1 deletion PinStats/PopupWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,14 @@ public PopupWindow()
{
InitializeComponent();

// Disable window animations and set dark mode if
WindowHelper.DisableWindowAnimations(this);

// Fix white flickering issue when the window is first shown
if ((Content as FrameworkElement).RequestedTheme == ElementTheme.Dark) WindowHelper.SetDarkModeWindow(this);

// Set window and AppWindow properties
this.SetIsAlwaysOnTop(true);
this.SetIsAlwaysOnTop(true);
this.SetIsShownInSwitchers(false);

// Hide the title bar
Expand Down

0 comments on commit 23139c9

Please sign in to comment.