1 Attachment(s)
[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 :thumb:
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.
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.
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.
Re: [VB6] Undocumented ListView feature: Highlight column
Re: [VB6] Undocumented ListView feature: Highlight column
Quote:
Originally Posted by
lrd_VB6
That link just show the ListView messages... It doesn't answer the question but, thanks anyway for responding.
Re: [VB6] Undocumented ListView feature: Highlight column
Quote:
Originally Posted by
fafalone
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.