Click here to Skip to main content
15,886,199 members
Articles / Programming Languages / Visual Basic

Explorer ComboBox and ListView in VB.NET

Rate me:
Please Sign up or sign in to vote.
4.88/5 (53 votes)
18 Aug 2006CPOL18 min read 1M   13.2K   141  
A ComboBox (and ListView) displaying the file system, using the system image list.
Imports System.Runtime.InteropServices

Module ListViewAPI

#Region " Constants "

    'ListView Message Constants
    Friend Const LVM_FIRST As Integer = &H1000
    Friend Const LVM_SETITEMSTATE As Integer = (LVM_FIRST + 43)
    Friend Const LVM_SETBKIMAGE As Integer = (LVM_FIRST + 68)
    Friend Const LVM_SETTEXTBKCOLOR As Integer = (LVM_FIRST + 38)
    Friend Const LVM_ENABLEGROUPVIEW As Integer = (LVM_FIRST + 157)
    Friend Const LVM_INSERTGROUP As Integer = (LVM_FIRST + 145)
    Friend Const LVM_REMOVEALLGROUPS As Integer = (LVM_FIRST + 160)
    Friend Const LVM_SETITEM As Integer = (LVM_FIRST + 6)
    Friend Const LVM_SETSELECTEDCOLUMN As Integer = (LVM_FIRST + 140)
    Friend Const LVM_GETHEADER As Integer = 4127
    Friend Const LVM_SETCOLUMN As Integer = 4122
    Friend Const LVM_SETEXTENDEDLISTVIEWSTYLE As Integer = LVM_FIRST + 54

    'For WndProc
    Friend Const WM_PAINT As Integer = &HF
    Friend Const WM_NOTIFY As Integer = &H4E
    Friend Const WM_USER As Integer = &H400
    Friend Const OCM_BASE As Integer = (WM_USER + &H1C00)
    Friend Const OCM_NOTIFY As Integer = (OCM_BASE + WM_NOTIFY)
    Friend Const NM_CUSTOMDRAW As Integer = -&HC
    Friend Const CDRF_DODEFAULT As Integer = &H0

    'For Grouping
    Friend Const LVGS_NORMAL As Integer = &H0
    Friend Const LVGF_GROUPID As Integer = &H10
    Friend Const LVGF_HEADER As Integer = &H1
    Friend Const LVGF_STATE As Integer = &H4
    Friend Const LVIF_GROUPID As Integer = &H100

    'For ListItem State
    Friend Const LVIF_STATE As Integer = &H8
    Friend Const LVIS_SELECTED As Integer = &H2
    Friend Const LVIS_FOCUSED As Integer = &H1
    Friend Const LVIS_CUT As Integer = &H4

    'For BackgroundImage
    Friend Const LVBKIF_SOURCE_NONE As Integer = &H0
    Friend Const LVBKIF_SOURCE_URL As Integer = &H2
    Friend Const LVBKIF_STYLE_TILE As Integer = &H10
    Friend Const LVBKIF_STYLE_NORMAL As Integer = &H0

    'For ColumnHeader Images
    Friend Const HDM_SETIMAGELIST As Integer = 4616
    Friend Const LVCF_FMT As Integer = &H1
    Friend Const LVCF_IMAGE As Integer = &H10
    Friend Const LVCFMT_IMAGE As Integer = 2048
    Friend Const LVCF_BITMAP_ON_RIGHT As Integer = 4096
    Friend Const LVCF_STRING As Integer = 16384

    'For ToolTips
    Friend Const LVS_EX_LABELTIP As Integer = &H4000

    'For ImageList_Draw
    Friend Const ILD_NORMAL As Integer = &H0
    Friend Const ILD_TRANSPARENT As Integer = &H1
    Friend Const ILD_BLEND25 As Integer = &H2
    Friend Const ILD_SELECTED As Integer = &H4
    Friend Const ILD_MASK As Integer = &H10
    Friend Const ILD_IMAGE As Integer = &H20

    'Other...
    Friend Const CLR_NONE As Integer = -&H1

#End Region

#Region " Structures "

    <StructLayout(LayoutKind.Sequential)> _
    Friend Structure LVBKIMAGE
        Friend ulFlags As Int32
        Friend hbm As IntPtr
        Friend pszImage As String
        Friend cchImageMax As Int32
        Friend xOffsetPercent As Int32
        Friend yOffsetPercent As Int32
    End Structure

    <StructLayout(LayoutKind.Sequential)> _
    Friend Structure LVITEM
        Friend mask As Int32
        Friend iItem As Int32
        Friend iSubItem As Int32
        Friend state As Int32
        Friend stateMask As Int32
        <MarshalAs(UnmanagedType.LPWStr)> _
        Friend pszText As String
        Friend cchTextMax As String
        Friend iImage As Int32
        Friend lParam As Int32
        Friend iIndent As Int32
        Friend iGroupId As Int32
        Friend cColumns As Int32
        Friend puColumns As Int32
    End Structure

    <StructLayout(LayoutKind.Sequential, pack:=8, CharSet:=CharSet.Auto)> _
    Friend Structure LVCOLUMN
        Dim mask As Integer
        Dim fmt As Integer
        Dim cx As Integer
        Dim pszText As IntPtr
        Dim cchTextMax As Integer
        Dim iSubItem As Integer
        Dim iImage As Integer
        Dim iOrder As Integer
    End Structure

#End Region

#Region " SendMessage "

    Friend Declare Auto Function SendMessage Lib "User32.dll" (ByVal hWnd As IntPtr, ByVal Msg As Integer, _
       ByVal wParam As Integer, ByVal lParam As Integer) As IntPtr

    Friend Declare Auto Function SendMessage Lib "User32.dll" (ByVal hWnd As IntPtr, ByVal Msg As Integer, _
       ByVal wParam As Integer, ByVal lParam As IntPtr) As IntPtr

    Friend Declare Auto Function SendMessage Lib "User32.dll" (ByVal hWnd As IntPtr, ByVal Msg As Integer, _
          ByVal wParam As Integer, ByRef lParam As LVCOLUMN) As IntPtr

    Friend Declare Auto Function SendMessage Lib "user32.dll" (ByVal hWnd As IntPtr, ByVal wMsg As Int32, _
        ByVal wParam As Int32, ByRef lParam As LVBKIMAGE) As Boolean

    Friend Declare Auto Function SendMessage Lib "user32.dll" (ByVal hWnd As IntPtr, ByVal wMsg As Int32, _
       ByVal wParam As Int32, ByRef lParam As LVITEM) As Boolean

#End Region

#Region " ImageList_DrawEx "

    'Used for hidden folders in ExpCombo
    Friend Declare Function ImageList_DrawEx Lib "comctl32" (ByVal hIml As IntPtr, ByVal i As Integer, ByVal hdcDst As IntPtr, _
       ByVal x As Integer, ByVal y As Integer, ByVal dx As Integer, ByVal dy As Integer, ByVal rgbBk As Integer, _
       ByVal rgbFg As Integer, ByVal fStyle As Integer) As Integer

#End Region

End Module

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Germany Germany
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions