From b1513ca587f82357afce94cd6b5b4d5fe0800d1f Mon Sep 17 00:00:00 2001 From: CJKmkp <2564608840@qq.com> Date: Sat, 21 Feb 2026 15:23:42 +0800 Subject: [PATCH] =?UTF-8?q?improve:PPT=E5=A2=A8=E8=BF=B9=E7=AE=A1=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Ink Canvas/MainWindow.xaml.cs | 32 ------------ Ink Canvas/MainWindow_cs/MW_PPT.cs | 82 +++++++++++++----------------- 2 files changed, 35 insertions(+), 79 deletions(-) diff --git a/Ink Canvas/MainWindow.xaml.cs b/Ink Canvas/MainWindow.xaml.cs index 3019f05b..1e38efcd 100644 --- a/Ink Canvas/MainWindow.xaml.cs +++ b/Ink Canvas/MainWindow.xaml.cs @@ -2802,38 +2802,6 @@ namespace Ink_Canvas private IntPtr KeyboardHookProc(int nCode, IntPtr wParam, IntPtr lParam) { - if (nCode >= 0) - { - if (Settings.Advanced.IsNoFocusMode && - BtnPPTSlideShowEnd.Visibility == Visibility.Visible && - currentMode == 0) - { - KBDLLHOOKSTRUCT hookStruct = (KBDLLHOOKSTRUCT)Marshal.PtrToStructure(lParam, typeof(KBDLLHOOKSTRUCT)); - uint vkCode = hookStruct.vkCode; - - if (wParam == (IntPtr)WM_KEYDOWN || wParam == (IntPtr)WM_SYSKEYDOWN) - { - if (vkCode == 0x22 || vkCode == 0x28 || vkCode == 0x27 || - vkCode == 0x4E || vkCode == 0x20) - { - Dispatcher.BeginInvoke(new Action(() => - { - BtnPPTSlidesDown_Click(null, null); - }), DispatcherPriority.Normal); - return (IntPtr)1; - } - else if (vkCode == 0x21 || vkCode == 0x26 || vkCode == 0x25 || - vkCode == 0x50) - { - Dispatcher.BeginInvoke(new Action(() => - { - BtnPPTSlidesUp_Click(null, null); - }), DispatcherPriority.Normal); - return (IntPtr)1; - } - } - } - } return CallNextHookEx(_keyboardHookId, nCode, wParam, lParam); } diff --git a/Ink Canvas/MainWindow_cs/MW_PPT.cs b/Ink Canvas/MainWindow_cs/MW_PPT.cs index a4e8a00a..fe436068 100644 --- a/Ink Canvas/MainWindow_cs/MW_PPT.cs +++ b/Ink Canvas/MainWindow_cs/MW_PPT.cs @@ -948,67 +948,55 @@ namespace Ink_Canvas if (currentSlide == _previousSlideID) return; - lock (_slideSwitchLock) - { - if (currentSlide == _currentSlideShowPosition) return; - if (_isProcessingSlideSwitch) return; - _isProcessingSlideSwitch = true; - } - - int prev = _currentSlideShowPosition; + int prev = _previousSlideID; Application.Current.Dispatcher.Invoke(() => { - try + var ms = new MemoryStream(); + inkCanvas.Strokes.Save(ms); + ms.Position = 0; + if (_memoryStreams.ContainsKey(prev)) + _memoryStreams[prev]?.Dispose(); + _memoryStreams[prev] = ms; + + ClearStrokes(true); + timeMachine.ClearStrokeHistory(); + + _currentSlideShowPosition = currentSlide; + _singlePPTInkManager?.LockInkForSlide(currentSlide); + _pptUIManager?.UpdateCurrentSlideNumber(currentSlide, totalSlides); + + if (_memoryStreams.ContainsKey(currentSlide) && _memoryStreams[currentSlide] != null) { - if (inkCanvas.Strokes.Count > 0 && prev > 0 && prev != currentSlide) + byte[] bytes = _memoryStreams[currentSlide].ToArray(); + int loadingPage = currentSlide; + Task.Run(() => { - var ms = new MemoryStream(); - inkCanvas.Strokes.Save(ms); - ms.Position = 0; - if (_memoryStreams.ContainsKey(prev)) - _memoryStreams[prev]?.Dispose(); - _memoryStreams[prev] = ms; - } - - ClearStrokes(true); - timeMachine.ClearStrokeHistory(); - - // 从内存流加载新页墨迹(无文件I/O) - try - { - if (_memoryStreams.ContainsKey(currentSlide) && _memoryStreams[currentSlide] != null) + try { - _memoryStreams[currentSlide].Position = 0; - inkCanvas.Strokes.Add(new StrokeCollection(_memoryStreams[currentSlide])); + return new StrokeCollection(new MemoryStream(bytes)); } - } - catch (Exception ex) + catch (Exception ex) + { + LogHelper.WriteLogToFile($"从内存流加载第 {loadingPage} 页墨迹失败: {ex}", LogHelper.LogType.Warning); + return null; + } + }).ContinueWith(t => { - LogHelper.WriteLogToFile($"从内存流加载第 {currentSlide} 页墨迹失败: {ex}", LogHelper.LogType.Warning); - } - - _singlePPTInkManager?.LockInkForSlide(currentSlide); - _pptUIManager?.UpdateCurrentSlideNumber(currentSlide, totalSlides); - } - finally - { - _currentSlideShowPosition = currentSlide; - _previousSlideID = currentSlide; - lock (_slideSwitchLock) - { - _isProcessingSlideSwitch = false; - } + if (t.IsFaulted || t.Result == null) return; + Application.Current.Dispatcher.Invoke(() => + { + if (_currentSlideShowPosition != loadingPage) return; + inkCanvas.Strokes.Add(t.Result); + }); + }); } }); + _previousSlideID = currentSlide; } catch (Exception ex) { LogHelper.WriteLogToFile($"处理幻灯片切换事件失败: {ex}", LogHelper.LogType.Error); - lock (_slideSwitchLock) - { - _isProcessingSlideSwitch = false; - } } }