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 |
Partager