Bonjour, je suis en train de faire une application qui permettra d'ouvrir des applications externes du genre MS Word, Notepad etc. Lorsque j'ouvre une application,un bouton est crée automatiquement dans mon application C# et lorsque je ferme l'application externe, le bouton disparait.
PS: j'ai utilisé MS Word comme application externe.
J'arrive à ouvrir , créer un bouton et supprimer le bouton pour une seule application Word.
Lorsque j'ouvre plusieurs applications, le bouton de la dernière application disparait les autres je n'arrive pas à les faire disparaitre.
Voici le code :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
try
            {
 
                Word.Application wdApp = new Word.Application();
                string oldCaption = wdApp.Application.Caption;
                string guid = Guid.NewGuid().ToString();
                //set caption to random value
                wdApp.Application.Caption = guid;
                //make sure app is visible:
                wdApp.Visible = true;
                //find random value to get process id
                int processId = GetProcessIdByWindowTitle(guid);
 
 
                //reset caption
                wdApp.Application.Caption = oldCaption;
 
 
                if( wdApp.Visible == true)
                {
 
                    deleteButton = new Microsoft.Office.Tools.Word.Controls.Button();
                    //create a dictionary
                    mapping = new Dictionary<int, Button>();
                    //add mapping
                    mapping.Add(processId, deleteButton);
                    PIC_Barre.Controls.Add(deleteButton);
 
 
 
 
                    //PIC_Barre.Controls.Add(_button);
                }
                ((Word.ApplicationEvents4_Event)wdApp).Quit += () =>
                {
 
                // remove the button corresponding to the processid
                     var method = (Action)(() =>
                PIC_Barre.Controls.Remove(mapping[processId]));
                     if (mapping[processId].InvokeRequired)
                     {
                         mapping[processId].Invoke(method);
 
                     }
                 // remove the key from the dictionary
 
                };
                Debugger.Break();
 
 
 
            }
            catch
            {
 
            }