Re: get text from listbox



RB Smissaert wrote:
> Trying to get the text of items in a listbox of an external
> application.

Hard to tell from the thread if you're still having issues with this. But I
wrote this long ago, and it works great for standard listboxes:

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 LB_GETTEXT = &H189
Private Const LB_GETTEXTLEN = &H18A
Private Const LB_GETCOUNT = &H18B
Private Const LB_ERR = (-1)

' Within some routine, assuming you have a valid hWnd...
Dim nCount As Long, i As Long
Dim TxtLen As Long
Dim Buffer As String

nCount = SendMessage(hWnd, LB_GETCOUNT, 0&, ByVal 0&)
If nCount <> LB_ERR Then
For i = 0 To nCount - 1
TxtLen = SendMessage(hWnd, LB_GETTEXTLEN, i, ByVal 0&)
If Len(Buffer) < (TxtLen + 1) Then
Buffer = Space$(TxtLen + 1)
End If
If SendMessage(hWnd, LB_GETTEXT, i, ByVal Buffer) <> LB_ERR Then
Debug.Print Left$(Buffer, TxtLen)
End If
Next i
End If

Later... Karl
--
Working without a .NET?
http://classicvb.org/


.



Relevant Pages

  • Re: Problems to set PaperSize prop for a Printer object. "Invalid property value"
    ... FillPapersList hinders the listbox from hanging while prosessing. ... Private Sub FillPapersList(ByRef Errors As Long, ... Dim iPrinter As Long ... Private Const DC_PAPERNAMES = 16 ...
    (microsoft.public.vb.general.discussion)
  • Re: Horizontal Scrollbar
    ... Oh...you're working with a ListBox not a Form's ScrollBar. ... Here's the code to force a ListBox to Scroll to a specific row. ... Private Const SB_THUMBPOSITION = 4 ... Dim hWndSB As Long ...
    (comp.databases.ms-access)
  • Re: Long MsgBox -- need to display in 2 paragraphs
    ... I have a problem with building an array for a listbox. ... Dim dbDatabase As Database ... MsgBox "Choose a search field", ... Word MVP web site http://word.mvps.org ...
    (microsoft.public.word.vba.general)
  • Re: Visual basic for a rightkey command
    ... Dim arrAs Long ... Sub Displaycursor() ... Private Const MOUSEEVENTF_LEFTDOWN = &H2 ... Dim lFlags As Long ...
    (microsoft.public.excel.programming)
  • Re: ACC 2002: Sort a ListBox with no SQL rowsource
    ... then sort the array. ... >algorythm to sort my listbox where my listbox does not ... >have a SQL statement or Query for it's RowSource; ... >>Dim vGetWidths As Variant ...
    (microsoft.public.access.formscoding)

Loading