• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 870
  • Last Modified:

getting text from a listview control

How do I get the text in a listview control from another program. its classname is SysListView32 so assume its a listview control.
Thank you.
  • 7
  • 3
  • 3
  • +1
1 Solution
If you have the listview's handle, you can use SendMessage with LVM_ messages to get the items. To get the handle, you can use FindWindow and FindWindowEx. the LVM_GETITEMCOUNT message will give you the number of items, the LVM_GETITEM message will return information about item, incuding text.
You can get some more info at:
ViperXAuthor Commented:
Basicly you have told me the correct comamnd to do what i want to do. but it doesn't work. heres what i did.
listview% = my handle which does equal true! syslistview32
SendNow% = SendMessageByNum(listview%, LVM_GETITEMCOUNT, &HD, 0)

then i msgbox sendnow%
my msgbox was a value of 0 err help!
I think here is the part that you are missing.
Now you have to find a way to split the points.

Dim lvi as LVITEM

itemcount = SendMessage(listview%, LVM_GETITEMCOUNT, 0, byval 0)
for i = 1 to itemcount
    itemcount = SendMessageAny(listview%, LVM_GETITEM, i, lvi)
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

ViperXAuthor Commented:
I get problems like LVITEM  isn't defined and, SendMessageAny isn't defined. I think I need some LVM commands to go into my module file. If you have the ones I need I'd be happy if you tell me them.
SendMessageAny is just a regular SendMessage

Public Type LV_ITEM
    mask as long
    iItem as long
    iSubItem as long
    state as long
    stateMask as long
    pszText as string
    cchTextMax as long
    iImage as long
    lParam as long
End Type

ViperXAuthor Commented:
hmmm  i can't get this working. i dont feel like bothering you anymore. but i apreciate the help. thank you.
Is the other program made in VB? I've seen some problems with VB made apps and common controls. Also, use the Long type on the list handle, not integer (& instead of %)
ViperXAuthor Commented:
nah its in c++
I thought at least getting the count would be easy to do :)
well I may end up giving up on this project i want to do.
But thats ok, I hope in the future my better exparience will help me.

If you still want to I have some sample code to do this...
ViperXAuthor Commented:
Ya I really want to do this badly.
Look, I really am not all that great with VB. I try to learn off of source code. Which I do. Please just assum I have the handle of the syslistview32 which i do.. I need all the code that will define the lvm commands so that I can get the count, and get the item...
so when I msgbox count, it will tell me the count.
When I msgbox the first item in the list view, it will tell me...
just show me how to disply the first item please... that would be number 0 i think... I can make the counters .. make it simple.. please.  thank you
You need the declaration as provided by VBNet and put them in a module. Here is the code for a form.

Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
Private Declare Function GetLastError Lib "kernel32" () As Long

Dim m_lvHwnd As Long

Private Function FindWindow() As Long
    Dim pmHwnd As Long
    Dim dvHwnd As Long
    Dim lvHwnd As Long
    pmHwnd = FindWindowEx(0, 0, "Progman", "Program Manager")
    dvHwnd = FindWindowEx(pmHwnd, 0, "SHELLDLL_DefView", "")
    lvHwnd = FindWindowEx(dvHwnd, 0, "SysListView32", "")
     FindWindow = lvHwnd
End Function

Private Sub Command1_Click()
End Sub

Private Sub Form_Load()
End Sub

Private Sub init()
    m_lvHwnd = FindWindow
    ListView1.View = lvwReport
    ListView1.ColumnHeaders.Add , , "Name"
    ListView1.ColumnHeaders.Add , , "Size"
    ListView1.ColumnHeaders.Add , , "Type"
    ListView1.ColumnHeaders.Add , , "Modified"
    ListView1.ColumnHeaders.Add , , "Attributes"
End Sub

Private Sub fill()
    Dim c As Long
    Dim lvi As LVITEM
    Dim i As Integer
    Dim j As Integer
    Dim b As Boolean
    c = SendMessageLong(m_lvHwnd, LVM_GETITEMCOUNT, 0, 0)
    For i = 0 To c - 1
        lvi.iItem = i
        For j = 0 To 4
            lvi.mask = LVIF_TEXT
            lvi.iSubItem = j
            lvi.pszText = Space$(80)
            lvi.cchTextMax = Len(lvi.pszText)
            b = SendMessageAny(m_lvHwnd, LVM_GETITEMTEXT, i, lvi)
            Debug.Assert b = True
            Debug.Print GetLastError
        Next j
    Next i
End Sub

ViperXAuthor Commented:
well thanks... to bad vb6 rejects it...
ViperXAuthor Commented:
Ok, I'v done some searching and someone told me that I have to hook this window I want and recieve the in comming windows messages and add each message into a text box. I really dont know how to do this and if it wouldn't be to much trouble I would be thankful if you could tell me a place that will show me what I need to know.  
b = SendMessageAny(m_lvHwnd, LVM_GETITEMTEXT, i, lvi)
Not Work
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 7
  • 3
  • 3
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now