Results 1 to 6 of 6

Thread: [VB6] Undocumented ListView feature: Highlight column

Threaded View

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Jul 2010
    Location
    NYC
    Posts
    7,653

    Post [VB6] Undocumented ListView feature: Highlight column




    About
    ListView message handling for NM_CUSTOMDRAW is documented in many projects, and while using that method you could manually set the background color of all desired items, it's also possible to automatically set the background color of a given column without subclassing/handling that message, with just a few simple lines.

    Requirements
    VB6:
    oleexp.tlb v4.0 or higher
    (Note: I'm unsure if this will work with MSComctlLib 6.0 ListViews, definitely provide feedback if not working.)
    (Note: This uses a general, documented, interface, IVisualProperties, that was not included in lvundoc.tlb, so that lib would not be enough.)
    twinBASIC:
    Windows Development Library for twinBASIC

    Code
    This one, like subsetted groups, is so simple I'm just presenting it as a code snippet rather than full demo project (but if you'd really like one, LMK).
    Code:
    Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As LongPtr, ByVal wMsg As Long, ByVal wParam As LongPtr, lParam As Any) As LongPtr
    
    Private Const LVM_FIRST = &H1000
    Private Const LVM_SETSELECTEDCOLUMN = (LVM_FIRST + 140)
    Private Const LVM_QUERYINTERFACE = (LVM_FIRST + 189)      'UNDOCUMENTED: NOT OFFICIAL NAME
    
    Public Sub HighlightColumn(hLV As LongPtr, nColumn As Long, clrBack As Long)
    If nColumn = -1 Then
        SendMessage hLV, LVM_SETSELECTEDCOLUMN, -1&, ByVal 0&
        Exit Sub
    End If
    ColumnSetBk nColumn, clrBack
    End Sub
    Private Sub ColumnSetBk(hLV As LongPtr, nCol As Long, clr As Long)
    Dim pVis As IVisualProperties
    SendMessage hLV, LVM_QUERYINTERFACE, VarPtr(IID_IVisualProperties), pVis
    If (pVis Is Nothing) Then
        Debug.Print "HighlightColumn::Failed to get IVisualProperties"
        Exit Sub
    End If
    pVis.SetColor VPCF_SORTCOLUMN, clr
    
    SendMessage hLV, LVM_SETSELECTEDCOLUMN, nCol, ByVal 0&
    End Sub
    
    'The following is not needed if your project includes mIID.bas or uses WinDevLib 
    Private Sub DEFINE_UUID(Name As UUID, l As Long, w1 As Integer, w2 As Integer, B0 As Byte, b1 As Byte, b2 As Byte, B3 As Byte, b4 As Byte, b5 As Byte, b6 As Byte, b7 As Byte)
      With Name
        .Data1 = l
        .Data2 = w1
        .Data3 = w2
        .Data4(0) = B0
        .Data4(1) = b1
        .Data4(2) = b2
        .Data4(3) = B3
        .Data4(4) = b4
        .Data4(5) = b5
        .Data4(6) = b6
        .Data4(7) = b7
      End With
    End Sub
    
    Private Function IID_IVisualProperties() As UUID
    '{e693cf68-d967-4112-8763-99172aee5e5a}
    Static IID As UUID
     If (IID.Data1 = 0&) Then Call DEFINE_UUID(IID, &HE693CF68, CInt(&HD967), CInt(&H4112), &H87, &H63, &H99, &H17, &H2A, &HEE, &H5E, &H5A)
    IID_IVisualProperties = IID
    End Function
    Just call HighlightColumn with the ListView hWnd, the zero-based column index, and desired color. It's that simple
    As an aside, it seems that none of the other IVisualProperties methods seem to work.


    ----
    Semi-related, sorry guys, I never managed to figure out how to get subitem controls working in VB6. I take a shot every one in a while, but the code I'm going off of uses a bunch of odd memory-related calls that it seems just don't work the same in VB6... if you know anything about translating C code that uses HeapAlloc, GetAtomName, GetProp(,#43280) and why those might fail in a direct port... please contact me.
    PS- If you were following this issue from here or similar... I misinterpreted things with Timo. He finally did release the source code to his ListView with subitem controls, since it was an ActiveX .ocx being shown in VB projects, I presumed the control was written in VB. It wasn't. So it's of no help beyond the demo, it's all in C.
    Last edited by fafalone; Mar 8th, 2026 at 11:06 PM. Reason: Update for tB/x64 compatibility

Tags for this Thread

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