Solved

getting text from a listview control

Posted on 1998-11-25
14
827 Views
Last Modified: 2008-02-20
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.
0
Comment
Question by:ViperX
  • 7
  • 3
  • 3
  • +1
14 Comments
 
LVL 8

Expert Comment

by:MikeP090797
ID: 1446797
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
 

Author Comment

by:ViperX
ID: 1446798
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
 
LVL 13

Expert Comment

by:Mirkwood
ID: 1446799
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
 

Author Comment

by:ViperX
ID: 1446800
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
 
LVL 8

Expert Comment

by:MikeP090797
ID: 1446801
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
 

Author Comment

by:ViperX
ID: 1446802
hmmm  i can't get this working. i dont feel like bothering you anymore. but i apreciate the help. thank you.
0
 
LVL 8

Expert Comment

by:MikeP090797
ID: 1446803
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Author Comment

by:ViperX
ID: 1446804
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
 
LVL 13

Expert Comment

by:Mirkwood
ID: 1446805
If you still want to I have some sample code to do this...
0
 

Author Comment

by:ViperX
ID: 1446806
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
 
LVL 13

Accepted Solution

by:
Mirkwood earned 200 total points
ID: 1446807
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
 

Author Comment

by:ViperX
ID: 1446808
well thanks... to bad vb6 rejects it...
0
 

Author Comment

by:ViperX
ID: 1446809
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
 

Expert Comment

by:vivekagarwal2009
ID: 25450024
b = SendMessageAny(m_lvHwnd, LVM_GETITEMTEXT, i, lvi)
Not Work
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now