From 67e3d5110674e29e1b89229499bc27b4ac55f2cf Mon Sep 17 00:00:00 2001
From: CJKmkp <2564608840@qq.com>
Date: Sat, 6 Sep 2025 13:58:49 +0800
Subject: [PATCH] =?UTF-8?q?improve:=E7=AA=97=E5=8F=A3=E7=BD=AE=E9=A1=B6?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
Ink Canvas/Helpers/PPTManager.cs | 56 +++++++++++++++-
Ink Canvas/Helpers/PPTUIManager.cs | 37 +++++++++--
.../MainWindow_cs/MW_FloatingBarIcons.cs | 57 ++++++++++++++--
Ink Canvas/MainWindow_cs/MW_Settings.cs | 22 +++++--
Ink Canvas/Windows/CountdownTimerWindow.xaml | 66 +++++--------------
Ink Canvas/Windows/OperatingGuideWindow.xaml | 2 +-
Ink Canvas/Windows/RandWindow.xaml.cs | 65 ++++++++++++++++++
7 files changed, 232 insertions(+), 73 deletions(-)
diff --git a/Ink Canvas/Helpers/PPTManager.cs b/Ink Canvas/Helpers/PPTManager.cs
index d8a03bd4..48fc4c70 100644
--- a/Ink Canvas/Helpers/PPTManager.cs
+++ b/Ink Canvas/Helpers/PPTManager.cs
@@ -70,7 +70,32 @@ namespace Ink_Canvas.Helpers
try
{
if (PPTApplication == null || !Marshal.IsComObject(PPTApplication)) return false;
- return PPTApplication.SlideShowWindows?.Count > 0;
+
+ // 检查是否有放映窗口
+ var slideShowWindows = PPTApplication.SlideShowWindows;
+ if (slideShowWindows == null || slideShowWindows.Count == 0) return false;
+
+ // 验证放映窗口是否真正有效
+ try
+ {
+ var slideShowWindow = slideShowWindows[1];
+ if (slideShowWindow == null) return false;
+
+ // 尝试访问放映窗口的属性来验证其有效性
+ var _ = slideShowWindow.View;
+ return true;
+ }
+ catch (COMException comEx)
+ {
+ var hr = (uint)comEx.HResult;
+ if (hr == 0x8001010E || hr == 0x80004005)
+ {
+ // COM对象已失效,触发断开连接
+ DisconnectFromPPT();
+ }
+ LogHelper.WriteLogToFile($"验证PPT放映窗口失败: {comEx.Message} (HR: 0x{hr:X8})", LogHelper.LogType.Warning);
+ return false;
+ }
}
catch (COMException comEx)
{
@@ -80,10 +105,12 @@ namespace Ink_Canvas.Helpers
// COM对象已失效,触发断开连接
DisconnectFromPPT();
}
+ LogHelper.WriteLogToFile($"检查PPT放映状态失败: {comEx.Message} (HR: 0x{hr:X8})", LogHelper.LogType.Warning);
return false;
}
- catch
+ catch (Exception ex)
{
+ LogHelper.WriteLogToFile($"检查PPT放映状态时发生意外错误: {ex}", LogHelper.LogType.Warning);
return false;
}
}
@@ -452,7 +479,30 @@ namespace Ink_Canvas.Helpers
{
CurrentPresentation = activePresentation;
CurrentSlides = CurrentPresentation.Slides;
- SlidesCount = CurrentSlides.Count;
+
+ // 验证页数读取是否成功
+ try
+ {
+ var slideCount = CurrentSlides.Count;
+ if (slideCount > 0)
+ {
+ SlidesCount = slideCount;
+ LogHelper.WriteLogToFile($"成功读取PPT页数: {slideCount}", LogHelper.LogType.Trace);
+ }
+ else
+ {
+ // 页数为0,可能是空演示文稿或读取失败
+ SlidesCount = 0;
+ LogHelper.WriteLogToFile("PPT演示文稿页数为0,可能为空演示文稿", LogHelper.LogType.Warning);
+ }
+ }
+ catch (COMException comEx)
+ {
+ // 页数读取失败
+ var hr = (uint)comEx.HResult;
+ SlidesCount = 0;
+ LogHelper.WriteLogToFile($"读取PPT页数失败: {comEx.Message} (HR: 0x{hr:X8})", LogHelper.LogType.Warning);
+ }
// 获取当前幻灯片
try
diff --git a/Ink Canvas/Helpers/PPTUIManager.cs b/Ink Canvas/Helpers/PPTUIManager.cs
index b022a29b..1e29affc 100644
--- a/Ink Canvas/Helpers/PPTUIManager.cs
+++ b/Ink Canvas/Helpers/PPTUIManager.cs
@@ -81,10 +81,19 @@ namespace Ink_Canvas.Helpers
_mainWindow.BtnPPTSlideShow.Visibility = Visibility.Collapsed;
_mainWindow.BtnPPTSlideShowEnd.Visibility = Visibility.Visible;
+ // 只有在页数有效时才更新页码显示
if (currentSlide > 0 && totalSlides > 0)
{
_mainWindow.PPTBtnPageNow.Text = currentSlide.ToString();
_mainWindow.PPTBtnPageTotal.Text = $"/ {totalSlides}";
+ LogHelper.WriteLogToFile($"更新PPT页码显示: {currentSlide}/{totalSlides}", LogHelper.LogType.Trace);
+ }
+ else
+ {
+ // 页数无效时清空页码显示
+ _mainWindow.PPTBtnPageNow.Text = "?";
+ _mainWindow.PPTBtnPageTotal.Text = "/ ?";
+ LogHelper.WriteLogToFile($"PPT页数无效,清空页码显示: 当前页={currentSlide}, 总页数={totalSlides}", LogHelper.LogType.Warning);
}
UpdateNavigationPanelsVisibility();
@@ -113,8 +122,20 @@ namespace Ink_Canvas.Helpers
{
try
{
- _mainWindow.PPTBtnPageNow.Text = currentSlide.ToString();
- _mainWindow.PPTBtnPageTotal.Text = $"/ {totalSlides}";
+ // 只有在页数有效时才更新页码显示
+ if (currentSlide > 0 && totalSlides > 0)
+ {
+ _mainWindow.PPTBtnPageNow.Text = currentSlide.ToString();
+ _mainWindow.PPTBtnPageTotal.Text = $"/ {totalSlides}";
+ LogHelper.WriteLogToFile($"更新PPT页码显示: {currentSlide}/{totalSlides}", LogHelper.LogType.Trace);
+ }
+ else
+ {
+ // 页数无效时清空页码显示
+ _mainWindow.PPTBtnPageNow.Text = "?";
+ _mainWindow.PPTBtnPageTotal.Text = "/ ?";
+ LogHelper.WriteLogToFile($"PPT页数无效,清空页码显示: 当前页={currentSlide}, 总页数={totalSlides}", LogHelper.LogType.Warning);
+ }
}
catch (Exception ex)
{
@@ -156,17 +177,25 @@ namespace Ink_Canvas.Helpers
try
{
// 检查是否应该显示PPT按钮
- // 不仅要检查按钮设置,还要确保确实在PPT放映模式下
+ // 不仅要检查按钮设置,还要确保确实在PPT放映模式下且页数有效
+ bool isInSlideShow = _mainWindow.PPTManager?.IsInSlideShow == true;
+ int slidesCount = _mainWindow.PPTManager?.SlidesCount ?? 0;
+ bool hasValidPageCount = slidesCount > 0;
+
bool shouldShowButtons = ShowPPTButton &&
_mainWindow.BtnPPTSlideShowEnd.Visibility == Visibility.Visible &&
- _mainWindow.PPTManager?.IsInSlideShow == true;
+ isInSlideShow &&
+ hasValidPageCount;
if (!shouldShowButtons)
{
HideAllNavigationPanels();
+ LogHelper.WriteLogToFile($"隐藏PPT导航面板 - 放映状态: {isInSlideShow}, 页数: {slidesCount}, 按钮设置: {ShowPPTButton}", LogHelper.LogType.Trace);
return;
}
+ LogHelper.WriteLogToFile($"显示PPT导航面板 - 放映状态: {isInSlideShow}, 页数: {slidesCount}", LogHelper.LogType.Trace);
+
// 设置侧边按钮位置
_mainWindow.LeftSidePanelForPPTNavigation.Margin = new Thickness(0, 0, 0, PPTLSButtonPosition * 2);
_mainWindow.RightSidePanelForPPTNavigation.Margin = new Thickness(0, 0, 0, PPTRSButtonPosition * 2);
diff --git a/Ink Canvas/MainWindow_cs/MW_FloatingBarIcons.cs b/Ink Canvas/MainWindow_cs/MW_FloatingBarIcons.cs
index 3b976f54..80b400cb 100644
--- a/Ink Canvas/MainWindow_cs/MW_FloatingBarIcons.cs
+++ b/Ink Canvas/MainWindow_cs/MW_FloatingBarIcons.cs
@@ -2,6 +2,7 @@ using Ink_Canvas.Helpers;
using iNKORE.UI.WPF.Modern;
using System;
using System.Diagnostics;
+using System.Runtime.InteropServices;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
@@ -13,6 +14,7 @@ using System.Windows.Interop;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Media.Imaging;
+using System.Windows.Threading;
using Application = System.Windows.Application;
using Button = System.Windows.Controls.Button;
using Cursors = System.Windows.Input.Cursors;
@@ -946,10 +948,45 @@ namespace Ink_Canvas
var randWindow = new RandWindow(Settings);
randWindow.Show();
- // 确保窗口显示后立即置顶
- randWindow.Activate();
- randWindow.Topmost = true;
- randWindow.Focus();
+
+ // 使用延迟确保窗口完全显示后再强制置顶
+ randWindow.Dispatcher.BeginInvoke(new Action(() =>
+ {
+ try
+ {
+ // 强制激活窗口
+ randWindow.Activate();
+ randWindow.Focus();
+
+ // 设置置顶
+ randWindow.Topmost = true;
+
+ // 使用Win32 API强制置顶
+ var hwnd = new WindowInteropHelper(randWindow).Handle;
+ if (hwnd != IntPtr.Zero)
+ {
+ const int WS_EX_TOPMOST = 0x00000008;
+ const int GWL_EXSTYLE = -20;
+ const int SWP_NOMOVE = 0x0002;
+ const int SWP_NOSIZE = 0x0001;
+ const int SWP_SHOWWINDOW = 0x0040;
+ const int SWP_NOOWNERZORDER = 0x0200;
+ var HWND_TOPMOST = new IntPtr(-1);
+
+ // 设置窗口样式为置顶
+ int exStyle = GetWindowLong(hwnd, GWL_EXSTYLE);
+ SetWindowLong(hwnd, GWL_EXSTYLE, exStyle | WS_EX_TOPMOST);
+
+ // 强制置顶
+ SetWindowPos(hwnd, HWND_TOPMOST, 0, 0, 0, 0,
+ SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW | SWP_NOOWNERZORDER);
+ }
+ }
+ catch (Exception ex)
+ {
+ LogHelper.WriteLogToFile($"强制置顶RandWindow失败: {ex.Message}", LogHelper.LogType.Error);
+ }
+ }), DispatcherPriority.Loaded);
}
public void CheckEraserTypeTab()
@@ -1346,7 +1383,9 @@ namespace Ink_Canvas
var toolbarHeight = ForegroundWindowInfo.GetTaskbarHeight(screen, dpiScaleY);
// 计算浮动栏位置,考虑快捷调色盘的显示状态
- double floatingBarWidth = ViewboxFloatingBar.ActualWidth * ViewboxFloatingBarScaleTransform.ScaleX;
+ // 确保获取到正确的浮动栏宽度,如果ActualWidth为0则使用DesiredSize
+ double baseWidth = ViewboxFloatingBar.ActualWidth > 0 ? ViewboxFloatingBar.ActualWidth : ViewboxFloatingBar.DesiredSize.Width;
+ double floatingBarWidth = baseWidth * ViewboxFloatingBarScaleTransform.ScaleX;
// 如果快捷调色盘显示,确保有足够空间
if ((QuickColorPalettePanel != null && QuickColorPalettePanel.Visibility == Visibility.Visible) ||
@@ -1467,7 +1506,9 @@ namespace Ink_Canvas
var toolbarHeight = ForegroundWindowInfo.GetTaskbarHeight(screen, dpiScaleY);
// 计算浮动栏位置,考虑快捷调色盘的显示状态
- double floatingBarWidth = ViewboxFloatingBar.ActualWidth * ViewboxFloatingBarScaleTransform.ScaleX;
+ // 确保获取到正确的浮动栏宽度,如果ActualWidth为0则使用DesiredSize
+ double baseWidth = ViewboxFloatingBar.ActualWidth > 0 ? ViewboxFloatingBar.ActualWidth : ViewboxFloatingBar.DesiredSize.Width;
+ double floatingBarWidth = baseWidth * ViewboxFloatingBarScaleTransform.ScaleX;
// 如果快捷调色盘显示,确保有足够空间
if ((QuickColorPalettePanel != null && QuickColorPalettePanel.Visibility == Visibility.Visible) ||
@@ -1549,7 +1590,9 @@ namespace Ink_Canvas
var toolbarHeight = ForegroundWindowInfo.GetTaskbarHeight(screen, dpiScaleY);
// 计算浮动栏位置,考虑快捷调色盘的显示状态
- double floatingBarWidth = ViewboxFloatingBar.ActualWidth * ViewboxFloatingBarScaleTransform.ScaleX;
+ // 确保获取到正确的浮动栏宽度,如果ActualWidth为0则使用DesiredSize
+ double baseWidth = ViewboxFloatingBar.ActualWidth > 0 ? ViewboxFloatingBar.ActualWidth : ViewboxFloatingBar.DesiredSize.Width;
+ double floatingBarWidth = baseWidth * ViewboxFloatingBarScaleTransform.ScaleX;
// 如果快捷调色盘显示,确保有足够空间
if ((QuickColorPalettePanel != null && QuickColorPalettePanel.Visibility == Visibility.Visible) ||
diff --git a/Ink Canvas/MainWindow_cs/MW_Settings.cs b/Ink Canvas/MainWindow_cs/MW_Settings.cs
index 1afb5732..eafd870b 100644
--- a/Ink Canvas/MainWindow_cs/MW_Settings.cs
+++ b/Ink Canvas/MainWindow_cs/MW_Settings.cs
@@ -197,14 +197,22 @@ namespace Ink_Canvas
val > 0.5 && val < 1.25 ? val : val <= 0.5 ? 0.5 : val >= 1.25 ? 1.25 : 1;
ViewboxFloatingBarScaleTransform.ScaleY =
val > 0.5 && val < 1.25 ? val : val <= 0.5 ? 0.5 : val >= 1.25 ? 1.25 : 1;
- // auto align - 新增:只在屏幕模式下重新计算浮动栏位置
- if (currentMode == 0)
+
+ // 等待UI更新后再重新计算浮动栏位置,确保居中计算准确
+ Dispatcher.BeginInvoke(new Action(() =>
{
- if (BtnPPTSlideShowEnd.Visibility == Visibility.Visible)
- ViewboxFloatingBarMarginAnimation(60);
- else
- ViewboxFloatingBarMarginAnimation(100, true);
- }
+ // 强制更新布局以确保ActualWidth正确
+ ViewboxFloatingBar.UpdateLayout();
+
+ // auto align - 新增:只在屏幕模式下重新计算浮动栏位置
+ if (currentMode == 0)
+ {
+ if (BtnPPTSlideShowEnd.Visibility == Visibility.Visible)
+ ViewboxFloatingBarMarginAnimation(60);
+ else
+ ViewboxFloatingBarMarginAnimation(100, true);
+ }
+ }), DispatcherPriority.Render);
}
private void ViewboxFloatingBarOpacityValueSlider_ValueChanged(object sender, RoutedEventArgs e)
diff --git a/Ink Canvas/Windows/CountdownTimerWindow.xaml b/Ink Canvas/Windows/CountdownTimerWindow.xaml
index 8c785503..37372edb 100644
--- a/Ink Canvas/Windows/CountdownTimerWindow.xaml
+++ b/Ink Canvas/Windows/CountdownTimerWindow.xaml
@@ -24,23 +24,11 @@
Margin="0,0,0,0" Visibility="Collapsed"
Foreground="#5B5D5F"
Text="00" FontSize="26"/>
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+