Problem clicking save button on File Download window?
hi all . i am trying to click save button on file download window using this code but for some reason it doesn't work. I know i got the correct handle of the button but problem is clicking it. Hope you guyes help me fix this problem.Thanks
Code:
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" _
(ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
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 Const WM_KEYDOWN = &H100
Private Const WM_KEYUP = &H101
Private Const VK_SPACE = &H20
Private Sub Command2_Click()
Dim X As Long, editx As Long
Dim button As Long
X = FindWindow("#32770", "File Download")
button = FindWindowEx(X, 0&, "button", "&Save")
PostMessage button, WM_KEYDOWN, 32, 0 'send space to trigger button press
PostMessage button, WM_KEYUP, 32, 0
End Sub
Re: Problem clicking save button on File Download window?
try something like this:
Code:
Declare Function SendNotifyMessage Lib "user32.dll" Alias "SendNotifyMessageA" (ByVal hwnd As Long, ByVal msg As Long, wParam As Any, lParam As Any) As Long
Private Const BM_Click = &HF5
Code:
hwndAllow = FindWindowEx(hwnd, ByVal 0&, "Button", "Allow") ' find the allow button
If hwndAllow > 0 Then
Call SendNotifyMessage(hwndAllow, BM_Click, 0, 0) ' won't wait for send message to finish ie asynch
End If
SendNotifyMessage info:
http://msdn.microsoft.com/en-us/libr...(v=vs.85).aspx
"If the window was created by the calling thread, SendNotifyMessage calls the window procedure for the window and does not return until the window procedure has processed the message. If the window was created by a different thread, SendNotifyMessage passes the message to the window procedure and returns immediately; it does not wait for the window procedure to finish processing the message."
Re: Problem clicking save button on File Download window?
if you look at a similar thread in OD forum i have posted some working solution yesterday
if this does not work for you i would need to see the full code including website address (and login if required, you can pm those separately if needed)
Re: Problem clicking save button on File Download window?
Quote:
Originally Posted by
westconn1
if you look at a similar thread in OD forum i have posted some working solution yesterday
if this does not work for you i would need to see the full code including website address (and login if required, you can pm those separately if needed)
OD forum?
I'm using WinXP/IE8 here and so far the only thing that has worked for me is to wait 500ms after the "File Download" window is detected and then send a button click message to the Save button, if I don't wait the 500ms it just ignores any keys sent to it! :sick:
Re: Problem clicking save button on File Download window?
office development
Quote:
if I don't wait the 500ms it just ignores any keys sent to it!
i used application.wait in excel though i suggested that sleep could be used, i found that sometimes even a 1 second delay would not be enough
Re: Problem clicking save button on File Download window?
Quote:
Originally Posted by
westconn1
office development
i used application.wait in excel though i suggested that sleep could be used, i found that sometimes even a 1 second delay would not be enough
Thanks for the feedback! :thumb:
Re: Problem clicking save button on File Download window?
Thanks guys. well the window is called by same vb6 project so you guys think it will not work or should i put some sort of sleep before sending click ?
westconn1 if i used the example in OD fourm the file download window doesn't allow me to click any button on my form!! i think problem is the file download is called from within same vb6 project!
Re: Problem clicking save button on File Download window?
tony007 if you are only clicking a single button then you shouldn't have to sleep your thread, you would only have to sleep your thread if you need to wait for the application to respond to having the button clicked prior to doing something else with the application. Did using BM_Clicked work?
Re: Problem clicking save button on File Download window?
all testing i did, needed a sleep (or other pause) after setforgroundwindow, this may not be the case for all dialogs, but appears to be so for IE ones
Quote:
westconn1 if i used the example in OD fourm the file download window doesn't allow me to click any button on my form!!
during my testing i was able to either click the link by code, within the same procedure, before calling the code to click the dialog, or run the code to click the dialog first then click the link in the browser, both worked
Re: Problem clicking save button on File Download window?
Quote:
Originally Posted by
westconn1
all testing i did, needed a sleep (or other pause) after setforgroundwindow, this may not be the case for all dialogs, but appears to be so for IE ones
If you are using IE, I would go with Westconn1 on that one.