Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Reading/Copying Listview from another app.

Status
Not open for further replies.

Raydr

IS-IT--Management
Mar 19, 2002
20
US
Alright,

I work for an installation company. We have a program that populates a ListView with hundreds of work orders, along with info about the work order, such as address, customer name, etc.

Basically, a listview with hundreds of rows and a dozen columns.

Here's the issue:

The dumbass app developers didn't include any kind of export function. I would like to read the listview using API to copy it to a listview in my own program. Then, I can do sorting/printing/exporting/etc.

I've spent a good couple of hours trying to research the best way to copy a listview out of another program into mine.

Help? :)
 
Ok, I think it might help if you try to ask where the source data is? It sounds as if your app has a database behind it. Itd probably be easier to get the data straight from there.
 
I am sure this can be done. It would be complex.

You would somehow have to get the window handle of the listview control on the other form.

Then you could use the SendMessage API to get all of the items and subitems from the listview. Check out this article and other articles in it's section.


I wish I had time to put this all together for you but I don't. If I get time later then maybe I can.... or maybe someone else here can go from here... ??
 
Ok, so I got a little curious and this is what I came up with so far. This get's the handle of the listview control

Code:
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 Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
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 Sub Form_Load()
    Dim hwndFrm As Long
    Dim hwndLvw As Long
    
    Dim lRet As Long
    
    hwndFrm = FindWindow(vbNullString, "ListViewWindow") 'Replace with the text of your window
    
    If hwndFrm = 0 Then
        MsgBox "Window Not Found"
    Else
        hwndLvw = FindWindowEx(hwndFrm, &O0, "ListView20WndClass", vbNullString)
        If hwndLvw = 0 Then
            MsgBox "Can't find Listview"
        End If
    End If
End Sub
 
VBrit: There's absolutely no way there'd be any access directly to the database. This is a national company with millions and millions of subscribers.

bjd4jc, getting the hwnd is no problem - although I do greatly appreciate the effort on that end. The issue is I'm not familiar at all with the API calls I can send to the listview control.

I've found a little bit of stuff out there, but not enough to properly get all items and subitems and place it into my own listview.

Do you know, assuming we already have the hwnd of the external listview, how we can loop through and copy each item to a listview in my own app?
 
Heck, maybe there's a way we can subclass the thing so I can just loop through each item in the list and print it to a file?
 
You will want to use the SendMessage API to send the LVM_GETITEM (hex value of &H104B) and LVM_GETNEXTITEM (&H100C). I get stuck in actually returning the item. I am not familiar enough with C to convert the structures to what is acceptable for VB to call them. The link above contains links to all of the structures you will need (paticuraly LV_ITEM). If I get more time and can play around with it I may be able to pound something out eventually.

Sorry I can't be of more immediate help to you...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top