Results 1 to 3 of 3

Thread: help - trying to get text from another programs window

  1. #1

    Thread Starter
    New Member
    Join Date
    Feb 2001
    Posts
    7
    hi , im trying to obtain text from msn messenger window
    thats bacically it
    if any one could help i would be very chuffed
    cheers
    ali
    msvs6 enterprise sp5

  2. #2
    Frenzied Member Vlatko's Avatar
    Join Date
    Aug 2000
    Location
    Skopje, Macedonia
    Posts
    1,409
    You need the handle of the window whose text you want to get. After thet use the GetWindowText and GetWindowText API's.
    Code:
    Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
    Private Declare Function SetWindowText Lib "user32" Alias "SetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String) As Long
    Private Sub Form_Activate()
        Dim MyStr As String
        'Create a buffer
        MyStr = String(100, Chr$(0))
        'Get the windowtext
        GetWindowText hwnd, MyStr, 100
        'strip the rest of buffer
        MyStr = Left$(MyStr, InStr(MyStr, Chr$(0)) - 1)
    End Sub
    I am become death, the destroyer of worlds.
    mail:[email protected]

    • Visual Basic 6.0 & .NET
    • Visual C++ 6.0 & .NET
    • ASP
    • LISP
    • PROLOG
    • C
    • Pascal

  3. #3
    coder. Lord Orwell's Avatar
    Join Date
    Feb 2001
    Location
    Elberfeld, IN
    Posts
    7,628
    That works, but if the text you are getting is more than 100 bytes you are asking for a system crash.
    You need to preallocate the size of the buffer to at least as big as you know the text is.
    Code Sampe:
    Length& = SendMessage(windowhandle&, WM_GETTEXTLENGTH, 0&, 0&)

    buffer$ = String(Length&, 0&)

    Make sure you include all constants in your module...
    My light show youtube page (it's made the news) www.youtube.com/@lightsofelberfeld
    Contact me on the socials www.facebook.com/lordorwell

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