nhervagault
Messages postés6063Date d'inscriptiondimanche 13 avril 2003StatutMembreDernière intervention15 juillet 201137 25 oct. 2005 à 21:56
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
Maintenant le problème, est que ce code m'affiche une liste avec
plein d'autre chose autre que des fenêtres, or je souhaiterai juste
lister les fenêtres actives. Comment est-ce possible ?
PS : Par fenêtre active, j'entend les fenêtres qu'on peut accéder par la barre de tâches.