I shifted the code out and tested it on a separate project, but it still doesn't work. Anything is wrong?
code:
Dim hwnd_msn As Long
Dim hwnd_msn_edit As Long
hwnd_msn = FindWindow("IMWindowClass", vbNullString)
hwnd_msn_edit = FindWindowEx(hwnd_msn, 0&, "DirectUIHWND", vbNullString)
Dim sText As String
sText = Text1.text
Text1.text = ""
For i = 1 To Len(sText)
Call PostMessage(hwnd_msn_edit, WM_CHAR, Asc(Mid(sText, i, 1)), 0)
Next i
Call PostMessage(hwnd_msn_edit, WM_KEYDOWN, VK_RETURN, 0&)
Call PostMessage(hwnd_msn_edit, WM_KEYUP, VK_RETURN, 0&)
EDIT:
I realized that the above code will only work if I bring the window to the front first using this code:
code:
Dim RetVal As Long
RetVal = SetForegroundWindow(hwnd_msn_edit)
WaitForSingleObject RetVal, INFINITE
It wasn't very reliable though. Some messages would not get sent. Some concatenated and got sent as one line. (Tested it by repeatedly sending string of messsages through a text box)
Funny thing is, posting messages to Notepad actually works without having to bring the window to the front. I wonder why the difference.