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 Const GW_CHILD = 5 Private Const GW_HWNDNEXT As Long = 2 Public Function HwndFenetre(ByVal Texte As String) As Long ' Recherche le handle de la première fenêtre contenant ' le Texte dans le titre Dim Titre As String, hWnd As Long, r As Long Dim i As Integer ' Handle du bureau hWnd = GetDesktopWindow() ' Cherche la première fenêtre lui appartenant hWnd = GetWindow(hWnd, GW_CHILD) Do While hWnd <> 0 ' Récupère le nom de la fenêtre For i = 1 To 255 Titre += " " Next i r = GetWindowText(hWnd, Titre, 255) Titre = Left(Titre, r) ' Terminé si le nom correspond If UCase(Titre) Like UCase("*" & Texte & "*") Then HwndFenetre = hWnd Exit Do End If ' Sinon, cherche la fenêtre suivante hWnd = GetWindow(hWnd, GW_HWNDNEXT) Loop End Function