Précédent   Forum des professionnels en informatique > Logiciels > Microsoft Office > Excel > Contribuez
Contribuez Placez ici vos codes, sources, trucs et astuces que vous souhaitez partager avec les membres du club.
Partagez cette discussion sur d'autres réseaux sociaux : Viadeo Twitter Google Facebook Digg Delicious MySpace Yahoo
Réponse Proposer ce sujet en actualité
 
Outils de la discussion
Publicité
'
Vieux 20/02/2008, 11h50   #1
Expert Confirmé Sénior

 
Avatar de cafeine
 
Inscription : juin 2002
Messages : 3 882
Détails du profil
Informations forums :
Inscription : juin 2002
Messages : 3 882
Points : 4 500
Points : 4 500
Par défaut [FAQ][API] fermer des windows par une classe ou un nom génériques

Permet d'énumérer des windows et de les fermer s'ils correspondent à la recherche générique de titre ou de classe.

exemple d'utilisation :
fermer toutes les fenêtres Internet Explorer
Code :
findandkillwindows 0,"*","IEFrame"
fermer tous les notepad
Code :
findandkillwindows 0, "*Bloc-note*","*"
Code :
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
Option Explicit
 
Private Declare Function GetDesktopWindow Lib "user32" () As Long
 
Private Declare Function GetWindow Lib "user32" _
  (ByVal hWnd As Long, _
   ByVal wCmd As Long) As Long
 
Private Declare Function GetWindowText Lib "user32" _
   Alias "GetWindowTextA" _
  (ByVal hWnd As Long, _
   ByVal lpString As String, _
   ByVal cch As Long) As Long
 
Private Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hWnd As Long, _
    ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
 
Private Declare Function GetClassName Lib "user32" _
   Alias "GetClassNameA" _
  (ByVal hWnd As Long, _
   ByVal lpClassName As String, _
   ByVal nMaxCount As Long) As Long
 
Private Const GW_HWNDNEXT = 2
Private Const GW_CHILD = 5
Private Const WM_CLOSE = &H10
 
Public Sub FindAndKillWindows(ByVal hWndStart As Long, _
                              ByVal WindowText As String, _
                              ByVal ClassName As String)
 
   Dim hWnd As Long
   Dim sWindowText As String
   Dim sClassname As String
   Dim r As Long
 
   Static level As Integer
 
 
   If level = 0 Then
      If hWndStart = 0 Then hWndStart = GetDesktopWindow()
   End If
 
   level = level + 1
 
   hWnd = GetWindow(hWndStart, GW_CHILD)
 
   Do Until hWnd = 0
 
      FindAndKillWindows hWnd, WindowText, ClassName
 
      sWindowText = Space$(255)
      r = GetWindowText(hWnd, sWindowText, 255)
      sWindowText = Left(sWindowText, r)
 
      sClassname = Space$(255)
      r = GetClassName(hWnd, sClassname, 255)
      sClassname = Left(sClassname, r)
 
      If (sWindowText Like WindowText) And _
         (sClassname Like ClassName) Then
        Debug.Print "Fermeture de " & hWnd, "titre : " & sWindowText, "class : " & sClassname
         ' Ferme le window
         FermeUnWindow hWnd
 
      End If
 
      hWnd = GetWindow(hWnd, GW_HWNDNEXT)
 
   Loop
 
   level = level - 1
 
End Sub
 
 
Private Sub FermeUnWindow(ByVal hWnd As Long)
 
    PostMessage hWnd, WM_CLOSE, 0, 0 'ferme un window
 
End Sub
__________________
Ne mettez pas "Problème" dans vos titres, par définition derrière toute question se cache un problème

Développez une application de gestion des comptes bancaires dans Access de A à Z
Déjà 12 tutoriels, le dernier en date : Comment faire un TextBox auto-extensible dans un formulaire ?


cafeine est déconnecté   Envoyer un message privé Réponse avec citation 00
Réponse Proposer ce sujet en actualité
Outils de la discussion



Fuseau horaire GMT +2. Il est actuellement 03h20.


 
 
 
 
Partenaires

Hébergement Web