Réponse acceptée !
Salut
Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal
lpClassName As String, ByVal lpWindowName As String) As Long
Declare Function BringWindowToTop Lib "user32" (ByVal hwnd As Long) As Long
dans un bouton :
Private Sub Command1_Click()
Dim hNoteWnd As Long
Dim x As Long
hNoteWnd = FindWindow("Notepad", "Sans titre - Bloc-notes")
If hNoteWnd = 0 Then
'le notepad avec le titre "Sans titre - Bloc-notes" n'est pas en mémoire
x =Shell("notepad.EXE", vbNormalFocus)
Else
'il est en mémoire : on le force en avant plan
BringWindowToTop (hNoteWnd)
End If
End Sub
Sinon, tu peux utiliser GetWindow pour obtenir la liste de toutes les
fenêtres actives :
dans un module basique :
Public Const GW_HWNDFIRST = 0
Public Const GW_HWNDNEXT = 2
Declare Function GetWindow Lib "user32" Alias "GetWindow" (ByVal hwnd As
Long, ByVal wCmd As Long) As Long
Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal
hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
dans un bouton :
Private Sub Command1_Click()
Dim hWndNext As Long
Dim x As Long
Dim lpString As String * 255
Dim vLen As Long
hWndNext = GetWindow(hWnd, GW_HWNDFIRST)
If hWndNext <> 0 Then
vLen = GetWindowText (hWndNext , lpString , len(lpString ))
Debug.print Left(lpString ,vLen )
End If
do until hWndNext = 0
hWndNext = GetWindow(hWndNext, GW_HWNDNEXT)
vLen = GetWindowText (hWndNext , lpString , len(lpString ))
Debug.print Left(lpString ,vLen )
loop
End Sub
Voila un petit debut
APres a toi faire la suite.