VB6 select/highlight ListView Item

You can talk about VB programming here

VB6 select/highlight ListView Item

Postby autopilot » Mon Oct 15, 2007 4:51 pm


This is a function that will highlight the item at a given index value in a SysListView. You pass to it the SysListview handle and the index of the the item to highlight. It uses the same const and API declarations as to read the selected text.

The SysListView indexing is zero based, so to highlight the third item, pass an iIndex value of 2.

Code: Select all
Public Function HiLiteSLVItem(ByVal hwnd As Long, ByVal iIndex As Long)
    Dim lProcID As Long
    Dim hProc As Long
    Dim lxprocLVITEM As Long
    Dim LVITEM As LV_ITEM
    Dim lItemPos As Long
   
    GetWindowThreadProcessId hwnd, lProcID ' Get the process ID in which the ListView is running
    If lProcID <> 0 Then
        hProc = OpenProcess(PROCESS_VM_OPERATION Or PROCESS_VM_READ Or PROCESS_VM_WRITE, False, lProcID) ' makwe sure we have read write permissions in the process space
        If hProc <> 0 Then
            lxprocLVITEM = VirtualAllocEx(hProc, 0, LenB(LVITEM), MEM_RESERVE Or MEM_COMMIT, PAGE_READWRITE) ' Grab enough memory in the other procedure's space to hold our LV_ITEM
           
            ' Set up our local LV_ITEM to change the selected item
            LVITEM.mask = LVIF_STATE
            LVITEM.state = True
            LVITEM.stateMask = LVIS_SELECTED
           
            ' Copy the local LV_ITEM into the space we reserved in the foreign process
            WriteProcessMemory hProc, ByVal lxprocLVITEM, ByVal VarPtr(LVITEM), LenB(LVITEM), 0
           
            ' Now send the message, but pass the address of the copy of our LV_ITEM that now exists in the foreign process instead of our local versiony
            lItemPos = iIndex& ' index of item to highlight
            SendMessage hwnd, LVM_SETITEMSTATE, lItemPos, ByVal lxprocLVITEM
           
            ' Clean up
            VirtualFreeEx hProc, ByVal lxprocLVITEM, LenB(LVITEM), MEM_RELEASE
            CloseHandle hProc
        End If
    End If
End Function
User avatar
autopilot
Forum Moderator
Forum Moderator
 
Posts: 356
Joined: Sat Sep 23, 2006 7:19 pm

Re: VB6 select/highlight ListView Item

Postby Snoopy1968 » Tue Oct 16, 2007 9:56 am

Hey thats cool do you know how to read SystemTreeView?
Snoopy1968
imFiles Newbie
imFiles Newbie
 
Posts: 47
Joined: Fri Sep 14, 2007 8:29 pm

Re: VB6 select/highlight ListView Item

Postby method » Mon Nov 12, 2007 12:12 pm

could you upload a working vb6 that highligths and selects user name giving its position in the listview in paltalk 9.2 ? i couldn't modify my old code which was for paltalk 8.2!! Looking forward for your reply.Thanks
method
imFiles Master
imFiles Master
 
Posts: 686
Joined: Tue Oct 18, 2005 11:12 am


Return to Visual Basic Programming

 


  • Related topics
    Replies
    Views
    Last post

Who is online

Users browsing this forum: No registered users and 0 guests