Bonjour
Je cherche à fermer toutes les fenetres d'une application ouvertes. Par
exemple fermer d'un click, toutes les fenetres Internet Explorer qui sont
ouverte.
Cette action est irreversible, confirmez la suppression du commentaire ?
Signaler le commentaire
Veuillez sélectionner un problème
Nudité
Violence
Harcèlement
Fraude
Vente illégale
Discours haineux
Terrorisme
Autre
Jacques93
Bonjour Irénée A. Irénée A. a écrit :
Bonjour Je cherche à fermer toutes les fenetres d'une application ouvertes. Par exemple fermer d'un click, toutes les fenetres Internet Explorer qui sont ouverte.
A adapter. Le code qui suit énumère et ferme les fenêtres filles du bureau. Si tu ne veux fermer que les fenêtres IE, tu peux ajouter un test :
Private Declare Function GetClassName Lib "user32" _ Alias "GetClassNameA" (ByVal hwnd As Long, _ ByVal lpClassName As String, ByVal nMaxCount As Long) As Long
[...]
Dim ClassName as String
ClassName = Space (255) GetClassName hwnd, ClassName, Len (ClassName) If UCase(Left(Txt, 7)) = "IEFRAME" Then ...
Private Declare Function EnumWindows Lib "user32" _ (ByVal lpEnumFunc As Long, ByVal lParam 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 SendMessage Lib "user32" _ Alias "SendMessageA" (ByVal hWnd As Long, _ ByVal wMsg As Long, _ ByVal wParam As Long, _ lParam As Any) As Long
Private Sub Command1_Click() Dim lResult As Long Dim i As Integer Dim Titre As String Dim Rep As String
ReDim hWnds(0) EnumWindows AddressOf EnumTopWindows, 0 For i = LBound(hWnds) To UBound(hWnds) - 1 If hWnds(i) <> Me.hWnd Then Titre = Space(255) GetWindowText hWnds(i), Titre, Len(Titre) Rep = MsgBox("Fermeture de : " & Titre & vbCrLf & hWnds(i), _ vbYesNo Or vbQuestion) If Rep = vbYes Then SendMessage hWnds(i), WM_SYSCOMMAND, SC_CLOSE, 0& End If End If Next i End Sub '-------------------------------------------------------------------------
Private Declare Function GetParent Lib "user32" _ (ByVal hWnd As Long) As Long Private Declare Function IsWindowVisible Lib "user32" _ (ByVal hWnd As Long) As Long Private Declare Function GetWindowLong Lib "user32" _ Alias "GetWindowLongA" (ByVal hWnd As Long, _ ByVal nIndex As Long) As Long Private Const GWL_STYLE = (-16) Private Const WS_CHILD = &H40000000 Private Const WS_POPUP = &H80000000
Public hWnds() As Long
Public Function EnumTopWindows(ByVal hWnd As Long, _ ByVal lParam As Long) As Boolean Dim ws As Long
If GetParent(hWnd) = 0 And IsWindowVisible(hWnd) <> 0 Then ws = GetWindowLong(hWnd, GWL_STYLE) If (ws And WS_CHILD) = 0 And (ws And WS_POPUP) = 0 Then hWnds(UBound(hWnds)) = hWnd ReDim Preserve hWnds(UBound(hWnds) + 1) End If End If EnumTopWindows = True End Function
-- Cordialement,
Jacques.
Bonjour Irénée A.
Irénée A. a écrit :
Bonjour
Je cherche à fermer toutes les fenetres d'une application ouvertes. Par
exemple fermer d'un click, toutes les fenetres Internet Explorer qui sont
ouverte.
A adapter. Le code qui suit énumère et ferme les fenêtres filles du
bureau. Si tu ne veux fermer que les fenêtres IE, tu peux ajouter un test :
Private Declare Function GetClassName Lib "user32" _
Alias "GetClassNameA" (ByVal hwnd As Long, _
ByVal lpClassName As String, ByVal nMaxCount As Long) As Long
[...]
Dim ClassName as String
ClassName = Space (255)
GetClassName hwnd, ClassName, Len (ClassName)
If UCase(Left(Txt, 7)) = "IEFRAME" Then ...
Private Declare Function EnumWindows Lib "user32" _
(ByVal lpEnumFunc As Long, ByVal lParam 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 SendMessage Lib "user32" _
Alias "SendMessageA" (ByVal hWnd As Long, _
ByVal wMsg As Long, _
ByVal wParam As Long, _
lParam As Any) As Long
Private Sub Command1_Click()
Dim lResult As Long
Dim i As Integer
Dim Titre As String
Dim Rep As String
ReDim hWnds(0)
EnumWindows AddressOf EnumTopWindows, 0
For i = LBound(hWnds) To UBound(hWnds) - 1
If hWnds(i) <> Me.hWnd Then
Titre = Space(255)
GetWindowText hWnds(i), Titre, Len(Titre)
Rep = MsgBox("Fermeture de : " & Titre & vbCrLf & hWnds(i), _
vbYesNo Or vbQuestion)
If Rep = vbYes Then
SendMessage hWnds(i), WM_SYSCOMMAND, SC_CLOSE, 0&
End If
End If
Next i
End Sub
'-------------------------------------------------------------------------
Private Declare Function GetParent Lib "user32" _
(ByVal hWnd As Long) As Long
Private Declare Function IsWindowVisible Lib "user32" _
(ByVal hWnd As Long) As Long
Private Declare Function GetWindowLong Lib "user32" _
Alias "GetWindowLongA" (ByVal hWnd As Long, _
ByVal nIndex As Long) As Long
Private Const GWL_STYLE = (-16)
Private Const WS_CHILD = &H40000000
Private Const WS_POPUP = &H80000000
Public hWnds() As Long
Public Function EnumTopWindows(ByVal hWnd As Long, _
ByVal lParam As Long) As Boolean
Dim ws As Long
If GetParent(hWnd) = 0 And IsWindowVisible(hWnd) <> 0 Then
ws = GetWindowLong(hWnd, GWL_STYLE)
If (ws And WS_CHILD) = 0 And (ws And WS_POPUP) = 0 Then
hWnds(UBound(hWnds)) = hWnd
ReDim Preserve hWnds(UBound(hWnds) + 1)
End If
End If
EnumTopWindows = True
End Function
Bonjour Je cherche à fermer toutes les fenetres d'une application ouvertes. Par exemple fermer d'un click, toutes les fenetres Internet Explorer qui sont ouverte.
A adapter. Le code qui suit énumère et ferme les fenêtres filles du bureau. Si tu ne veux fermer que les fenêtres IE, tu peux ajouter un test :
Private Declare Function GetClassName Lib "user32" _ Alias "GetClassNameA" (ByVal hwnd As Long, _ ByVal lpClassName As String, ByVal nMaxCount As Long) As Long
[...]
Dim ClassName as String
ClassName = Space (255) GetClassName hwnd, ClassName, Len (ClassName) If UCase(Left(Txt, 7)) = "IEFRAME" Then ...
Private Declare Function EnumWindows Lib "user32" _ (ByVal lpEnumFunc As Long, ByVal lParam 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 SendMessage Lib "user32" _ Alias "SendMessageA" (ByVal hWnd As Long, _ ByVal wMsg As Long, _ ByVal wParam As Long, _ lParam As Any) As Long
Private Sub Command1_Click() Dim lResult As Long Dim i As Integer Dim Titre As String Dim Rep As String
ReDim hWnds(0) EnumWindows AddressOf EnumTopWindows, 0 For i = LBound(hWnds) To UBound(hWnds) - 1 If hWnds(i) <> Me.hWnd Then Titre = Space(255) GetWindowText hWnds(i), Titre, Len(Titre) Rep = MsgBox("Fermeture de : " & Titre & vbCrLf & hWnds(i), _ vbYesNo Or vbQuestion) If Rep = vbYes Then SendMessage hWnds(i), WM_SYSCOMMAND, SC_CLOSE, 0& End If End If Next i End Sub '-------------------------------------------------------------------------
Private Declare Function GetParent Lib "user32" _ (ByVal hWnd As Long) As Long Private Declare Function IsWindowVisible Lib "user32" _ (ByVal hWnd As Long) As Long Private Declare Function GetWindowLong Lib "user32" _ Alias "GetWindowLongA" (ByVal hWnd As Long, _ ByVal nIndex As Long) As Long Private Const GWL_STYLE = (-16) Private Const WS_CHILD = &H40000000 Private Const WS_POPUP = &H80000000
Public hWnds() As Long
Public Function EnumTopWindows(ByVal hWnd As Long, _ ByVal lParam As Long) As Boolean Dim ws As Long
If GetParent(hWnd) = 0 And IsWindowVisible(hWnd) <> 0 Then ws = GetWindowLong(hWnd, GWL_STYLE) If (ws And WS_CHILD) = 0 And (ws And WS_POPUP) = 0 Then hWnds(UBound(hWnds)) = hWnd ReDim Preserve hWnds(UBound(hWnds) + 1) End If End If EnumTopWindows = True End Function
-- Cordialement,
Jacques.
Irénée A.
Merci Jacque Je vais essayer de me débrouiller avec ça.
"Jacques93" a écrit :
Bonjour Irénée A. Irénée A. a écrit : > Bonjour > Je cherche à fermer toutes les fenetres d'une application ouvertes. Par > exemple fermer d'un click, toutes les fenetres Internet Explorer qui sont > ouverte. >
A adapter. Le code qui suit énumère et ferme les fenêtres filles du bureau. Si tu ne veux fermer que les fenêtres IE, tu peux ajouter un test :
Private Declare Function GetClassName Lib "user32" _ Alias "GetClassNameA" (ByVal hwnd As Long, _ ByVal lpClassName As String, ByVal nMaxCount As Long) As Long
[...]
Dim ClassName as String
ClassName = Space (255) GetClassName hwnd, ClassName, Len (ClassName) If UCase(Left(Txt, 7)) = "IEFRAME" Then ...
Private Declare Function EnumWindows Lib "user32" _ (ByVal lpEnumFunc As Long, ByVal lParam 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 SendMessage Lib "user32" _ Alias "SendMessageA" (ByVal hWnd As Long, _ ByVal wMsg As Long, _ ByVal wParam As Long, _ lParam As Any) As Long
Private Sub Command1_Click() Dim lResult As Long Dim i As Integer Dim Titre As String Dim Rep As String
ReDim hWnds(0) EnumWindows AddressOf EnumTopWindows, 0 For i = LBound(hWnds) To UBound(hWnds) - 1 If hWnds(i) <> Me.hWnd Then Titre = Space(255) GetWindowText hWnds(i), Titre, Len(Titre) Rep = MsgBox("Fermeture de : " & Titre & vbCrLf & hWnds(i), _ vbYesNo Or vbQuestion) If Rep = vbYes Then SendMessage hWnds(i), WM_SYSCOMMAND, SC_CLOSE, 0& End If End If Next i End Sub '-------------------------------------------------------------------------
Private Declare Function GetParent Lib "user32" _ (ByVal hWnd As Long) As Long Private Declare Function IsWindowVisible Lib "user32" _ (ByVal hWnd As Long) As Long Private Declare Function GetWindowLong Lib "user32" _ Alias "GetWindowLongA" (ByVal hWnd As Long, _ ByVal nIndex As Long) As Long Private Const GWL_STYLE = (-16) Private Const WS_CHILD = &H40000000 Private Const WS_POPUP = &H80000000
Public hWnds() As Long
Public Function EnumTopWindows(ByVal hWnd As Long, _ ByVal lParam As Long) As Boolean Dim ws As Long
If GetParent(hWnd) = 0 And IsWindowVisible(hWnd) <> 0 Then ws = GetWindowLong(hWnd, GWL_STYLE) If (ws And WS_CHILD) = 0 And (ws And WS_POPUP) = 0 Then hWnds(UBound(hWnds)) = hWnd ReDim Preserve hWnds(UBound(hWnds) + 1) End If End If EnumTopWindows = True End Function
-- Cordialement,
Jacques.
Merci Jacque
Je vais essayer de me débrouiller avec ça.
"Jacques93" a écrit :
Bonjour Irénée A.
Irénée A. a écrit :
> Bonjour
> Je cherche à fermer toutes les fenetres d'une application ouvertes. Par
> exemple fermer d'un click, toutes les fenetres Internet Explorer qui sont
> ouverte.
>
A adapter. Le code qui suit énumère et ferme les fenêtres filles du
bureau. Si tu ne veux fermer que les fenêtres IE, tu peux ajouter un test :
Private Declare Function GetClassName Lib "user32" _
Alias "GetClassNameA" (ByVal hwnd As Long, _
ByVal lpClassName As String, ByVal nMaxCount As Long) As Long
[...]
Dim ClassName as String
ClassName = Space (255)
GetClassName hwnd, ClassName, Len (ClassName)
If UCase(Left(Txt, 7)) = "IEFRAME" Then ...
Private Declare Function EnumWindows Lib "user32" _
(ByVal lpEnumFunc As Long, ByVal lParam 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 SendMessage Lib "user32" _
Alias "SendMessageA" (ByVal hWnd As Long, _
ByVal wMsg As Long, _
ByVal wParam As Long, _
lParam As Any) As Long
Private Sub Command1_Click()
Dim lResult As Long
Dim i As Integer
Dim Titre As String
Dim Rep As String
ReDim hWnds(0)
EnumWindows AddressOf EnumTopWindows, 0
For i = LBound(hWnds) To UBound(hWnds) - 1
If hWnds(i) <> Me.hWnd Then
Titre = Space(255)
GetWindowText hWnds(i), Titre, Len(Titre)
Rep = MsgBox("Fermeture de : " & Titre & vbCrLf & hWnds(i), _
vbYesNo Or vbQuestion)
If Rep = vbYes Then
SendMessage hWnds(i), WM_SYSCOMMAND, SC_CLOSE, 0&
End If
End If
Next i
End Sub
'-------------------------------------------------------------------------
Private Declare Function GetParent Lib "user32" _
(ByVal hWnd As Long) As Long
Private Declare Function IsWindowVisible Lib "user32" _
(ByVal hWnd As Long) As Long
Private Declare Function GetWindowLong Lib "user32" _
Alias "GetWindowLongA" (ByVal hWnd As Long, _
ByVal nIndex As Long) As Long
Private Const GWL_STYLE = (-16)
Private Const WS_CHILD = &H40000000
Private Const WS_POPUP = &H80000000
Public hWnds() As Long
Public Function EnumTopWindows(ByVal hWnd As Long, _
ByVal lParam As Long) As Boolean
Dim ws As Long
If GetParent(hWnd) = 0 And IsWindowVisible(hWnd) <> 0 Then
ws = GetWindowLong(hWnd, GWL_STYLE)
If (ws And WS_CHILD) = 0 And (ws And WS_POPUP) = 0 Then
hWnds(UBound(hWnds)) = hWnd
ReDim Preserve hWnds(UBound(hWnds) + 1)
End If
End If
EnumTopWindows = True
End Function
Merci Jacque Je vais essayer de me débrouiller avec ça.
"Jacques93" a écrit :
Bonjour Irénée A. Irénée A. a écrit : > Bonjour > Je cherche à fermer toutes les fenetres d'une application ouvertes. Par > exemple fermer d'un click, toutes les fenetres Internet Explorer qui sont > ouverte. >
A adapter. Le code qui suit énumère et ferme les fenêtres filles du bureau. Si tu ne veux fermer que les fenêtres IE, tu peux ajouter un test :
Private Declare Function GetClassName Lib "user32" _ Alias "GetClassNameA" (ByVal hwnd As Long, _ ByVal lpClassName As String, ByVal nMaxCount As Long) As Long
[...]
Dim ClassName as String
ClassName = Space (255) GetClassName hwnd, ClassName, Len (ClassName) If UCase(Left(Txt, 7)) = "IEFRAME" Then ...
Private Declare Function EnumWindows Lib "user32" _ (ByVal lpEnumFunc As Long, ByVal lParam 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 SendMessage Lib "user32" _ Alias "SendMessageA" (ByVal hWnd As Long, _ ByVal wMsg As Long, _ ByVal wParam As Long, _ lParam As Any) As Long
Private Sub Command1_Click() Dim lResult As Long Dim i As Integer Dim Titre As String Dim Rep As String
ReDim hWnds(0) EnumWindows AddressOf EnumTopWindows, 0 For i = LBound(hWnds) To UBound(hWnds) - 1 If hWnds(i) <> Me.hWnd Then Titre = Space(255) GetWindowText hWnds(i), Titre, Len(Titre) Rep = MsgBox("Fermeture de : " & Titre & vbCrLf & hWnds(i), _ vbYesNo Or vbQuestion) If Rep = vbYes Then SendMessage hWnds(i), WM_SYSCOMMAND, SC_CLOSE, 0& End If End If Next i End Sub '-------------------------------------------------------------------------
Private Declare Function GetParent Lib "user32" _ (ByVal hWnd As Long) As Long Private Declare Function IsWindowVisible Lib "user32" _ (ByVal hWnd As Long) As Long Private Declare Function GetWindowLong Lib "user32" _ Alias "GetWindowLongA" (ByVal hWnd As Long, _ ByVal nIndex As Long) As Long Private Const GWL_STYLE = (-16) Private Const WS_CHILD = &H40000000 Private Const WS_POPUP = &H80000000
Public hWnds() As Long
Public Function EnumTopWindows(ByVal hWnd As Long, _ ByVal lParam As Long) As Boolean Dim ws As Long
If GetParent(hWnd) = 0 And IsWindowVisible(hWnd) <> 0 Then ws = GetWindowLong(hWnd, GWL_STYLE) If (ws And WS_CHILD) = 0 And (ws And WS_POPUP) = 0 Then hWnds(UBound(hWnds)) = hWnd ReDim Preserve hWnds(UBound(hWnds) + 1) End If End If EnumTopWindows = True End Function