CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Sep 1999
    Posts
    3

    help with getting text from active window

    I need some ones infinite wisdom. I am trying to write an app. in vb6 that first you click a button then in 5 seconds it will grab the text from the active window. Ie. iexplorer e-mail ect. then send it to notepad. I haven't been able to figure it out though. I can get the entire window as bmp. but not just the text.


  2. #2
    Join Date
    May 1999
    Posts
    3,332

    Re: help with getting text from active window

    use this code to grab the window text of the foreground window then send it to notepad via sendkeys.

    option Explicit
    private Declare Function GetActiveWindow Lib "user32" () as Long
    private Declare Function GetForegroundWindow Lib "user32" () as Long
    private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (byval hwnd as Long, byval lpString as string, byval cch as Long) as Long
    private Const WM_GETTEXT = &HD
    private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (byval hwnd as Long, byval wMsg as Long, byval wParam as Long, byval strParam as string) as Long

    private Sub Command1_Click()
    Dim hwnd as Long
    hwnd = getacticewindow()

    End Sub

    private Sub t_Timer()
    Dim hwnd as Long
    hwnd = GetForegroundWindow()
    If hwnd = 0 then Exit Sub
    Dim strbuffer as string * 100
    SendMessage hwnd, WM_GETTEXT, 100, strbuffer
    MsgBox strbuffer
    End Sub



    tested in NT 4 with VB 6


  3. #3
    Join Date
    Sep 1999
    Posts
    3

    Re: help with getting text from active window

    Thank you so mutch for responding. I tried the code but have not been able to get it to send it. Is there any way you could send me a working modle to play with so I can see what I am doing wrong? I am still in the learning proces and need all the help I can get. I dont care where it sends it as long as it sends it some where.Thanks



  4. #4
    Join Date
    May 1999
    Posts
    3,332

    Re: help with getting text from active window

    given my example I assume that you have managed to grab the caption of the active (foreground) window. To send the text to notepad, use code like this:

    AppActivate "Unbenannt - Editor", true
    SendKeys "hi"



    This is based on a German NT installation. In an American version it's probably
    Appactivate "untitled - Notepad"...


  5. #5
    Join Date
    Sep 1999
    Posts
    3

    Re: help with getting text from active window

    Ok thanks for the help. I now have it functional. I just have one more question. How do you captcher the client area of the active window? Thank you so mutch for the help so far.


  6. #6
    Join Date
    Jul 1999
    Posts
    145

    Re: help with getting text from active window

    Careful with that SendKeys function though. If you close the target window in the middle of sending you crash your program and VB at the same time!


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

Featured