Results 1 to 2 of 2

Thread: List active windows - select a window - send keys to it

  1. #1

    Thread Starter
    New Member
    Join Date
    Jun 2001
    Posts
    5

    Question List active windows - select a window - send keys to it

    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

    Matt

  2. #2
    Registered User Nucleus's Avatar
    Join Date
    Apr 2001
    Location
    So that's what you are up to ;)
    Posts
    2,530
    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 :

    Code:
    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

    Code:
    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width