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}
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;
}
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments