Revert "优化代码"

This reverts commit 92bb458345.
This commit is contained in:
2025-09-30 19:15:03 +08:00
parent d9e3524211
commit a9b0ac0595
16 changed files with 131 additions and 71 deletions
+6 -3
View File
@@ -30,7 +30,8 @@ namespace Ink_Canvas.Helpers
if (!(bool)window.GetValue(IsAvoidFullScreenEnabledProperty))
{
if (PresentationSource.FromVisual(window) is HwndSource hwndSource)
var hwndSource = PresentationSource.FromVisual(window) as HwndSource;
if (hwndSource != null)
{
hwndSource.AddHook(KeepInWorkingAreaHook);
window.SetValue(IsAvoidFullScreenEnabledProperty, true);
@@ -45,7 +46,8 @@ namespace Ink_Canvas.Helpers
if ((bool)window.GetValue(IsAvoidFullScreenEnabledProperty))
{
if (PresentationSource.FromVisual(window) is HwndSource hwndSource)
var hwndSource = PresentationSource.FromVisual(window) as HwndSource;
if (hwndSource != null)
{
hwndSource.RemoveHook(KeepInWorkingAreaHook);
window.ClearValue(IsAvoidFullScreenEnabledProperty);
@@ -59,7 +61,8 @@ namespace Ink_Canvas.Helpers
private static IntPtr KeepInWorkingAreaHook(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
{
// 只拦截主画布窗口的全屏(最大化)操作
if (!(HwndSource.FromHwnd(hwnd)?.RootVisual is Window window)) return IntPtr.Zero;
var window = HwndSource.FromHwnd(hwnd)?.RootVisual as Window;
if (window == null) return IntPtr.Zero;
// 这里假设主画布窗口类名为MainWindow(如有不同请调整)
if (window.GetType().Name != "MainWindow") return IntPtr.Zero;