Skip to content
Prev Previous commit
Next Next commit
Move all of UxTheme to CsWin32.
  • Loading branch information
Nuklon committed Nov 10, 2025
commit 0499faf45eee76b6abfbdf40b11c976a3cf370cb
40 changes: 18 additions & 22 deletions src/Wpf.Ui/Interop/UnsafeNativeMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,7 @@ public static bool RemoveWindowCaption(Window window)
return RemoveWindowCaption(windowHandle);
}

public static bool RemoveWindowCaption(IntPtr hWnd)
public static unsafe bool RemoveWindowCaption(IntPtr hWnd)
{
if (hWnd == IntPtr.Zero)
{
Expand All @@ -533,21 +533,17 @@ public static bool RemoveWindowCaption(IntPtr hWnd)
{
return false;
}

var wtaOptions = new UxTheme.WTA_OPTIONS()
var wtaOptions = new WTA_OPTIONS()
{
dwFlags = UxTheme.WTNCA.NODRAWCAPTION,
dwMask = UxTheme.WTNCA.VALIDBITS,
dwFlags = PInvoke.WTNCA_NODRAWCAPTION,
dwMask = PInvoke.WTNCA_NODRAWCAPTION | PInvoke.WTNCA_NODRAWICON | PInvoke.WTNCA_NOMIRRORHELP | PInvoke.WTNCA_NOSYSMENU,
};

UxTheme.SetWindowThemeAttribute(
hWnd,
UxTheme.WINDOWTHEMEATTRIBUTETYPE.WTA_NONCLIENT,
ref wtaOptions,
(uint)Marshal.SizeOf(typeof(UxTheme.WTA_OPTIONS))
);

return true;
return PInvoke.SetWindowThemeAttribute(new HWND(hWnd),
WINDOWTHEMEATTRIBUTETYPE.WTA_NONCLIENT,
&wtaOptions,
(uint)sizeof(WTA_OPTIONS)) == Windows.Win32.Foundation.HRESULT.S_OK;
}

public static bool ExtendClientAreaIntoTitleBar(Window window)
Expand All @@ -562,7 +558,7 @@ public static bool ExtendClientAreaIntoTitleBar(Window window)
return ExtendClientAreaIntoTitleBar(windowHandle);
}

public static bool ExtendClientAreaIntoTitleBar(IntPtr hWnd)
public static unsafe bool ExtendClientAreaIntoTitleBar(IntPtr hWnd)
{
/*
* !! EXPERIMENTAl !!
Expand All @@ -580,17 +576,17 @@ public static bool ExtendClientAreaIntoTitleBar(IntPtr hWnd)
}

// #1 Remove titlebar elements
var wtaOptions = new UxTheme.WTA_OPTIONS()
var wtaOptions = new WTA_OPTIONS()
{
dwFlags = UxTheme.WTNCA.NODRAWCAPTION | UxTheme.WTNCA.NODRAWICON | UxTheme.WTNCA.NOSYSMENU,
dwMask = UxTheme.WTNCA.VALIDBITS,
dwFlags = PInvoke.WTNCA_NODRAWCAPTION | PInvoke.WTNCA_NODRAWICON | PInvoke.WTNCA_NOSYSMENU,
dwMask = PInvoke.WTNCA_NODRAWCAPTION | PInvoke.WTNCA_NODRAWICON | PInvoke.WTNCA_NOMIRRORHELP | PInvoke.WTNCA_NOSYSMENU
};

Interop.UxTheme.SetWindowThemeAttribute(
hWnd,
UxTheme.WINDOWTHEMEATTRIBUTETYPE.WTA_NONCLIENT,
ref wtaOptions,
(uint)Marshal.SizeOf(typeof(UxTheme.WTA_OPTIONS))
PInvoke.SetWindowThemeAttribute(
new HWND(hWnd),
WINDOWTHEMEATTRIBUTETYPE.WTA_NONCLIENT,
&wtaOptions,
(uint)sizeof(WTA_OPTIONS)
);

DisplayDpi windowDpi = DpiHelper.GetWindowDpi(hWnd);
Expand Down
124 changes: 0 additions & 124 deletions src/Wpf.Ui/Interop/UxTheme.cs

This file was deleted.

5 changes: 4 additions & 1 deletion src/Wpf.Ui/NativeMethods.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
S_OK
DwmIsCompositionEnabled
DwmExtendFrameIntoClientArea
DwmExtendFrameIntoClientArea
SetWindowThemeAttribute
WTA_OPTIONS
WTNCA_*