简体   繁体   English

确定Powerpoint是否处于演示模式

[英]Determine whether Powerpoint is in Presentation mode or not

I have written a program that pops up and plays a Sound when a interval has elapsed that the user can set by himself. 我编写了一个程序,当用户可以自己设置一个间隔时,它会弹出并播放声音。

Now I want it to stay silent when Powerpoint is running in presentation mode and the interval elapses, so the program won't appear at the top of the screen and playing the sound when doing presentations with an external audience. 现在,我想让Powerpoint在演示文稿模式下运行并且间隔过去时保持静音,这样在与外部观众进行演示时该程序就不会出现在屏幕顶部并播放声音。

The used PowerPoint versions are 07/10/13 (12.0/14.0/15.0) I couldnt find any way to determine if the presentation mode is running or not. 使用的PowerPoint版本是13/10/13(12.0 / 14.0 / 15.0),我找不到确定演示模式是否正在运行的任何方法。

This program is no PowerPoint addin or something like that just a normal WPF desktop application. 该程序不是PowerPoint插件,也不是普通的WPF桌面应用程序。

Sorry if that looks a bit greedy to answer my own question, but i think this answer will help someone with the same problem: 抱歉,如果回答我自己的问题看起来有点贪心,但我认为此答案将对遇到相同问题的人有所帮助:

Simply add the COM reference called "Microsoft PowerPoint 15.0 Object Libary" - it appears in the reference list as "Microsoft.Office.Interop.PowerPoint" 只需添加名为“ Microsoft PowerPoint 15.0对象库”的COM引用-它在引用列表中显示为“ Microsoft.Office.Interop.PowerPoint”

The following code tests for running Presentations and was tested working for versions 2007/10/13 (12.0/14.0/15.0): 以下代码测试了用于运行Presentation的代码,并经过测试可用于版本2007/10/13(12.0 / 14.0 / 15.0):

var PPT = new Microsoft.Office.Interop.PowerPoint.Application();

if (PPT.SlideShowWindows.Count > 0)
{ //a PowerPoint Presentation mode is currently running}
else 
{//there is no PowerPoint Presentation mode running}

EDIT: 编辑:

Some error reports have shown that just doing it the above way can cause an exception if PowerPoint is not running at all or when the presentation mode is not active, so I modified the code a little bit: 一些错误报告表明,如果PowerPoint根本不运行或演示模式未处于活动状态,则仅通过上述方法进行操作会导致异常,因此我对代码进行了一些修改:

private bool IsPPTPresentationRunning()
{
    Process[] prozesse = Process.GetProcesses();
    foreach (Process p in prozesse)
    {//searches for a running PowerPoint process
        if (p.ProcessName == "POWERPNT")
        {
            try
            {
                Microsoft.Office.Interop.PowerPoint.Application PPT = 
                new Microsoft.Office.Interop.PowerPoint.Application();
                if (PPT.SlideShowWindows.Count > 0)
                 return true; 
                else
                 return false; 
            }
            //Catches any exception that seems to get thrown when
            // powerpoint is not in Presentation mode
            catch (Exception) 
            {
                return false;
            }
        }
    }
    return false;
}

可能对您有帮助...“如何自动控制PowerPoint幻灯片” https://code.msdn.microsoft.com/office/How-to-Automate-control-23cd2a8f

You can detect if any other program (not only PowerPoint) is running full screen or not. 您可以检测是否有其他程序(不仅是PowerPoint)正在全屏运行。 Here is the answer that exactly what you want https://stackoverflow.com/a/3744720/1977363 这正是您想要的答案https://stackoverflow.com/a/3744720/1977363

Visit the below link. 访问以下链接。 I think it will help 我认为这会有所帮助

Detect if Full Screen mode is on 检测全屏模式是否打开

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM