简体   繁体   中英

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.

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.

This program is no PowerPoint addin or something like that just a normal WPF desktop application.

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"

The following code tests for running Presentations and was tested working for versions 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:

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. Here is the answer that exactly what you want https://stackoverflow.com/a/3744720/1977363

Visit the below link. I think it will help

Detect if Full Screen mode is on

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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