Results 1 to 6 of 6

Thread: [VB6] Undocumented ListView feature: Highlight column

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Jul 2010
    Location
    NYC
    Posts
    5,651

    Post [VB6] Undocumented ListView feature: Highlight column

    Name:  lvud1.jpg
Views: 252
Size:  56.2 KB
    Undocumented ListView Features : Part 4 - Column Back Color
    See Also: Part 1 - Footer Items | Part 2 - Subsetted Groups | Part 3 - Groups With Virtual Mode | Part 5 - Explorer-style selection



    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
    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.)

    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 Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
    
    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 Long, 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 Long, 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
    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; Jan 25th, 2022 at 01:29 AM. Reason: Added link to Part 5

  2. #2
    Fanatic Member
    Join Date
    Nov 2013
    Posts
    658

    Re: [VB6] Undocumented ListView feature: Highlight column

    Sorry if I am not supposed to post questions in threads in the codebank section .. Please, admins, delete this post if that is so.

    Hi fafalone,

    This is great. Do you you know if any other objects implement the IVisualProperties interface apart from the ListView ocx ?

    It would be great if this interface was also implemented by other COM objects such the office ribbon, dialogboxes etc ....

    Thanks.

  3. #3

    Thread Starter
    PowerPoster
    Join Date
    Jul 2010
    Location
    NYC
    Posts
    5,651

    Re: [VB6] Undocumented ListView feature: Highlight column

    Questions are fine as replies to code samples, just not as original threads, so you're all good.

    I haven't ever seen it implemented elsewhere, and couldn't find anything else searching on Google, so it looks like it's just for the ListView.

  4. #4
    Member lrd_VB6's Avatar
    Join Date
    Jul 2014
    Location
    FRANCE
    Posts
    36

    Re: [VB6] Undocumented ListView feature: Highlight column


  5. #5
    Fanatic Member
    Join Date
    Nov 2013
    Posts
    658

    Re: [VB6] Undocumented ListView feature: Highlight column

    That link just show the ListView messages... It doesn't answer the question but, thanks anyway for responding.

  6. #6
    Fanatic Member
    Join Date
    Nov 2013
    Posts
    658

    Re: [VB6] Undocumented ListView feature: Highlight column

    Quote Originally Posted by fafalone View Post
    Questions are fine as replies to code samples, just not as original threads, so you're all good.

    I haven't ever seen it implemented elsewhere, and couldn't find anything else searching on Google, so it looks like it's just for the ListView.
    Shame, no other components seem to implement this cool IVisualProperties interface. This would have been very useful for me in order to set the backcolor of individual office ribbon tabs and controls.

    Thanks.

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