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;
+8 -4
View File
@@ -107,7 +107,8 @@ namespace Ink_Canvas.Helpers
{
// 将墨迹添加到 inkCanvas 的父容器中,而不是 inkCanvas.Children
// 这样可以避免坐标系统问题
if (_mainWindow.inkCanvas.Parent is Panel parent)
var parent = _mainWindow.inkCanvas.Parent as Panel;
if (parent != null)
{
parent.Children.Add(strokeVisual);
}
@@ -153,7 +154,8 @@ namespace Ink_Canvas.Helpers
try
{
// 从父容器中移除墨迹
if (_mainWindow.inkCanvas?.Parent is Panel parent && parent.Children.Contains(visual))
var parent = _mainWindow.inkCanvas?.Parent as Panel;
if (parent != null && parent.Children.Contains(visual))
{
parent.Children.Remove(visual);
}
@@ -511,7 +513,8 @@ namespace Ink_Canvas.Helpers
originalVisual.Visibility = Visibility.Hidden;
var segments = new List<UIElement>();
if (!(_mainWindow.inkCanvas?.Parent is Panel parent))
var parent = _mainWindow.inkCanvas?.Parent as Panel;
if (parent == null)
{
// 如果父容器不是Panel,直接使用InkCanvas
parent = null; // 稍后会检查并使用InkCanvas.Children
@@ -867,7 +870,8 @@ namespace Ink_Canvas.Helpers
try
{
// 从父容器中移除墨迹
if (_mainWindow.inkCanvas?.Parent is Panel parent && parent.Children.Contains(visual))
var parent = _mainWindow.inkCanvas?.Parent as Panel;
if (parent != null && parent.Children.Contains(visual))
{
parent.Children.Remove(visual);
}
@@ -313,7 +313,8 @@ namespace Ink_Canvas.Helpers.Plugins.BuiltIn
var buttonElement = _launcherButton.Element;
// 查找浮动栏
if (!(mainWindow.FindName("StackPanelFloatingBar") is Panel floatingBar))
var floatingBar = mainWindow.FindName("StackPanelFloatingBar") as Panel;
if (floatingBar == null)
{
// 如果直接查找失败,则尝试遍历可视树查找
Panel floatingBarPanelFromTree = null;
@@ -404,7 +405,8 @@ namespace Ink_Canvas.Helpers.Plugins.BuiltIn
var buttonElement = _launcherButton.Element;
// 查找浮动栏
if (!(mainWindow.FindName("StackPanelFloatingBar") is Panel floatingBar))
var floatingBar = mainWindow.FindName("StackPanelFloatingBar") as Panel;
if (floatingBar == null)
{
// 如果直接查找失败,则尝试遍历可视树查找
Panel floatingBarPanelFromTree = null;
+2 -1
View File
@@ -25,7 +25,8 @@ namespace Ink_Canvas.Helpers
return Screen.PrimaryScreen;
// 获取窗口的句柄
if (!(PresentationSource.FromVisual(window) is HwndSource hwndSource))
var hwndSource = PresentationSource.FromVisual(window) as HwndSource;
if (hwndSource == null)
return Screen.PrimaryScreen;
// 获取窗口在屏幕上的位置
+4 -2
View File
@@ -61,7 +61,8 @@ namespace Ink_Canvas.Helpers
{
if (windowTitle.Length == windowName.Length)
{
if (window.GetCurrentPattern(WindowPattern.Pattern) is WindowPattern windowPattern)
WindowPattern windowPattern = window.GetCurrentPattern(WindowPattern.Pattern) as WindowPattern;
if (windowPattern != null)
{
return true;
}
@@ -69,7 +70,8 @@ namespace Ink_Canvas.Helpers
}
else
{
if (window.GetCurrentPattern(WindowPattern.Pattern) is WindowPattern windowPattern)
WindowPattern windowPattern = window.GetCurrentPattern(WindowPattern.Pattern) as WindowPattern;
if (windowPattern != null)
{
return true;
}