From cca65635a62cd3c8252c407f5a364f854b14920d Mon Sep 17 00:00:00 2001 From: Lightczx <1686188646@qq.com> Date: Tue, 17 Oct 2023 14:52:38 +0800 Subject: [PATCH] investigate into CoreWindow --- .../Snap.Hutao.Win32/UnsafePInvoke.cs | 37 +++++++++++++++++++ .../Core/Windowing/WindowController.cs | 3 ++ 2 files changed, 40 insertions(+) create mode 100644 src/Snap.Hutao/Snap.Hutao.Win32/UnsafePInvoke.cs diff --git a/src/Snap.Hutao/Snap.Hutao.Win32/UnsafePInvoke.cs b/src/Snap.Hutao/Snap.Hutao.Win32/UnsafePInvoke.cs new file mode 100644 index 00000000..98b9cab0 --- /dev/null +++ b/src/Snap.Hutao/Snap.Hutao.Win32/UnsafePInvoke.cs @@ -0,0 +1,37 @@ +// Copyright (c) DGP Studio. All rights reserved. +// Licensed under the MIT license. + + +using System; +using System.Runtime.InteropServices; +using Windows.UI.Core; +using Windows.Win32.Foundation; + +namespace Snap.Hutao.Win32; + +internal static class UnsafePInvoke +{ + private enum WINDOW_TYPE : uint + { + IMMERSIVE_BODY, + IMMERSIVE_DOCK, + IMMERSIVE_HOSTED, + IMMERSIVE_TEST, + IMMERSIVE_BODY_ACTIVE, + IMMERSIVE_DOCK_ACTIVE, + NOT_IMMERSIVE, + } + + [DllImport("Windows.UI.dll", CharSet = CharSet.None, EntryPoint = "#1500", ExactSpelling = false, SetLastError = true)] + [DefaultDllImportSearchPaths(DllImportSearchPath.System32)] + private static extern HRESULT PrivateCreateCoreWindow(WINDOW_TYPE WindowType, PWSTR pWindowTitle, int x, int y, uint uWidth, uint uHeight, uint dwAttributes, HWND hOwnerWindow, Guid riid, out nint ppv); + + public static unsafe CoreWindow PrivateCreateCoreWindow(string title, HWND hOwnerWindow) + { + fixed(char* pTitle = title) + { + PrivateCreateCoreWindow(WINDOW_TYPE.NOT_IMMERSIVE, pTitle, 0, 0, 400, 400, 0, hOwnerWindow, typeof(ICoreWindow).GUID, out nint thisPtr); + return CoreWindow.FromAbi(thisPtr); + } + } +} \ No newline at end of file diff --git a/src/Snap.Hutao/Snap.Hutao/Core/Windowing/WindowController.cs b/src/Snap.Hutao/Snap.Hutao/Core/Windowing/WindowController.cs index 946fc5bc..4a71d89e 100644 --- a/src/Snap.Hutao/Snap.Hutao/Core/Windowing/WindowController.cs +++ b/src/Snap.Hutao/Snap.Hutao/Core/Windowing/WindowController.cs @@ -8,9 +8,11 @@ using Microsoft.UI.Xaml; using Microsoft.UI.Xaml.Media; using Snap.Hutao.Core.Setting; using Snap.Hutao.Service; +using Snap.Hutao.Win32; using System.IO; using Windows.Graphics; using Windows.UI; +using Windows.UI.Core; using Windows.Win32.Foundation; using Windows.Win32.Graphics.Dwm; using Windows.Win32.UI.WindowsAndMessaging; @@ -55,6 +57,7 @@ internal sealed class WindowController ExtendsContentIntoTitleBar(); RecoverOrInitWindowSize(); + CoreWindow coreWindow = UnsafePInvoke.PrivateCreateCoreWindow("Snap Hutao CoreWindow", options.Hwnd); UpdateImmersiveDarkMode(options.TitleBar, default!); // appWindow.Show(true);