CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 10 of 10

Threaded View

  1. #1
    Join Date
    Dec 2009
    Posts
    17

    Get text of the item out of listview with LVS_OWNERDRAWFIXED

    how to Get itemtext of the list item out of listview with LVS_OWNERDRAWFIXED

    what is wrong wht the code its not getting the item text from the listview with lvs_ownerdrawfixed

    Code:
    Public Function SysListView32ToCSV(ByVal hListView As Long, ByVal DestPath As String, ByVal Delimiter As String) As Boolean
        On Error GoTo ErrHandler
        
        Dim ListCount As Long, ColumnCount As Long, HeaderhWnd As Long
        Dim ProcessID As Long, ProcessHandle As Long
        Dim MemAddr1 As Long, MemAddr2  As Long
        Dim i As Long, j As Long, lRtn As Long
        Dim sLine As String, sText As String, ItemText As String
        Dim ListViewItem As LVITEM
        Dim HeaderItem As HDITEM
        Dim aText() As Byte
        Dim FF As Integer
        
        Dim DI As NMLVDISPINFO      'trying for DISPINFO
        
        
        ListCount = SendMessage(hListView, LVM_GETITEMCOUNT, 0, ByVal 0&)
        
        HeaderhWnd = SendMessage(hListView, LVM_GETHEADER, 0, ByVal 0&)
        
        ColumnCount = SendMessage(HeaderhWnd, HDM_GETITEMCOUNT, 0, ByVal 0&)
        
    
        If Dir(DestPath) <> "" Then Kill DestPath
        
        GetWindowThreadProcessId hListView, ProcessID
        
        If ProcessID = 0 Then Exit Function
            
        ProcessHandle = OpenIPCProcess(ProcessID)
        
        If ProcessHandle Then
        
            FF = FreeFile
            Open DestPath For Append As #FF
                
    '        MemAddr1 = CreateIPCMemory(36, ProcessHandle)
            MemAddr2 = CreateIPCMemory(261, ProcessHandle)
            
    '        If Not (MemAddr1 = 0& Or MemAddr2 = 0&) Then
    '
    '            With HeaderItem
    '                .cchTextMax = 260&
    '                .mask = HDI_TEXT
    '                .pszText = MemAddr2
    '
    '            End With
    '
    '            ReDim aText(0 To 260) ' << Moved here
    '            For i = 0 To ColumnCount - 1
    '                WriteIPCMemory ProcessHandle, MemAddr1, VarPtr(HeaderItem), 36&
    '                lRtn = SendMessage(HeaderhWnd, HDM_GETITEMA, i, ByVal MemAddr1)
    '                Debug.Print lRtn
    '                If lRtn Then
    '                    ReadIPCMemory ProcessHandle, MemAddr2, VarPtr(aText(0)), 260&
    '                     ItemText = StrConv(aText, vbUnicode)
    '                    ItemText = Left$(ItemText, InStr(ItemText, vbNullChar) - 1)
    '                    sLine = sLine & ItemText & IIf(j < ColumnCount - 1, Delimiter, vbNullString)
    '                End If
    '            Next
    '
    '            Print #FF, sLine
    '
    '            ' Release virtual memory
    '            DestroyIPCMemory ProcessHandle, MemAddr1
    '
    '        End If
    
            ' Create virtual memory
             MemAddr1 = CreateIPCMemory(40, ProcessHandle)
            ' MemAddr1 = CreateIPCMemory(Len(DI), ProcessHandle)
            
            
            If Not (MemAddr1 = 0& Or MemAddr2 = 0&) Then
                
                For i = 0 To 0 ' ListCount - 1
                    sLine = vbNullString
                    For j = 0 To 0 ' ColumnCount - 1
                        With ListViewItem
                            .cchTextMax = 260&
                            .mask = LVIF_TEXT
                            .pszText = MemAddr2
                            .iItem = i
                            .iSubItem = j
                        End With
                        WriteIPCMemory ProcessHandle, MemAddr1, VarPtr(ListViewItem), 40&
                        lRtn = SendMessage(hListView, LVM_GETITEMA, 0&, ByVal MemAddr1)
        Debug.Print lRtn
                        If lRtn <> 0& Then
                            ReadIPCMemory ProcessHandle, MemAddr1, VarPtr(ListViewItem), 40&
        Debug.Print vbTab; ListViewItem.pszText; MemAddr2; ListViewItem.cchTextMax
                            ' To be safe, I'd resize aText() to .cchTextMax
                            ReDim aText(0 To ListViewItem.cchTextMax)
                            ReadIPCMemory ProcessHandle, ListViewItem.pszText, VarPtr(aText(0)), ListViewItem.cchTextMax
                           ' sLine = sLine & Left$(StrConv(aText, vbUnicode), lRtn) & IIf(j < ColumnCount - 1, Delimiter, vbNullString)
                            sLine = sLine & Left$(StrConv(aText, vbUnicode), _
           ListViewItem.cchTextMax) & IIf(j < ColumnCount - 1, Delimiter, vbNullString)
                        End If
                        Print #FF, i, j, sLine
                     Next
                Next
                
                ' Release virtual memory
                DestroyIPCMemory ProcessHandle, MemAddr1
    
            End If
            
            Close #FF
            
            ' Release virtual memory
            If MemAddr2 <> 0& Then DestroyIPCMemory ProcessHandle, MemAddr2
            
            CLoseIPCProcess ProcessHandle
            
            SysListView32ToCSV = True
        End If
            
        Exit Function
    ErrHandler:
        
    End Function
    Last edited by rohitb; June 3rd, 2010 at 11:59 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured