Ask Question Forum:
Model Library:2025-02-08 Updated:A.I. model is online for auto reply question page
C
O
M
P
U
T
E
R
2
8
Show
#
ASK
RECENT
←
- Underline
- Bold
- Italic
- Indent
- Step
- Bullet
- Quote
- Cut
- Copy
- Paste
- Table
- Spelling
- Find & Replace
- Undo
- Redo
- Link
- Attach
- Clear
- Code
Below area will not be traslated by Google,you can input code or other languages
Hint:If find spelling error, You need to correct it,1 by 1 or ignore it (code area won't be checked).
X-position of the mouse cursor
Y-position of the mouse cursor
Y-position of the mouse cursor
Testcursor
caretPos
Attachment:===
Asked by srj19
at 2024-04-21 10:13:03
Point:0 Replies:17 POST_ID:828481USER_ID:11306
Topic:
Miscellaneous Programming;Visual Basic Programming;Programming Languages
I hope this is as easy as it seems, I'm missing something though as I'm not well versed in VB.
Once I've got the Print/Save dialog from of the browswer, I'm sucessfully getting a handle to the print dialog window and also the handle for the "save as" button however getting the button to click is not working.
Additionally, I'd like to be able to send a file name directly to the textbox within this dialog box instead of using keystrokes.
Simple right?
I've enclosed some scaled down code to make for easy scanning, basically I'm stuck in the process of getting SendMessage() to
Once I've got the Print/Save dialog from of the browswer, I'm sucessfully getting a handle to the print dialog window and also the handle for the "save as" button however getting the button to click is not working.
Additionally, I'd like to be able to send a file name directly to the textbox within this dialog box instead of using keystrokes.
Simple right?
I've enclosed some scaled down code to make for easy scanning, basically I'm stuck in the process of getting SendMessage() to
DialogHwnd = 0 Do Until DialogHwnd <> 0 DialogHwnd = FindWindow(vbNullString, "Save As") Loop Dim ButtonHwnd As Long 'get the handle of the first button ButtonHwnd = FindWindowEx(DialogHwnd, 0, "Button", "&Save") Call SendMessage(ButtonHandle, ByVal BM_CLICK, 0, 0) 1:2:3:4:5:6:7:8:9:10:11:12:13:14:15:16:
Author: srj19 replied at 2024-06-13 01:19:16
I always use Postmessage and it work for many year for a button click for auotmation file download in popupmenu,
Sendmessage is not stable
Public Declare Function PostMessage Lib "user32" Alias "PostMessageA" _
(ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Const WM_LBUTTONDOWN = &H201
hdlg= FindWindow(vbNullString, "Example download site! - Window Internet Explorer")
retval= 0
Do Until retval <> 0
retval = PostMessage(hdlg, WM_LBUTTONDOWN, 0, vbNullString) 'Click download button
Loop
Sendmessage is not stable
Public Declare Function PostMessage Lib "user32" Alias "PostMessageA" _
(ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Const WM_LBUTTONDOWN = &H201
hdlg= FindWindow(vbNullString, "Example download site! - Window Internet Explorer")
retval= 0
Do Until retval <> 0
retval = PostMessage(hdlg, WM_LBUTTONDOWN, 0, vbNullString) 'Click download button
Loop
Accepted Solution
Author: srj19 replied at 2024-06-08 10:14:24
Wasn't able to resolve.
Expert: Dhaest replied at 2024-06-01 01:17:03
I always use Postmessage and it work for many year for a button click for auotmation file download in popupmenu,
Sendmessage is not stable
Public Declare Function PostMessage Lib "user32" Alias "PostMessageA" _
(ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Const WM_LBUTTONDOWN = &H201
hdlg= FindWindow(vbNullString, "Example download site! - Window Internet Explorer")
retval= 0
Do Until retval <> 0
retval = PostMessage(hdlg, WM_LBUTTONDOWN, 0, vbNullString) 'Click download button
Loop
Sendmessage is not stable
Public Declare Function PostMessage Lib "user32" Alias "PostMessageA" _
(ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Const WM_LBUTTONDOWN = &H201
hdlg= FindWindow(vbNullString, "Example download site! - Window Internet Explorer")
retval= 0
Do Until retval <> 0
retval = PostMessage(hdlg, WM_LBUTTONDOWN, 0, vbNullString) 'Click download button
Loop
Expert: duncanb7 replied at 2024-05-05 11:52:15
I always use Postmessage and it work for many year for a button click for auotmation file download in popupmenu,
Sendmessage is not stable
Public Declare Function PostMessage Lib "user32" Alias "PostMessageA" _
(ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Const WM_LBUTTONDOWN = &H201
hdlg= FindWindow(vbNullString, "Example download site! - Window Internet Explorer")
retval= 0
Do Until retval <> 0
retval = PostMessage(hdlg, WM_LBUTTONDOWN, 0, vbNullString) 'Click download button
Loop
Sendmessage is not stable
Public Declare Function PostMessage Lib "user32" Alias "PostMessageA" _
(ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Const WM_LBUTTONDOWN = &H201
hdlg= FindWindow(vbNullString, "Example download site! - Window Internet Explorer")
retval= 0
Do Until retval <> 0
retval = PostMessage(hdlg, WM_LBUTTONDOWN, 0, vbNullString) 'Click download button
Loop
Expert: Ark replied at 2024-05-01 18:39:49
Oops, PostMessage Declaration:
Public 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
Public 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
Expert: Ark replied at 2024-05-01 18:33:40
Not sure about WebBrowser dialogs, but standard windows dialogs use WM_COMMAND messages
Option ExplicitPrivate Enum CtrlID ' ID of controls' For All dialogs ID_OK = &H1 'Open or Save button ID_CANCEL = &H2 'Cancel Button ID_HELP = &H40E 'Help Button' For open/save dialogs ID_READONLY = &H410 'Read-only check box ID_FILETYPELABEL = &H441 'FileType label ID_FILELABEL = &H442 'FileName label ID_FOLDERLABEL = &H443 'Folder label ID_LIST = &H461 'Parent of file list ID_FILETYPE = &H470 'FileType combo box ID_FOLDER = &H471 'Folder combo box ID_FILETEXT = &H480 'FileName text box ID_NEWFOLDER = &HFFFFA002 ' NewFolder Button - can not be disabled ID_PARENTFOLDER = &HFFFFA001 ' GoUp button - can not be disabled' for print dialogs ID_ALLPAGES = &H420 ID_SELECTEDTEXT = &H421 ID_PAGERANGE = &H422 ID_COPYES = &H482 ID_PRINTERCOMBO = &H473 ID_PRINTTOFILE = &H410 ID_PROPERTIES = &H401 ' for font Dialog ID_FONTTEXT = &H470 ID_STYLETEXT = &H471 ID_SIZETEXT = &H471End EnumPrivate Declare Function GetDlgItem Lib "user32" (ByVal hDlg As Long, ByVal nIDDlgItem As Long) As LongPrivate Const WM_COMMAND = &H111Private Const BN_CLICKED = 0Private Sub Command1_Click() 'Assuming you know hDlg - dialog handle PostMessage hDlg, WM_COMMAND, MakeDWord(ID_OK, BN_CLICKED), GetDialogItem(hDlg, ID_OK)End SubPrivate Function GetDialogItem(ByVal hDlg As Long, ByVal ItemID As CtrlID) As Long GetDialogItem = GetDlgItem(hDlg, nItem)End FunctionPrivate Function MakeDWord(ByVal wLo As Integer, ByVal wHi As Integer) As Long MakeDWord = (wHi * 65536) + (wLo And &HFFFF&)End Function 1:2:3:4:5:6:7:8:9:10:11:12:13:14:15:16:17:18:19:20:21:22:23:24:25:26:27:28:29:30:31:32:33:34:35:36:37:38:39:40:41:42:43:44:45:46:47:48:49:
Expert: xxlc replied at 2024-04-22 04:26:15
You can look at this accepted answere and see if it helps .. http:Q_25718823.html
Which OS and can you show print screen of the this print dialog?
Which OS and can you show print screen of the this print dialog?
Expert: Mike Tomlinson replied at 2024-04-21 15:30:37
Not sure...do you have Spy++? It would help in figuring out if the targeted window is getting the message or determining if a different message is needed instead.
Author: srj19 replied at 2024-04-21 15:08:33
Anyone?
Assuming I have a valid handle for the "Save As" button, what are the areas to delve into to determine why the code below isn't producing a click?
Call SendMessage(ButtonHandle, WM_LBUTTONDOWN, 0, 0)
Call SendMessage(ButtonHandle, BM_SETSTATE, 1, 0)
Call SendMessage(ButtonHandle, BM_CLICK, 0, 0)
Call SendMessage(ButtonHandle, WM_LBUTTONUP, 0, 0)
Assuming I have a valid handle for the "Save As" button, what are the areas to delve into to determine why the code below isn't producing a click?
Call SendMessage(ButtonHandle, WM_LBUTTONDOWN, 0, 0)
Call SendMessage(ButtonHandle, BM_SETSTATE, 1, 0)
Call SendMessage(ButtonHandle, BM_CLICK, 0, 0)
Call SendMessage(ButtonHandle, WM_LBUTTONUP, 0, 0)
Author: srj19 replied at 2024-04-21 13:52:55
I might have to go the direction of moving the mouse and clicking the button via programming. ACan you point me toward any code examples of how that would work?
On the other hand, is there any code snipets I could be putting into the flow that could help undertand what is not being passed to SendMessage() or possibly what isn't being returned.
Scott
On the other hand, is there any code snipets I could be putting into the flow that could help undertand what is not being passed to SendMessage() or possibly what isn't being returned.
Scott
Expert: Mike Tomlinson replied at 2024-04-21 13:32:20
If you can't get it to work with SendMessage() then you can pass the handle to GetWindowRect() which would give you the physical screen coords of the button. Then you could physically move and click the mouse over that area using the mouse_event() API. This obviously has the limitation that the dialog MUST be in the foreground for this to work.
Author: srj19 replied at 2024-04-21 13:29:50
I just noticed that in the example I posted the two handle variables were not the same but since then I've tried Idle_Minds' additional code plus some from another source and I'm still not getting a click.
To answer you other question, ButtonHwnd gets value from the line
ButtonHwnd = FindWindowEx(DialogHwnd, 0, "Button", "&Save")
To answer you other question, ButtonHwnd gets value from the line
ButtonHwnd = FindWindowEx(DialogHwnd, 0, "Button", "&Save")
Expert: xDJR1875 replied at 2024-04-21 12:42:12
srj19... I simply stated that it looked like you were assigning the button handle to one variable (ButtonHwnd ) and then using a different handle (ButtonHandle ) to send the message.
Where does ButtonHandle get the windowhandle id from? If ButtonHwnd has the value, use it in the SendMessage call.
Where does ButtonHandle get the windowhandle id from? If ButtonHwnd has the value, use it in the SendMessage call.
Author: srj19 replied at 2024-04-21 12:33:34
Idle_Mind, I inserted the code you gave (buttondown, setstate, click and button up) but I still am not clicking the button. I'm pretty sure the handle to the button is good, I put a few msgboxs into the code and after identifiying the window I have a handle of 268688 and after identifing the button I have a control of 203416. Assuming the handle is good, what is likely the cause of the failure to click? This code would work on any windows based button correct? This button is part of the CutePdf printer/convter dialog. It functions just like printing but converts to a PDF.
xDJR1875, I'm using SendMessage since it's the only example I've seen online to communicate with the button control, is there a better way to do this?
DevelopedTester, I looked at the link you sent. I initially thought I'd written it since he described my situation so closely, but in the end it looks like he didn't resolve the issue in that forum.
Expert: Mike Tomlinson replied at 2024-04-21 11:17:05
For the button, try a sequence like this:
Call SendMessage(ButtonHandle, WM_LBUTTONDOWN, 0, 0)
Call SendMessage(ButtonHandle, BM_SETSTATE, 1, 0)
Call SendMessage(ButtonHandle, BM_CLICK, 0, 0)
Call SendMessage(ButtonHandle, WM_LBUTTONUP, 0, 0)
Are you sure you have a valid handle though?
ButtonHwnd = FindWindowEx(DialogHwnd, 0, "Button", "&Save")
If ButtonHwnd <> 0 Then
' ... click the button ...
Else
MsgBox "Button not found"
End If
Call SendMessage(ButtonHandle, WM_LBUTTONDOWN, 0, 0)
Call SendMessage(ButtonHandle, BM_SETSTATE, 1, 0)
Call SendMessage(ButtonHandle, BM_CLICK, 0, 0)
Call SendMessage(ButtonHandle, WM_LBUTTONUP, 0, 0)
Are you sure you have a valid handle though?
ButtonHwnd = FindWindowEx(DialogHwnd, 0, "Button", "&Save")
If ButtonHwnd <> 0 Then
' ... click the button ...
Else
MsgBox "Button not found"
End If
Expert: developedtester replied at 2024-04-21 10:25:13
Expert: xDJR1875 replied at 2024-04-21 10:25:05
Unless I am missing somthing , you are getting the handle ito the ButtonHwnd variable yet you are passing ButtonHandle to the SendMessage function.
Where is ButtonHandle getting set to the value of ButtonHwnd?
Where is ButtonHandle getting set to the value of ButtonHwnd?