豆包给了一段代码,可以检测PowerPoint是否进入了PPT全屏放映模式,VS2022,winform4.8
cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Microsoft.Office.Interop.PowerPoint;
using Microsoft.Office.Core;
namespace PowerPointTool
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
/// <summary>
/// 检测 PowerPoint 是否处于全屏放映模式
/// </summary>
public static bool IsPowerPointFullScreen()
{
Microsoft.Office.Interop.PowerPoint.Application pptApp = null;
try
{
// 获取正在运行的 PowerPoint 实例
pptApp = (Microsoft.Office.Interop.PowerPoint.Application)System.Runtime.InteropServices.Marshal.GetActiveObject("PowerPoint.Application");
if (pptApp.SlideShowWindows.Count > 0)
{
foreach (SlideShowWindow window in pptApp.SlideShowWindows)
{
// 判断是否全屏
if (window.IsFullScreen == MsoTriState.msoTrue)
return true;
}
}
return false;
}
catch
{
// 没有运行 PowerPoint
return false;
}
finally
{
// 释放 COM 对象,避免进程残留
if (pptApp != null)
{
System.Runtime.InteropServices.Marshal.ReleaseComObject(pptApp);
}
}
}
private void button1_Click(object sender, EventArgs e)
{
label1.Text = IsPowerPointFullScreen().ToString();
}
}
}