lolpop
Messages postés211Date d'inscriptionmercredi 4 août 2004StatutMembreDernière intervention18 octobre 2010
-
4 sept. 2006 à 18:42
lolpop
Messages postés211Date d'inscriptionmercredi 4 août 2004StatutMembreDernière intervention18 octobre 2010
-
4 sept. 2006 à 21:47
Re,
il y a pas longtemp je suis venu vous demandé de l'aide pour arriver a fermer une fenetre en connaissant un morceau de son nom et pas le nom de la fenetre entière.
Grace a vos réponce et en fouinnant sur le net, j'ai réussi a faire un petit code qui fonctionne avec certaines conditions et je n'arrive pas a résoudre le problème.
Le code ferme toutes les fenetres qui contiennent le mot rechercher, SAUF lorsque c'est une fenètre Internet Explorer ou un explorateur Windows, hors j'ai besoin de se code pour fermer une fenetre du navigateur qui contiendra le mot recherché.
Avec Firefox cela marche mais par avec Internet Explorer.
Voici le module:
' Déclaration des API utilisées
Public Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" _
(ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Public Declare Function EnumWindows Lib "user32" _
(ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long
Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, _
ByVal wParam As Long, _
lParam As Any) As Long
Public Const WM_CLOSE = &H10
Public Function GetWindowsList()
Dim lgRep As Long
lgRep = EnumWindows(AddressOf EnumWindowsProc, 0)
End Function
Public Function EnumWindowsProc(ByVal lgHwnd As Long, ByVal lgParam As Long) As Long
Dim stTmp As String, lgTmp As Long, lgRet As Long, chercher As String
chercher = "Mozilla"
stTmp = Space$(120)
lgTmp = 119
' On récupère le titre de la fenêtre à partir du handle
lgRet = GetWindowText(lgHwnd, stTmp, lgTmp)
stTmp = Replace(stTmp, Chr$(0), vbNullString)
If InStr(stTmp, chercher) <> 0 Then
'Ferme la fenêtre
SendMessage lgHwnd, WM_CLOSE, 0, 0
End If
EnumWindowsProc = 1
End Function
et voici le Form:
Private Sub Form_Load()
EnumWindows AddressOf EnumWindowsProc, ByVal 0&
End Sub
J'ai oublier de préciser que lors du processus j'ai un son qui est joué : c'est le son par défaut (Windows XP Ding.wav) qui est joué.
Est ce que quelqu'un a une explication a ce problème?
Merci d'avance
lolpop
Messages postés211Date d'inscriptionmercredi 4 août 2004StatutMembreDernière intervention18 octobre 2010 4 sept. 2006 à 21:47
j'ai trouvé, en utilisant :
Private Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
lolpop
Messages postés211Date d'inscriptionmercredi 4 août 2004StatutMembreDernière intervention18 octobre 2010 4 sept. 2006 à 20:55
Je viens de tester cela, mais j'ai toujours le même problème:
Public Const WM_CLOSE = &H10
Public Function EnumChildProc(ByVal hwnd As Long, ByVal lParam As Long) As Long
Dim sSave As String
'Get the windowtext length
sSave = Space$(GetWindowTextLength(hwnd) + 1)
'get the window text
GetWindowText hwnd, sSave, Len(sSave)
'remove the last Chr$(0)
sSave = Left$(sSave, Len(sSave) - 1)
If sSave <> "" Then Form1.Print sSave
If InStr(sSave, "test") <> 0 Then
'Ferme la fenêtre
SendMessage hwnd, WM_CLOSE, 0, 0
'MsgBox stTmp
End If
'continue enumeration
EnumChildProc = 1
End Function
Private Sub Form_Load()
EnumChildWindows GetDesktopWindow, AddressOf EnumChildProc, ByVal 0&
End Sub
Vous n’avez pas trouvé la réponse que vous recherchez ?