Skip to content

Commit f09a349

Browse files
committed
add win32 api DwmSetIconicLivePreviewBitmap
1 parent 149bcc5 commit f09a349

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

src/WPFDevelopers.Shared/Core/Helpers/Win32.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System;
1+
using Standard;
2+
using System;
23
using System.Runtime.InteropServices;
34
using System.Text;
45
using System.Windows.Interop;
@@ -192,6 +193,9 @@ public static bool EnableDarkModeForWindow(HwndSource source, bool enable)
192193
[DllImport(DwmApi)]
193194
public static extern int DwmInvalidateIconicBitmaps(IntPtr hwnd);
194195

196+
[DllImport(DwmApi)]
197+
public static extern int DwmSetIconicLivePreviewBitmap(IntPtr hwnd, IntPtr hBitmap, IntPtr pptClient, DWM_SIT dwSITFlags);
198+
195199
[DllImport(User32)]
196200
public static extern bool GetWindowRect(IntPtr hWnd, out RECT lpRect);
197201

@@ -218,6 +222,7 @@ internal class WindowsMessageCodes
218222
public const int WM_NCHITTEST = 0x0084;
219223

220224
public const int WM_DWMSENDICONICTHUMBNAIL = 0x0323;
225+
public const int WM_DWMSENDICONICLIVEPREVIEWBITMAP = 0x0326;
221226
}
222227

223228
[Flags]
@@ -230,4 +235,10 @@ public enum DwmWindowAttributes : uint
230235
UseImmersiveDarkMode = 20
231236
}
232237

238+
[Flags]
239+
public enum DWM_SIT : uint
240+
{
241+
None = 0x0,
242+
DisplayFrame = 0x1
243+
}
233244
}

src/WPFDevelopers.Shared/Core/Helpers/WindowHelpers.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Diagnostics;
23
using System.Drawing;
34
using System.IO;
45
using System.Runtime.InteropServices;
@@ -89,6 +90,23 @@ public static void SetIconicThumbnail(this Window window, string imagePath)
8990

9091
handled = true;
9192
}
93+
if (msg == WindowsMessageCodes.WM_DWMSENDICONICLIVEPREVIEWBITMAP)
94+
{
95+
try
96+
{
97+
using (var bmp = new Bitmap(imagePath))
98+
{
99+
IntPtr hBitmap = bmp.GetHbitmap();
100+
Win32.DwmSetIconicLivePreviewBitmap(hwnd2, hBitmap, IntPtr.Zero, 0);
101+
Win32.DeleteObject(hBitmap);
102+
}
103+
}
104+
catch (Exception ex)
105+
{
106+
Debug.WriteLine($"LivePreview error: {ex.Message}");
107+
}
108+
handled = true;
109+
}
92110

93111
return IntPtr.Zero;
94112
}));

0 commit comments

Comments
 (0)