improve:PPT联动模块

This commit is contained in:
2026-01-17 17:44:46 +08:00
parent c0453ea1fc
commit a46f8b36a0
+17 -75
View File
@@ -371,29 +371,7 @@ namespace Ink_Canvas.Helpers
if (IsInSlideShow) if (IsInSlideShow)
{ {
object slideShowWindows = null; OnSlideShowBegin(PPTApplication.SlideShowWindows[1]);
object slideShowWindow = null;
try
{
slideShowWindows = PPTApplication.SlideShowWindows;
if (slideShowWindows != null)
{
dynamic ssw = slideShowWindows;
if (ssw.Count > 0)
{
slideShowWindow = ssw[1];
if (slideShowWindow != null)
{
OnSlideShowBegin(slideShowWindow as SlideShowWindow);
}
}
}
}
finally
{
SafeReleaseComObject(slideShowWindow);
SafeReleaseComObject(slideShowWindows);
}
} }
else if (CurrentPresentation != null) else if (CurrentPresentation != null)
{ {
@@ -1080,55 +1058,35 @@ namespace Ink_Canvas.Helpers
/// </summary> /// </summary>
public Presentation GetCurrentActivePresentation() public Presentation GetCurrentActivePresentation()
{ {
object slideShowWindows = null;
object slideShowWindow = null;
object view = null;
object slide = null;
object activeWindow = null;
object presentation = null;
try try
{ {
if (!IsConnected || PPTApplication == null) return null; if (!IsConnected || PPTApplication == null) return null;
if (!Marshal.IsComObject(PPTApplication)) return null; if (!Marshal.IsComObject(PPTApplication)) return null;
if (IsInSlideShow) if (IsInSlideShow && PPTApplication.SlideShowWindows.Count > 0)
{ {
slideShowWindows = PPTApplication.SlideShowWindows; try
if (slideShowWindows != null)
{ {
dynamic ssw = slideShowWindows; var slideShowWindow = PPTApplication.SlideShowWindows[1];
if (ssw.Count > 0) if (slideShowWindow?.View != null)
{ {
slideShowWindow = ssw[1]; return (Presentation)slideShowWindow.View.Slide.Parent;
if (slideShowWindow != null)
{
dynamic sswObj = slideShowWindow;
view = sswObj.View;
if (view != null)
{
dynamic viewObj = view;
slide = viewObj.Slide;
if (slide != null)
{
dynamic slideObj = slide;
presentation = slideObj.Parent;
return presentation as Presentation;
}
}
}
} }
} }
catch (COMException comEx)
{
var hr = (uint)comEx.HResult;
if (hr == 0x80048240)
{
return null;
}
throw;
}
} }
activeWindow = PPTApplication.ActiveWindow; if (PPTApplication.ActiveWindow?.Presentation != null)
if (activeWindow != null)
{ {
dynamic aw = activeWindow; return PPTApplication.ActiveWindow.Presentation;
presentation = aw.Presentation;
if (presentation != null)
{
return presentation as Presentation;
}
} }
return CurrentPresentation; return CurrentPresentation;
@@ -1140,10 +1098,6 @@ namespace Ink_Canvas.Helpers
{ {
DisconnectFromPPT(); DisconnectFromPPT();
} }
if (hr == 0x80048240)
{
return null;
}
LogHelper.WriteLogToFile($"获取当前活跃演示文稿失败: {comEx.Message}", LogHelper.LogType.Warning); LogHelper.WriteLogToFile($"获取当前活跃演示文稿失败: {comEx.Message}", LogHelper.LogType.Warning);
return CurrentPresentation; return CurrentPresentation;
} }
@@ -1152,18 +1106,6 @@ namespace Ink_Canvas.Helpers
LogHelper.WriteLogToFile($"获取当前活跃演示文稿失败: {ex}", LogHelper.LogType.Error); LogHelper.WriteLogToFile($"获取当前活跃演示文稿失败: {ex}", LogHelper.LogType.Error);
return CurrentPresentation; return CurrentPresentation;
} }
finally
{
if (presentation != null && !ReferenceEquals(presentation, CurrentPresentation))
{
SafeReleaseComObject(presentation);
}
SafeReleaseComObject(slide);
SafeReleaseComObject(view);
SafeReleaseComObject(slideShowWindow);
SafeReleaseComObject(slideShowWindows);
SafeReleaseComObject(activeWindow);
}
} }
/// <summary> /// <summary>