Hello
I am trying to automate a few non standard systems by using common API's such as SendMessage & PostMessage. I can use these API's as I intended, however there are issues where the code seems to go too fast. It's simple enough to have some sort of wait code for automating things such as Internet explorer by doing a Do Until ReadyState..., but when trying something similar on external windows, I seem to hit a problem.
Take for instance this example; I need to send text to a textbox with WM_SETTEXT, I can get the handles no problem, I can also run this no successfully if I press F11 and step into each line, if however I let it run at normal speed, the code doesn't end up entering the text into the textbox, my solution was to have the code do another SendMessage to do WM_GETTEXTLENGTH & WM_GETTEXT so that the code can check if the text has been entered to the textbox and loop until it is there, to my surprise however, the WM_GETTEXTLENGTH & WM_GETTEXT actually think that the text has been entered even though there is no text in the textbox, it even knows what text is supposed to be in there. Even more perculier is that when I do WM_GETTEXTLENGTH & WM_GETTEXT again on that control, it goes back to saying that there is no text within the textbox.
It sounds a bit confusing, I'm puzzled myself, if you have any solutions I would really like to know, the Sleep API would make it partially work as it makes the system physically wait, but I know that theres the possibility that would fail sometimes too, is there some sort of screen paint/refresh that would work or something?
I look forward to any solutions.
Many Thanks
Xenac
I am trying to automate a few non standard systems by using common API's such as SendMessage & PostMessage. I can use these API's as I intended, however there are issues where the code seems to go too fast. It's simple enough to have some sort of wait code for automating things such as Internet explorer by doing a Do Until ReadyState..., but when trying something similar on external windows, I seem to hit a problem.
Take for instance this example; I need to send text to a textbox with WM_SETTEXT, I can get the handles no problem, I can also run this no successfully if I press F11 and step into each line, if however I let it run at normal speed, the code doesn't end up entering the text into the textbox, my solution was to have the code do another SendMessage to do WM_GETTEXTLENGTH & WM_GETTEXT so that the code can check if the text has been entered to the textbox and loop until it is there, to my surprise however, the WM_GETTEXTLENGTH & WM_GETTEXT actually think that the text has been entered even though there is no text in the textbox, it even knows what text is supposed to be in there. Even more perculier is that when I do WM_GETTEXTLENGTH & WM_GETTEXT again on that control, it goes back to saying that there is no text within the textbox.
Code:
Private Enum WindowMessages
WM_SETTEXT = &HC
WM_GETTEXT = &HD
WM_GETTEXTLENGTH = &HE
End Enum
Private Declare Function SendMessage Lib "user32" Alias _
"SendMessageA" (ByVal hWnd As Int32, ByVal wMsg As Int32, ByVal _
wParam As Int32, lParam As String) As Int32
Private Sub TestExample(ByVal hWndTextBox As Int32, ByVal TextString As String)
'####Using the hWnd of a Combo box control and a string to enter in the combo box.####
Dim TextLength As Int32
Dim ItemText As String
Do Until ItemText = TextString
SendMessage(hWndTextBox, WM_SETTEXT, 0, TextString) > 0
TextLength = SendMessage(hWndTextBox, WM_GETTEXTLENGTH, 0, 0)
ItemText = Space(TextLength)
SendMessage(hWndTextBox, WM_GETTEXT, TextLen + 1, ItemText)
Loop
End Sub
I look forward to any solutions.
Many Thanks
Xenac