Public Sub SendChar(ByVal hwnd As Long, ByVal charCode As Long)
' Call PostMessage (hwnd, WM_KEYDOWN, charCode, ByVal 0&) '
Call PostMessage (hwnd, WM_CHAR, charCode, ByVal 0&)
' Call PostMessage (hwnd, WM_KEYUP, charCode, ByVal 0&) '<- This line causes characters to appear twice in textbox.
End Sub
if sending WM_KEYDOWN -> WM_CHAR -> WM_KEYUP
result is '55' and no <Enter> -> program does nothing.
Likewise when sent longer 12345 string result 1122334455 and no <Enter> -> program does nothing and the Enter key gets interpreted errorneously.
if posting WM_CHAR only...
the text is OK, but Enter gets interpreted errorneously.
Re: Postmessage API to send text and <Enter> to textbox in other application.
Originally Posted by Tech99
and would like to get some opinions about efficient ways to send text to other process textbox?
Directly posting using WM_SETTEXT message?
Originally Posted by MSDN
To set the text of a control in another process, send the WM_SETTEXT message directly instead of calling SetWindowText.
On Local Error Resume Next: If Not Empty Is Nothing Then Do While Null: ReDim i(True To False) As Currency: Loop: Else Debug.Assert CCur(CLng(CInt(CBool(False Imp True Xor False Eqv True)))): Stop: On Local Error GoTo 0
Re: Postmessage API to send text and <Enter> to textbox in other application.
Run App1 and App2
First thing you do is click on App2's Command "Get Objects From App1". This will fill the list box with all the info it needs. Now you can click on all the other buttons
Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.
Re: Postmessage API to send text and <Enter> to textbox in other application.
Originally Posted by Tech99
Call SendMessageByString(hwnd, WM_SETTEXT, 0, chars)
[/CODE]
Works nicely, likewise SetForeGroundWindow, but the textbox does not respond to BM_CLICK. Hence have to investigate how to send <Enter> key.
The app2 does not send BM_CLICK to a textbox; it sends it to a button
Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.
Re: Postmessage API to send text and <Enter> to textbox in other application.
Ok, thank you all. Got it working, but there were some anomalies, don't know why but...
Code:
Call SetForegroundWindow(AppMainWindowhWnd) 'App mainwindow hWnd Activate CRM app.
Call SendKeys("^{F2}", True) 'Wait for the app to perform go edit/search state keys pressing.
'Call SendKeys "^{F2}" 'does not work without Wait param (True).
Call SendMessageByString(TextBoxCtrlhWnd, WM_SETTEXT, 0, sDBPrimaryKey) 'Textbox ctrl hWnd
Call SendKeys("{ENTER}") 'Send <Enter>
and when first used plain 'SendKeys' instead of 'Call SendKeys ('. Sending app were 'kind of hanging' state - very sluggish respond and receiving app were in 'loop operation' ie. went edit state - got string - pressed enter again and again, until sending app was interrupted.