Results 1 to 3 of 3

Thread: Difficult? LB_GETTEXT is unreadable.

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 1999
    Location
    Cleveland, Ohio
    Posts
    263

    Difficult? LB_GETTEXT is unreadable.

    I'm using LB_GETTEXT to retrieve text from a listbox in another application, however the results are not exactly what I could have hoped for. I'm pretty sure my code here is correct, however I remember reading somewhere that I have to use ReadProcessMemory to retrieve the text, but I'm not sure. Any ideas?

    Code:
        Dim lCount As Long, lIndex As Long
        Dim sItem As String, lLen As Long
        Dim sList As String
        
        lCount = SendMessage(hwnd, LB_GETCOUNT, 0&, ByVal 0&)
        For lIndex = 0 To lCount - 1
            lLen = SendMessage(hwnd, LB_GETTEXTLEN, lIndex, ByVal 0&)
            sItem = Space(lLen)
            Call SendMessage(hwnd, LB_GETTEXT, lIndex, ByVal sItem)
            sList = sList & vbCrLf & sItem
        Next

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333
    Check out the .Bas file available on this link and see if it does anything for you. I found it when doing a web search for ReadProcessMemory.

    http://www.codearchive.com/vbasic/Hoax60.bas

  3. #3
    Fanatic Member Kaverin's Avatar
    Join Date
    Oct 2000
    Posts
    930
    What you can do is just alias the function and change lParam. Keep your existing declaration of SendMessage, but add another one that looks like this:
    VB Code:
    1. Declare Function SendMessageString Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, [b]ByVal lParam As String[/b]) As Long
    Then in the line where you actually retrieve the text, use SendMessageString rather than your other SendMessage function, and remove the ByVal you have before your sItem param. That way, you can keep the rest of the code as you've written it with no side effect, but you don't have to do any messing around with byte arrays and worrying over unicode strings and whatnot. I tested this before posting by grabbing stuff out of mIRC nickname list, so it can get the stuff out of a listbox of a non VB (and VB) app just fine.
    I'm baaaack...
    VB5 Professional Edition, VC++ 6
    Using a 1 gHz Thunderbird, 256 mb RAM, 40 gb HD system with Win98se

    I feel special because I finally figured out how to loop midis: Post link
    I'm a fanatic too

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