VBA - Savoir si une fenêtre est visible

VBA - Savoir si une fenêtre est visible - VB/VBA/VBS - Programmation

Marsh Posté le 04-01-2008 à 18:12:12    

Bonsoir et bonne année  :)  
J'ai trouvé ce code sur internet pour Savoir si une fenêtre est visible

Citation :

Public Declare Function IsWindowVisible& Lib "user32" (ByVal hwnd As Long)
 
Public Function FenetreEstVisible(hWnd As Long) As Boolean
    Dim ret As Long
    ret = IsWindowVisible(hWnd)
    FenetreEstVisible = (ret=1)
End Function
 
Exemple : If FenetreEstVisible(Me.hWnd) Then MsgBox "La fenêtre est visible" Else MsgBox "La fenêtre est invisible"


 
J'ai donc mis cela dans un module excel et rajouté ensuite :
Public Sub Essai ()
Dim FenetreEstVisible
FenetreEstVisible = "Sans titre - Bloc-notes"
If FenetreEstVisible(Me.hWnd) Then MsgBox "La fenêtre est visible" Else MsgBox "La fenêtre est invisible"
end sub
 
mais j'ai une erreur  :??:  
Pourriez vous m'aider ?


Message édité par didieraucun le 04-01-2008 à 19:47:21
Reply

Marsh Posté le 04-01-2008 à 18:12:12   

Reply

Marsh Posté le 04-01-2008 à 20:28:29    

Bonsoir,
 
Avant d'appeler l'API IsWindowVisible, il faut d'abord connaître le handle (numéro d'identification)
de la fenêtre recherchée. Cela s'effectue à l'aide de l'API FindWindow.

Code :
  1. Public Declare Function IsWindowVisible& Lib "User32" (ByVal hWnd As Long)
  2. Public Declare Function FindWindow Lib "User32" Alias "FindWindowA" _
  3. (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
  4. Public Function FenetreEstVisible(hWnd As Long) As Boolean
  5.     Dim ret As Long
  6.     ret = IsWindowVisible(hWnd)
  7.     FenetreEstVisible = (ret = 1)
  8. End Function
  9. Public Sub Essai()
  10. Dim lHandle As Long
  11. lHandle = FindWindow(vbNullString, "Sans titre - Bloc-notes" )
  12. If FenetreEstVisible(lHandle) Then MsgBox "La fenêtre est visible" Else MsgBox "La fenêtre est invisible"
  13. End Sub


wape

Reply

Marsh Posté le 05-01-2008 à 00:19:03    

Grand merci à toi Wape

Reply

Sujets relatifs:

Leave a Replay

Make sure you enter the(*)required information where indicate.HTML code is not allowed