that works for listboxes within my program, however, the listbox whose contents i need is in another program. ive gotten that listbox's handle using a few API calls.
Main Topics
Browse All TopicsHow can I get the contents of a listbox if all i have is the list box's window handle?
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Another thing to consider is to try to get the listbox handle from the owner program and compare it with the window handle you are getting from the 'client' application. It may be that one window handle is a 16 bit number, and the other is a 32 bit handle. This could especially be the case if one application is Win16 and the other is Win32, or if a 'Win32' application actually uses a 'Win16' handle. I've had a similar problem before. I had a 32 bit application that worked fine under Win95, but didn't work under NT because a component in the application was returning a 16 bit handle. NT was unforgiving, Win95 didn't care.
Just A Thought,
Martin
Business Accounts
Answer for Membership
by: cipPosted on 1998-08-29 at 03:29:51ID: 1431744
You can use the SendMessage() API function to retrieve the content of a window listbox control.
The following code will retrieve the content of a listbox item only using the window handle of a visual basic listbox control. You should get the same result for any standard windows listbox.
- Draw a listbox control and a command button on your form.
- Paste this code:
Private Const LB_ERR = (-1)
Private Const LB_GETTEXT = &H189
Private Const LB_GETTEXTLEN = &H18A
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 Sub Command1_Click()
Dim i As Integer
Dim sItem As String, iLen As Integer
Cont ITEMINDEX = 20
' Fill the listbox
For i = 1 To 40
List1.AddItem "Item " & i
Next
' Get length of item 21 before
' retrieving it
iLen = SendMessage(List1.hwnd, LB_GETTEXTLEN, ITEMINDEX, 0&)
If iLen = LB_ERR Then
MsgBox "Error retrieving item length"
Exit Sub
End If
' Allocate enough room in the
' string variable, then get item
sItem = Space$(iLen)
iLen = SendMessage(List1.hwnd, LB_GETTEXT, ITEMINDEX, ByVal sItem)
If iLen = LB_ERR Then
MsgBox "Error retrieving item"
Exit Sub
End If
MsgBox "Item retrieved: " & sItem
End Sub