Bonjour,
Je cherche a fermer une fenêtre d'un process dans laquelle un fichier spécifique est ouvert à l'aide du code ci dessous.
La fenêtre est bien détectée mais la fonction DestroyWindow ne fait rien. En revanche j'ai testé avec CloseWindow (minimisation de la fenêtre) et cela fonctionne très bien.
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 static void Main(string[] args) { Process[] pro = Process.GetProcessesByName("notepad"); for (int i = 0; i < pro.Count(); i++) { int PID = pro[i].Id; foreach (var handle in EnumerateProcessWindowHandles( PID)) { if (IsWindowVisible(handle)) { int length = GetWindowTextLength(handle); StringBuilder sb = new StringBuilder(length + 1); GetWindowText(handle, sb, sb.Capacity); string Windowtext = sb.ToString(); Console.WriteLine(Windowtext); if (Windowtext.Contains("LeFichier")) { bool DW = DestroyWindow(handle); } } } } }
Auriez-vous s'il vous plaît une idée?
D'avance merci.
Partager