From 52a03d65ce565916624ff4b509cc3f551f250c22 Mon Sep 17 00:00:00 2001 From: 0x5bfa <62196528+0x5bfa@users.noreply.github.com> Date: Sun, 4 Aug 2024 02:48:25 +0900 Subject: [PATCH] Update --- .../Previews/ShellPreviewViewModel.cs | 29 +++++++------------ 1 file changed, 10 insertions(+), 19 deletions(-) diff --git a/src/Files.App/ViewModels/UserControls/Previews/ShellPreviewViewModel.cs b/src/Files.App/ViewModels/UserControls/Previews/ShellPreviewViewModel.cs index b428fe72d1ab6..cf006728fb975 100644 --- a/src/Files.App/ViewModels/UserControls/Previews/ShellPreviewViewModel.cs +++ b/src/Files.App/ViewModels/UserControls/Previews/ShellPreviewViewModel.cs @@ -13,7 +13,6 @@ using Windows.Win32.Graphics.Dxgi; using Windows.Win32.Graphics.DirectComposition; using Windows.Win32.Graphics.Dwm; -using Windows.Win32.System.Registry; using Windows.Win32.UI.Shell; using Windows.Win32.UI.WindowsAndMessaging; using WinRT; @@ -26,10 +25,6 @@ namespace Files.App.ViewModels.Previews { public sealed class ShellPreviewViewModel : BasePreviewModel { - private static readonly Guid IPreviewHandlerIid = new(0x8895b1c6, 0xb41f, 0x4c1c, 0xa5, 0x62, 0x0d, 0x56, 0x42, 0x50, 0x83, 0x6f); - private static readonly Guid QueryAssociationsClsid = new(0xa07034fd, 0x6caa, 0x4954, 0xac, 0x3f, 0x97, 0xa2, 0x72, 0x16, 0xf9, 0x8a); - private static readonly Guid IQueryAssociationsIid = new(0xc46ca590, 0x3c3f, 0x11d2, 0xbe, 0xe6, 0x00, 0x00, 0xf8, 0x05, 0xca, 0x57); - PreviewHandler? currentHandler; ContentExternalOutputLink? outputLink; WNDCLASSEXW? wCls; @@ -108,9 +103,10 @@ private unsafe LRESULT WndProc(HWND hwnd, uint msg, WPARAM wParam, LPARAM lParam var clsid = FindPreviewHandlerFor(Item.FileExtension, hwnd.Value); isOfficePreview = new Guid?[] { - Guid.Parse("84F66100-FF7C-4fb4-B0C0-02CD7FB668FE"), + Guid.Parse("84F66100-FF7C-4fb4-B0C0-02CD7FB668FE"), // Guid.Parse("65235197-874B-4A07-BDC5-E65EA825B718"), - Guid.Parse("00020827-0000-0000-C000-000000000046") }.Contains(clsid); + Guid.Parse("00020827-0000-0000-C000-000000000046") + }.Contains(clsid); try { @@ -138,21 +134,18 @@ private unsafe LRESULT WndProc(HWND hwnd, uint msg, WPARAM wParam, LPARAM lParam public unsafe void LoadPreview(UIElement presenter) { var parent = MainWindow.Instance.WindowHandle; + var hInst = PInvoke.GetModuleHandle(default(PWSTR)); + var szClassName = $"{GetType().Name}-{Guid.NewGuid()}"; + var szWindowName = $"Preview"; - HINSTANCE hInst = PInvoke.GetModuleHandle(default(PWSTR)); - - string className = $"{GetType().Name}{Guid.NewGuid()}"; - - fixed (char* pszClassName = className) + fixed (char* pszClassName = szClassName) { - PWSTR pwszClassName = new(pszClassName); - wCls = new WNDCLASSEXW { cbSize = (uint)Marshal.SizeOf(typeof(WNDCLASSEXW)), lpfnWndProc = new(WndProc), hInstance = hInst, - lpszClassName = pwszClassName, + lpszClassName = pszClassName, style = 0, hIcon = default, hIconSm = default, @@ -163,14 +156,12 @@ public unsafe void LoadPreview(UIElement presenter) cbWndExtra = 0, }; - fixed (char* pszWindowName = "Preview") + fixed (char* pszWindowName = szWindowName) { - PWSTR lpwszWindowName = new(pszWindowName); - hwnd = PInvoke.CreateWindowEx( WINDOW_EX_STYLE.WS_EX_LAYERED | WINDOW_EX_STYLE.WS_EX_COMPOSITED, wCls.Value.lpszClassName, - lpwszWindowName, + pszWindowName, WINDOW_STYLE.WS_CHILD | WINDOW_STYLE.WS_CLIPSIBLINGS | WINDOW_STYLE.WS_VISIBLE, 0, 0, 0, 0, new(parent),