|
-
Feb 17th, 2012, 08:01 AM
#1
Thread Starter
Frenzied Member
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
-
Feb 18th, 2012, 04:42 AM
#2
Addicted Member
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."
Last edited by Witis; Feb 18th, 2012 at 04:47 AM.
All men have an inherent right to life, the right to self determination including freedom from forced or compulsory labour, a right to hold opinions and the freedom of expression, and the right to a fair trial and freedom from torture. Be aware that these rights are universal and inalienable (cannot be given, taken or otherwise transferred or removed) although you do risk losing the aforementioned rights should you fail to uphold them e.g Charles Taylor; United Nations sources: http://www.un.org/en/documents/udhr/, http://www.ohchr.org/EN/Professional...ages/CCPR.aspx. Also Charles I was beheaded on the 30th of January of 1649 for trying to replace parliamentary democracy with an absolute monarchy, the same should happen to Dr Phil and Stephen Fry; source: http://www.vbforums.com/showthread.p...ute-Monarchism.
The plural of sun is stars you Catholic turkeys.
-
Feb 18th, 2012, 07:50 PM
#3
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)
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Feb 19th, 2012, 05:20 AM
#4
Re: Problem clicking save button on File Download window?
 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!
-
Feb 19th, 2012, 06:04 AM
#5
Re: Problem clicking save button on File Download window?
office development
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
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Feb 19th, 2012, 08:31 AM
#6
Re: Problem clicking save button on File Download window?
 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!
-
Feb 20th, 2012, 11:03 PM
#7
Thread Starter
Frenzied Member
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!
Last edited by tony007; Feb 20th, 2012 at 11:08 PM.
-
Feb 21st, 2012, 12:42 AM
#8
Addicted Member
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?
All men have an inherent right to life, the right to self determination including freedom from forced or compulsory labour, a right to hold opinions and the freedom of expression, and the right to a fair trial and freedom from torture. Be aware that these rights are universal and inalienable (cannot be given, taken or otherwise transferred or removed) although you do risk losing the aforementioned rights should you fail to uphold them e.g Charles Taylor; United Nations sources: http://www.un.org/en/documents/udhr/, http://www.ohchr.org/EN/Professional...ages/CCPR.aspx. Also Charles I was beheaded on the 30th of January of 1649 for trying to replace parliamentary democracy with an absolute monarchy, the same should happen to Dr Phil and Stephen Fry; source: http://www.vbforums.com/showthread.p...ute-Monarchism.
The plural of sun is stars you Catholic turkeys.
-
Feb 21st, 2012, 05:36 AM
#9
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
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
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Feb 21st, 2012, 06:55 AM
#10
Addicted Member
Re: Problem clicking save button on File Download window?
 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.
All men have an inherent right to life, the right to self determination including freedom from forced or compulsory labour, a right to hold opinions and the freedom of expression, and the right to a fair trial and freedom from torture. Be aware that these rights are universal and inalienable (cannot be given, taken or otherwise transferred or removed) although you do risk losing the aforementioned rights should you fail to uphold them e.g Charles Taylor; United Nations sources: http://www.un.org/en/documents/udhr/, http://www.ohchr.org/EN/Professional...ages/CCPR.aspx. Also Charles I was beheaded on the 30th of January of 1649 for trying to replace parliamentary democracy with an absolute monarchy, the same should happen to Dr Phil and Stephen Fry; source: http://www.vbforums.com/showthread.p...ute-Monarchism.
The plural of sun is stars you Catholic turkeys.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|