Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
0x5bfa committed Aug 3, 2024
1 parent 4bdcdfa commit 52a03d6
Showing 1 changed file with 10 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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
{
Expand Down Expand Up @@ -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,
Expand All @@ -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),
Expand Down

0 comments on commit 52a03d6

Please sign in to comment.