-
Hi,
I want to get a window handle with the FindWindow api, but the function always returns 0.
This is my code :
Private Sub Command1_Click()
Dim WindowHwnd as Long
WindowHwnd = FindWindow("#32770 (Dialog)", CLng(0)) ' it's the ie download window class name
If WindowHwnd = 0 Then
Label1.Caption = "Il n'y a pas de D/L en cours"
Else
Label1.Caption = "Il y a un D/L en cours"
End If
End Sub
Thanks
-
FindWindow will not search through child windows, use FindWindowEx.
The code below will find the "File Download" Window and close it.
Private Declare Function FindWindowEx Lib "User32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
Private Declare Function SendMessage Lib "User32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Const WM_CLOSE = &H10
Private Sub Command1_Click()
Dim bWnd, i
bWnd = FindWindowEx(ByVal 0&, ByVal 0&, vbNullString, "File Download")
If bWnd = 0 Then
Label1.Caption = "NO"
Else
Label1.Caption = "YES"
i = SendMessage(bWnd, WM_CLOSE, 0, 0&)
End If
End Sub
Bon Chance.
-
-
I assume you used Spy++ to get the ClassName. The class name for a dialog is not #32770 (Dialog), rather it's just #32770.