Avatar of SniperCode Sheva
SniperCode Sheva
 asked on

How to get the title of a presentation of a powerpoint app C#

Hello experts,
My idea is that when I create a presentation a button will be created automatically and when I close it, the button must be removed so I need to get the title of the presentation do you have any idea ?
Here is what I did:
 
using Powerpoint = Microsoft.Office.Interop.PowerPoint;      
Powerpoint.Application wdApp = new Powerpoint.Application();
    string oldCaption = wdApp.Application.Caption ;
    string guid = Guid.NewGuid().ToString();
    //set caption to random value
    wdApp.Application.Caption = guid;
    //create a presentation
    PresentationpptPresentation=wdApp.Presentations.Add(Microsoft.Office.Core.MsoTriState.msoTrue);
    //make sure app is visible:
    wdApp.Visible = true;
    //find random value to get process id
    //here I need to get the title of the presentation
    int processId = GetProcessIdByWindowTitle(guid);

    //reset caption
    wdApp.Application.Caption = oldCaption;

    //create a dictionary
    Dictionary<int, Button> mapping = new Dictionary<int, button>();
    //add mapping
    mapping.Add(new KeyValuePair<int, Button>(processId, deleteButton));







    //found this online:
    /// <summary>
    /// Returns the name of that process given by that title
    /// </summary>
    /// <param name="AppId">Int32MaxValue re
    public static int GetProcessIdByWindowTitle(string AppId)
    {
       Process[] P_CESSES = Process.GetProcesses();
       for (int p_count = 0; p_count < P_CESSES.Length; p_count++)
       {
            if (P_CESSES[p_count].MainWindowTitle.Equals(AppId))
            {
                        return P_CESSES[p_count].Id;
            }
       }

        return Int32.MaxValue;
    }

Open in new window

Microsoft PowerPointMicrosoft OfficeC#

Avatar of undefined
Last Comment
Anastasia D. Gavanas

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Anastasia D. Gavanas

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Anastasia D. Gavanas

Solution provided works
Your help has saved me hundreds of hours of internet surfing.
fblack61