For as powerful as win API's are, it sure is difficult to find good decent help on the subject.
Usually, you can google "example for " and find what you need to work off of, but Nooooo.
There's tons of "here's what an API is" but not exactly a simple "here's how to use it."
I've read through MSDN, and google posts, and experts-exchange, but i'm fed up.
How the snotrockets do you use SendMessage api to send simple letters and numbers to another window?
This just changes the freakin' title of the window. <grmph>
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Any) As Long
Private Declare Function SendMessageStr Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As String) As Long
Private Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Long) As Long
Sub testing()
Dim hwnd As Long
Const WM_SETTEXT = &HC
Const WM_KEYDOWN = &H100
Const WM_KEYUP = &H101
Const WM_CHAR = &H102
Const VK_RETURN = &HD
hwnd = FindWindow(0&, "Untitled - Notepad")
SendMessageStr hwnd, WM_SETTEXT, -1, "0131313"
End Sub
Posts
Also, when you say "send letters and numbers," do you mean keystrokes? The SendKeys .NET stuff is probably good for this.
I have a text box in another program, I use Sendkeys in VBA, but it's not exactly reliable, as the timing of the computer and speed of the program itself seems to play a big factor on successfully handling the key strokes.
For now, I'm looking to use SendMessage (I understand it pauses and waits for the result of the Keystroke being sent to the window) to send strings or sequences of letters to this other window. For now, even getting it to send to Notepad would be a step in the write direction.
If I could manage both goals, such as sending a string "01234567" and then sending {Enter} that'd be superb.
As for now, I'm relying on the Sleep API and doEvents to wait for the other program to kinda catch up.