Quelle fenêtre active ?

Résolu
elyote666 Messages postés 30 Date d'inscription lundi 17 mai 2004 Statut Membre Dernière intervention 4 octobre 2007 - 19 mars 2005 à 00:08
elyote666 Messages postés 30 Date d'inscription lundi 17 mai 2004 Statut Membre Dernière intervention 4 octobre 2007 - 19 mars 2005 à 01:29
Salut à tous !
Comment faire pour que mon programme détecte quelle fenêtre à le focus
dans Windows.
Merci de vos réponses !

5 réponses

Gobillot Messages postés 3140 Date d'inscription vendredi 14 mai 2004 Statut Membre Dernière intervention 11 mars 2019 34
19 mars 2005 à 00:35
Dim Hwnd As Long
Hwnd = GetForegroundWindow

ça renvoie le Handle de la fenêtre active et avec le Handle tu peux avoir tout le reste.

Daniel
3
Gobillot Messages postés 3140 Date d'inscription vendredi 14 mai 2004 Statut Membre Dernière intervention 11 mars 2019 34
19 mars 2005 à 00:17
Private
Declare
Function GetForegroundWindow
Lib
"user32" ()
As
Long

Daniel
0
elyote666 Messages postés 30 Date d'inscription lundi 17 mai 2004 Statut Membre Dernière intervention 4 octobre 2007
19 mars 2005 à 00:29
merci ! pour la réponse ,mais une nouvelle question :
La variable long que la Function renvoie, elle correspond à quoi ?
0
Gobillot Messages postés 3140 Date d'inscription vendredi 14 mai 2004 Statut Membre Dernière intervention 11 mars 2019 34
19 mars 2005 à 01:00
pour exemple pour avoir le nom de la fenêtre active:

Private Declare Function GetForegroundWindow Lib "user32" () As Long
Private Declare Function GetWindowTextLength Lib "user32" Alias "GetWindowTextLengthA" (ByVal Hwnd 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

Dim Hwnd As Long
Dim Lg As Long
Dim Nom As String

Hwnd = GetForegroundWindow
Lg = GetWindowTextLength(Hwnd)
Nom = Space$(Lg + 1)
GetWindowText Hwnd, Nom, Lg + 1
Nom = Left$(Nom, Lg)
MsgBox Nom

Daniel
0

Vous n’avez pas trouvé la réponse que vous recherchez ?

Posez votre question
elyote666 Messages postés 30 Date d'inscription lundi 17 mai 2004 Statut Membre Dernière intervention 4 octobre 2007
19 mars 2005 à 01:29
merci bocoup !
0
Rejoignez-nous