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.
ViperXAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

MikeP090797Commented:
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:
http://www.mvps.org/vbnet/code/_acc/ndxcomctl.htm
0
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!
0
MirkwoodCommented:
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)
next
0
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

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.
Thanks
0
MikeP090797Commented:
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

0
ViperXAuthor Commented:
hmmm  i can't get this working. i dont feel like bothering you anymore. but i apreciate the help. thank you.
0
MikeP090797Commented:
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 %)
0
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.

0
MirkwoodCommented:
If you still want to I have some sample code to do this...
0
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
0
MirkwoodCommented:
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()
    fill
End Sub

Private Sub Form_Load()
    init
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

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ViperXAuthor Commented:
well thanks... to bad vb6 rejects it...
0
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.  
0
vivekagarwal2009Commented:
b = SendMessageAny(m_lvHwnd, LVM_GETITEMTEXT, i, lvi)
Not Work
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.