Skip to content
Prev Previous commit
Next Next commit
Shell to CsWin32.
  • Loading branch information
Nuklon committed Nov 10, 2025
commit dd51a7c9f7d1ffb46a0e302d7290c0ed8da3e013
34 changes: 0 additions & 34 deletions src/Wpf.Ui/Interop/Libraries.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,39 +10,5 @@ namespace Wpf.Ui.Interop;
/// </summary>
internal static class Libraries
{
/*internal const string Advapi32 = "advapi32.dll";
internal const string BCrypt = "BCrypt.dll";
internal const string CoreComm_L1_1_1 = "api-ms-win-core-comm-l1-1-1.dll";
internal const string Crypt32 = "crypt32.dll";*/
internal const string Dwmapi = "dwmapi.dll";

/*internal const string Error_L1 = "api-ms-win-core-winrt-error-l1-1-0.dll";
internal const string HttpApi = "httpapi.dll";
internal const string IpHlpApi = "iphlpapi.dll";*/
internal const string Kernel32 = "kernel32.dll";

/*internal const string Memory_L1_3 = "api-ms-win-core-memory-l1-1-3.dll";
internal const string Mswsock = "mswsock.dll";
internal const string NCrypt = "ncrypt.dll";
internal const string NtDll = "ntdll.dll";
internal const string Odbc32 = "odbc32.dll";
internal const string OleAut32 = "oleaut32.dll";
internal const string PerfCounter = "perfcounter.dll";
internal const string RoBuffer = "api-ms-win-core-winrt-robuffer-l1-1-0.dll";
internal const string Secur32 = "secur32.dll";*/
internal const string Shell32 = "shell32.dll";

/*internal const string SspiCli = "sspicli.dll";*/
internal const string User32 = "user32.dll";
internal const string UxTheme = "uxtheme.dll";

/*internal const string Gdi32 = "gdi32.dll";
internal const string Gdip = "gdiplus.dll";*/
internal const string Version = "version.dll";
/*internal const string WebSocket = "websocket.dll";
internal const string WinHttp = "winhttp.dll";
internal const string WinMM = "winmm.dll";
internal const string Ws2_32 = "ws2_32.dll";
internal const string Wtsapi32 = "wtsapi32.dll";
internal const string CompressionNative = "System.IO.Compression.Native.dll";*/
}
209 changes: 0 additions & 209 deletions src/Wpf.Ui/Interop/ShObjIdl.cs

This file was deleted.

