Solved

getting text from a listview control

Posted on 1998-11-25
14
833 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
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

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
 

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

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.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

830 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