'Fonction API pour trouver la fenetre Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long 'Fonction API pour envoyer un message à la fenetre trouvée Private Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long Const WM_CLOSE = &H10 Private Sub Form_Load() Me.Visible = False Timer1.Interval = 1000 End Sub Private Sub Timer1_Timer() Fermer_Fenetre "Calculatrice" End Sub Private Sub Fermer_Fenetre(titre As String) Dim WinWnd As Long ' Recherche de la fenêtre WinWnd = FindWindow(vbNullString, titre) If WinWnd = 0 Then Exit Sub ' Fermeture de la fenêtre PostMessage WinWnd, WM_CLOSE, 0&, 0& End Sub
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre question'Dans une form avec une lixtbox(list1) (prévoir large) 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 GetWindowTextLength Lib "user32" Alias "GetWindowTextLengthA" (ByVal hwnd 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 Declare Function EnumWindows Lib "user32" (ByVal lpEnumFunc As Long, ByVal lParam As Long) As Boolean Public Function EnumWindowsProc(ByVal hwnd As Long, ByVal lParam As Long) As Boolean Dim TitreFenetre As String, LongueurTitre As Long Dim ClassName As String ' Récupération de la longueur du titre LongueurTitre = GetWindowTextLength(hwnd) ' Création buffer TitreFenetre = Space(LongueurTitre) ' Récup du titre GetWindowText hwnd, TitreFenetre, LongueurTitre + 1 ' Création buffer ClassName = Space(256) ' Récup du nom de classe de la fenetre Call GetClassName(hwnd, ClassName, Len(ClassName)) If TitreFenetre <> "" Then Form1.List1.AddItem "TITRE " & TitreFenetre & " : CLASSE " & Split(ClassName, Chr(0))(0) End If ' On continue l'énumeration EnumWindowsProc = True End Function Private Sub Form_Load() EnumWindows AddressOf EnumWindowsProc, ByVal 0& End Sub