检测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();
        }
    }
}
相关推荐
王up1654 小时前
反转课堂从作业开始!PPT内置作业管理工具,课代表扛活、学生自评,老师终于能闲下来啦!
powerpoint·教育·作业管理·班级管理
是筱倩阿5 小时前
Python 编程实现 PPT 批量转图片(PNG/JPG)
python·opencv·powerpoint
kyriewen119 小时前
你的前端滤镜慢得像PPT?用Rust+WebAssembly,一秒处理4K图
开发语言·前端·javascript·设计模式·rust·ecmascript·powerpoint
Mr数据杨20 小时前
【Codex】用整合教案模块串联PPT文案与课堂教学方案
django·powerpoint·codex·项目开发
AI小技巧1 天前
码农必备!PPT制作神器网站大揭秘
powerpoint
小e说说1 天前
2026 最强PPT制作工具大盘点,全类型覆盖,建议收藏
powerpoint
小t说说1 天前
6款实用PPT生成工具
powerpoint
小e说说1 天前
吐血实测!十款PPT生成工具大PK,谁才是效率之王?
powerpoint
开开心心就好2 天前
自动分类存储PPT素材的实用工具
科技·游戏·智能手机·电脑·powerpoint·sublime text·phpstorm