检测PowerPoint是否进入了PPT全屏放映模式

豆包给了一段代码,可以检测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();
        }
    }
}
相关推荐
死磕音视频6 天前
PowerPoint Copilot 入门:用 Interactive Slide 做出可点击讲解页
powerpoint·copilot·演示文稿·交互幻灯片
FinelyYang6 天前
uniapp使用kkfileview在线预览ppt,excel,word,pdf类型文件
pdf·uni-app·powerpoint
zhippt_10146 天前
截图、课件图、设计稿怎么变成可编辑PPT?图转PPT实测
powerpoint
ms365copilot7 天前
Copilot 笔记本,研究内容整理完变成 PowerPoint
powerpoint·copilot
jcqcool8 天前
win11下ppt内置的Flash 动画还直接能动起来:我做了一个 兼容播放小工具
powerpoint
zhippt_10148 天前
只剩截图没有源文件?图转PPT把图片还原成可编辑幻灯片
前端·人工智能·powerpoint
zhippt_10149 天前
教师做课件太耗时?AI生成PPT工具与图转PPT实测梳理
人工智能·html·powerpoint
zhippt_101410 天前
汇报总结PPT怎么做更快?5款AI生成PPT工具实测横评
人工智能·powerpoint
copilot中国版11 天前
PPT 新技能「创建项目启动会」:项目还没开会,Copilot 先把启动会 PPT 搭好了
powerpoint·copilot
●VON12 天前
芯稿 MarkDeck:在 HarmonyOS PC 上用 Markdown 生成可编辑 PPT
华为·powerpoint·harmonyos