Quantcast
Channel: VBForums - CodeBank - Visual Basic 6 and earlier
Viewing all articles
Browse latest Browse all 1448

[VB6, Vista+] Undocumented ListView feature: Footer items

$
0
0
Ran across this nifty thing on codeproject, and successfully got it working in VB.

Tested and working with 5.0 ListView and API ListView (it will also work on krool's Common Control Replacement ListView), have not tried with 6.0 ListView and presumably it wouldn't work (Windows Common Controls 5.0 is actually the more modern control due to linkage with the real comctl32.dll, and required for a lot of modern features like this and group view). The items are present and displayed the same way in all views, including tile and group view modes. It does appear you can only add up to 4 buttons, if you add more than that NONE of them appear.

This one is a little complicated to set up, but straightforward to use. First, it requires a type library with the undocumented interfaces IListViewFooter and IListViewFooterCallback, then the latter has to be implemented by a class module. From there, more undocumented goodness: LVM_SETIMAGELIST with a wParam of 4 will set the icons used in the footer, and LVM_QUERYINTERFACE retrieves an instance of IListViewFooter.
For the purposes of this code, I'll assume you have a ListView set up already. I use the system imagelist, but you can assign any imagelist (well, api imagelist):

Code:

Public Const IID_IListViewFooter = "{F0034DA8-8A22-4151-8F16-2EBA76565BCC}"
Public Const LVM_QUERYINTERFACE = (LVM_FIRST + 189)
Public Declare Function CLSIDFromString Lib "ole32" (ByVal lpszGuid As Long, pGuid As Any) As Long
Public Type GUIDA
  Data1 As Long
  Data2 As Integer
  Data3 As Integer
  Data4(7) As Byte
End Type
Public m_himlSysSmall As Long
Public Function GetFileTypeIconIndex(ext As String) As Long
  Dim sfi As SHFILEINFO
  Dim pidl As Long
If SHGetFileInfo(ext, FILE_ATTRIBUTE_NORMAL, sfi, Len(sfi), SHGFI_SYSICONINDEX Or SHGFI_SMALLICON Or SHGFI_USEFILEATTRIBUTES) Then
    GetFileTypeIconIndex = sfi.iIcon
  End If
End Function

The code to insert items can be placed wherever, but it won't show until there's items in the ListView.
Code:

  m_himlSysSmall = GetSystemImagelist(SHGFI_SMALLICON)
    Call SendMessage(ListView1.hWnd, LVM_SETIMAGELIST, 4, ByVal m_himlSysSmall)

Dim pLVF As IListViewFooter
Dim pFtrCB As cLVFooterCallback
Set pFtrCB = New cLVFooterCallback
Dim iidLVF As GUIDA
Call CLSIDFromString(StrPtr(IID_IListViewFooter), iidLVF)

Call SendMessage(hLVS, LVM_QUERYINTERFACE, VarPtr(iidLVF), pLVF)
If (pLVF Is Nothing) Then
    Debug.Print "Failed to get LV Footer interface"
    Exit Sub
End If
Dim lFtrIco As Long
lFtrIco = GetFileTypeIconIndex(".jpg") 'just an example, it's a standard index for the assigned image list.
With pLVF
    .SetIntroText "Intro text - hello!"
    .InsertButton 0, "Test Item 1", "where does this go", lFtrIco, 2000
    .Show pFtrCB
End With

'2000' - the lParam - has no special meaning, you can store whatever Long you want there. NOTE: It must not be 0, otherwise the buttonclick/buttondelete callback events won't fire.

The attached ZIP contains the typelib, the typelib source code, a batch file to compile it from a standard VS6 install, and the class module implementing the callback. I didn't bother will a full fledged example because presumably anyone interested in this would be adding it onto an already well set-up ListView, but if really needed let me know.

Coming up next in the world of undocumented ListView: subsetted groups (link for "Display all x items"), subitem label editing, and if I'm particularly ambitious.. apparently you can use groups in full virtual mode.
Attached Files

Viewing all articles
Browse latest Browse all 1448

Trending Articles