matthewfoster
Jun 3rd, 2001, 12:49 PM
How can I list all the active windows, select one of them and then send some text to it?
For example MSN messenger. Making it periodically send a set message.
Please help me :confused:
Matt
Nucleus
Jun 3rd, 2001, 07:44 PM
Try findwindow api call then enumerate through the child windows of the application to locate the hwnd of the textbox, then send text the hwnd of the control using :
Option Explicit
Private Const WM_SETTEXT = &HC
Private Declare Function SendMessageByStr& Lib "user32" Alias "SendMessageA" _
(ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal _
lParam As String)
Private Sub cmdSetText_Click()
Dim t$
Dim c&
t = "Hello World"
c& = SendMessageByStr(txt1.hWnd, WM_SETTEXT, 0, t)
End Sub
Then find the hwnd of the "submit" button, and click it :
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Const BM_CLICK = &HF5
SendMessage hWnd_Btn, BM_CLICK, 0, 0
Wrap the code in a timer to do it periodically and you are done. Easy in theory, but getting the correct hwnd is the hardest part.