19 changes: 10 additions & 9 deletions src/Wpf.Ui/Interop/UnsafeNativeMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ This Source Code is partially based on the source code provided by the .NET Foun
using Windows.Win32.Foundation;
using Windows.Win32.Graphics.Dwm;
using Windows.Win32.UI.Controls;
using Windows.Win32.UI.Shell;
using Windows.Win32.UI.WindowsAndMessaging;
using Microsoft.Win32;
using Wpf.Ui.Controls;
Expand Down Expand Up @@ -451,7 +452,7 @@ public static Color GetAccentColor()
/// </summary>
/// <param name="hWnd">Window handle.</param>
/// <param name="taskbarFlag">Taskbar flag.</param>
internal static bool SetTaskbarState(IntPtr hWnd, ShObjIdl.TBPFLAG taskbarFlag)
internal static bool SetTaskbarState(IntPtr hWnd, TBPFLAG taskbarFlag)
{
if (hWnd == IntPtr.Zero)
{
Expand All @@ -462,14 +463,14 @@ internal static bool SetTaskbarState(IntPtr hWnd, ShObjIdl.TBPFLAG taskbarFlag)
{
return false;
}

if (new ShObjIdl.CTaskbarList() is not ShObjIdl.ITaskbarList4 taskbarList)
if (new TaskbarList() is not ITaskbarList4 taskbarList)
{
return false;
}

taskbarList.HrInit();
taskbarList.SetProgressState(hWnd, taskbarFlag);
taskbarList.SetProgressState(new HWND(hWnd), taskbarFlag);

return true;
}
Expand All @@ -482,7 +483,7 @@ internal static bool SetTaskbarState(IntPtr hWnd, ShObjIdl.TBPFLAG taskbarFlag)
/// <param name="current">Current progress value.</param>
/// <param name="total">Maximum progress value.</param>
/// <returns>True if successful updated, otherwise false.</returns>
internal static bool SetTaskbarValue(IntPtr hWnd, ShObjIdl.TBPFLAG taskbarFlag, int current, int total)
internal static bool SetTaskbarValue(IntPtr hWnd, TBPFLAG taskbarFlag, int current, int total)
{
if (hWnd == IntPtr.Zero)
{
Expand All @@ -496,17 +497,17 @@ internal static bool SetTaskbarValue(IntPtr hWnd, ShObjIdl.TBPFLAG taskbarFlag,

/* TODO: Get existing taskbar class */

if (new ShObjIdl.CTaskbarList() is not ShObjIdl.ITaskbarList4 taskbarList)
if (new TaskbarList() is not ITaskbarList4 taskbarList)
{
return false;
}

taskbarList.HrInit();
taskbarList.SetProgressState(hWnd, taskbarFlag);
taskbarList.SetProgressState(new HWND(hWnd), taskbarFlag);

if (taskbarFlag is not ShObjIdl.TBPFLAG.TBPF_INDETERMINATE and not ShObjIdl.TBPFLAG.TBPF_NOPROGRESS)
if (taskbarFlag is not TBPFLAG.TBPF_INDETERMINATE and not TBPFLAG.TBPF_NOPROGRESS)
{
taskbarList.SetProgressValue(hWnd, Convert.ToUInt64(current), Convert.ToUInt64(total));
taskbarList.SetProgressValue(new HWND(hWnd), Convert.ToUInt64(current), Convert.ToUInt64(total));
}

return true;
Expand Down
21 changes: 11 additions & 10 deletions src/Wpf.Ui/Interop/UnsafeReflection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
This Source Code is partially based on the source code provided by the .NET Foundation. */

using Windows.Win32.Graphics.Dwm;
using Windows.Win32.UI.Shell;
using Wpf.Ui.Controls;
using Wpf.Ui.TaskBar;

Expand All @@ -19,7 +20,7 @@ namespace Wpf.Ui.Interop;
internal static class UnsafeReflection
{
/// <summary>
/// Casts <see cref="WindowBackdropType"/> to <see cref="DWM_SYSTEMBACKDROP_TYPE"/>.
/// Casts <see cref="WindowBackdropType" /> to <see cref="DWM_SYSTEMBACKDROP_TYPE" />.
/// </summary>
public static DWM_SYSTEMBACKDROP_TYPE Cast(WindowBackdropType backgroundType)
{
Expand All @@ -34,7 +35,7 @@ public static DWM_SYSTEMBACKDROP_TYPE Cast(WindowBackdropType backgroundType)
}

/// <summary>
/// Casts <see cref="WindowCornerPreference"/> to <see cref="DWM_WINDOW_CORNER_PREFERENCE"/>.
/// Casts <see cref="WindowCornerPreference" /> to <see cref="DWM_WINDOW_CORNER_PREFERENCE" />.
/// </summary>
public static DWM_WINDOW_CORNER_PREFERENCE Cast(WindowCornerPreference cornerPreference)
{
Expand All @@ -48,17 +49,17 @@ public static DWM_WINDOW_CORNER_PREFERENCE Cast(WindowCornerPreference cornerPre
}

/// <summary>
/// Casts <see cref="TaskBarProgressState"/> to <see cref="ShObjIdl.TBPFLAG"/>.
/// Casts <see cref="TaskBarProgressState" /> to <see cref="TBPFLAG" />.
/// </summary>
public static ShObjIdl.TBPFLAG Cast(TaskBarProgressState taskBarProgressState)
public static TBPFLAG Cast(TaskBarProgressState taskBarProgressState)
{
return taskBarProgressState switch
{
TaskBarProgressState.Indeterminate => ShObjIdl.TBPFLAG.TBPF_INDETERMINATE,
TaskBarProgressState.Error => ShObjIdl.TBPFLAG.TBPF_ERROR,
TaskBarProgressState.Paused => ShObjIdl.TBPFLAG.TBPF_PAUSED,
TaskBarProgressState.Normal => ShObjIdl.TBPFLAG.TBPF_NORMAL,
_ => Wpf.Ui.Interop.ShObjIdl.TBPFLAG.TBPF_NOPROGRESS,
TaskBarProgressState.Indeterminate => TBPFLAG.TBPF_INDETERMINATE,
TaskBarProgressState.Error => TBPFLAG.TBPF_ERROR,
TaskBarProgressState.Paused => TBPFLAG.TBPF_PAUSED,
TaskBarProgressState.Normal => TBPFLAG.TBPF_NORMAL,
_ => TBPFLAG.TBPF_NOPROGRESS,
};
}
}
}
2 changes: 2 additions & 0 deletions src/Wpf.Ui/NativeMethods.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ GetSystemMetrics
IsWindow
DwmSetWindowAttribute
DwmGetWindowAttribute
ITaskbarList4
TaskbarList
DWM_SYSTEMBACKDROP_TYPE
DWM_WINDOW_CORNER_PREFERENCE
DWMWA_COLOR_DEFAULT
Expand Down
2 changes: 1 addition & 1 deletion src/Wpf.Ui/Wpf.Ui.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<UseWPF>true</UseWPF>
<LangVersion>preview</LangVersion>
<EnableWindowsTargeting>true</EnableWindowsTargeting>
<PolySharpExcludeGeneratedTypes>System.Runtime.CompilerServices.OverloadResolutionPriorityAttribute</PolySharpExcludeGeneratedTypes>
<PolySharpExcludeGeneratedTypes>System.Runtime.CompilerServices.OverloadResolutionPriorityAttribute;System.Diagnostics.CodeAnalysis.UnscopedRefAttribute</PolySharpExcludeGeneratedTypes>
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CsWin32 also adds these types, so these need to be excluded.

</PropertyGroup>

<ItemGroup>
Expand Down