home *** CD-ROM | disk | FTP | other *** search
/ Planet Source Code Jumbo …e CD Visual Basic 1 to 7 / 1_2002.ISO / Data / Zips / CODE_UPLOAD7555792000.psc / VBRecentProjects / modListView.bas < prev    next >
Encoding:
BASIC Source File  |  2000-06-13  |  8.3 KB  |  252 lines

  1. Attribute VB_Name = "modListView"
  2.  
  3. Option Explicit
  4.  
  5. Public Type LVBKIMAGE
  6.   ulFlags As Long ' Tiled or normal etc
  7.   hBitmap As Long ' Handle to the bitmap
  8.   pszImage As String ' File Name of bitmap
  9.   cchImageMax As Long ' Size of bitmap
  10.   xOffsetPercent As Long ' X Offset to display (if not tiled)
  11.   yOffsetPercent As Long ' Y Offset to display (if not tiled)
  12. End Type
  13.  
  14. Public Const LVM_FIRST = &H1000
  15. Public Const LVM_SETCOLUMNWIDTH As Long = LVM_FIRST + 30
  16. Public Const LVM_GETHEADER = (LVM_FIRST + 31)
  17. Public Const LVM_GETCOUNTPERPAGE = (LVM_FIRST + 40)
  18. Public Const LVM_SETITEMSTATE = (LVM_FIRST + 43)
  19. Public Const LVM_GETITEMSTATE As Long = (LVM_FIRST + 44)
  20. Public Const LVM_GETSELECTEDCOUNT = (LVM_FIRST + 50)
  21. Public Const LVIS_SELECTED = &H2
  22. Public Const LVIF_STATE = &H8
  23. Public Const LVIS_STATEIMAGEMASK As Long = &HF000
  24. Public Const GWL_STYLE = (-16)
  25. Public Const HDS_HOTTRACK = &H4
  26. Public Const LVM_SETTEXTBKCOLOR = (LVM_FIRST + 38)
  27. Public Const LVM_SETBKIMAGE = (LVM_FIRST + 68)
  28. Public Const CLR_NONE = &HFFFFFFFF
  29.  
  30. '--- ListView Header
  31. Public Const HDI_BITMAP = &H10
  32. Public Const HDI_IMAGE = &H20
  33. Public Const HDI_ORDER = &H80
  34. Public Const HDI_FORMAT = &H4
  35. Public Const HDI_TEXT = &H2
  36. Public Const HDI_WIDTH = &H1
  37. Public Const HDI_HEIGHT = HDI_WIDTH
  38. Public Const HDF_LEFT = 0
  39. Public Const HDF_RIGHT = 1
  40. Public Const HDF_IMAGE = &H800
  41. Public Const HDF_BITMAP_ON_RIGHT = &H1000
  42. Public Const HDF_BITMAP = &H2000
  43. Public Const HDF_STRING = &H4000
  44. Public Const HDM_FIRST = &H1200
  45. Public Const HDM_SETITEM = (HDM_FIRST + 4)
  46. Public Const HDS_BUTTONS = &H2
  47. Public Const SWP_DRAWFRAME = &H20
  48. Public Const SWP_NOMOVE = &H2
  49. Public Const SWP_NOSIZE = &H1
  50. Public Const SWP_NOZORDER = &H4
  51. Public Const SWP_FLAGS = SWP_NOZORDER Or SWP_NOSIZE Or SWP_NOMOVE Or SWP_DRAWFRAME
  52.  
  53. '--- ListView Item
  54. Public Type LVItem
  55.   mask As Long
  56.   iItem As Long
  57.   iSubItem As Long
  58.   state As Long
  59.   stateMask As Long
  60.   pszText As String
  61.   cchTextMax As Long
  62.   iImage As Long
  63.   lParam As Long
  64.   iIndent As Long
  65. End Type
  66.  
  67. '--- ListView Header Item
  68. Private Type HD_ITEM
  69.   mask        As Long
  70.   cxy         As Long
  71.   pszText     As String
  72.   hbm         As Long
  73.   cchTextMax  As Long
  74.   fmt         As Long
  75.   lParam      As Long
  76.   iImage      As Long
  77.   iOrder      As Long
  78. End Type
  79.  
  80. '--- ListView Set Column Width Messages ---'
  81. Public Enum LVSCW_Styles
  82.   LVSCW_AUTOSIZE = -1
  83.   LVSCW_AUTOSIZE_USEHEADER = -2
  84. End Enum
  85.  
  86. '--- Rectangle ---
  87. Public Type RECT
  88.   Left   As Long
  89.   Top    As Long
  90.   Right  As Long
  91.   Bottom As Long
  92. End Type
  93.  
  94. Public Declare Function LockWindowUpdate Lib "user32" (ByVal hWndLock As Long) As Long
  95. Public Declare Function SendMessageLong Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
  96. Public Declare Function SendMessageAny Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal Msg As Long, ByVal wParam As Long, lParam As Any) As Long
  97. Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
  98. Public Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long) As Long
  99. Public Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
  100. Public Declare Function SetWindowPos Lib "user32" (ByVal hWnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
  101.  
  102. Public Function SelectLVItems(LV As ListView, Optional SelectLV As Boolean = True) As Long
  103.   Dim LVItem As LVItem
  104.  
  105. On Error GoTo ErrorHandler
  106.   With LVItem
  107.     .mask = LVIF_STATE
  108.     .state = SelectLV
  109.     .stateMask = LVIS_SELECTED
  110.   End With
  111.      
  112.  'By setting wParam to -1, the call affects all
  113.  'ListItems. To just change a particular item, pass its index as wParam.
  114.   Call SendMessageAny(LV.hWnd, LVM_SETITEMSTATE, -1, LVItem)
  115.  
  116.  'Update the result
  117.   SelectLVItems = SendMessageLong(LV.hWnd, LVM_GETSELECTEDCOUNT, 0&, 0&)
  118. Exit Function
  119.  
  120. ErrorHandler:
  121.   Err.Clear
  122. End Function
  123.  
  124. Public Sub ShowLVHeaderIcon(LV As ListView, _
  125.                             ColNo As Long, _
  126.                             imgIconNo As Long, _
  127.                             Justify As Long, _
  128.                             ShowImage As Long)
  129.   Dim r As Long
  130.   Dim hHeader As Long
  131.   Dim HD As HD_ITEM
  132.   
  133.   'get a handle to the listview header component
  134.   hHeader = SendMessageLong(LV.hWnd, LVM_GETHEADER, 0, 0)
  135.   
  136.   'set up the required structure members
  137.   With HD
  138.     .mask = HDI_IMAGE Or HDI_FORMAT
  139.     .fmt = HDF_LEFT Or HDF_STRING Or Justify Or ShowImage
  140.     .pszText = LV.ColumnHeaders(ColNo + 1).Text
  141.     If ShowImage Then .iImage = imgIconNo
  142.   End With
  143.   
  144.   'Modify the header
  145.   r = SendMessageAny(hHeader, HDM_SETITEM, ColNo, HD)
  146. End Sub
  147.  
  148. Public Sub SetLVHeaderHotTrack(LV As ListView)
  149.   Dim r As Long
  150.   Dim hHeader As Long
  151.   Dim rstyle As Long
  152.    
  153.   'get a handle to the listview header component
  154.    hHeader = SendMessageLong(LV.hWnd, LVM_GETHEADER, 0, 0)
  155.    
  156.   'retrieve the current style of the header
  157.    rstyle = GetWindowLong(hHeader, GWL_STYLE)
  158.    
  159.   'set/toggle the hottrack style attribute
  160.    rstyle = rstyle Xor HDS_HOTTRACK
  161.  
  162.   'set the header style
  163.    Call SetWindowLong(hHeader, GWL_STYLE, rstyle)
  164. End Sub
  165.  
  166. Public Sub SetLVFlatHeaders(MyParent_hWnd As Long, LV As ListView)
  167.  
  168.   Dim Style As Long
  169.   Dim hHeader As Long
  170.    
  171.  'get the handle to the listview header
  172.   hHeader = SendMessageLong(LV.hWnd, LVM_GETHEADER, 0, ByVal 0&)
  173.   
  174.  'get the current style attributes for the header
  175.   Style = GetWindowLong(hHeader, GWL_STYLE)
  176.   
  177.  'modify the style by toggling the HDS_BUTTONS style
  178.   Style = Style Xor HDS_BUTTONS
  179.   
  180.  'set the new style and redraw the listview
  181.   If Style Then
  182.      Call SetWindowLong(hHeader, GWL_STYLE, Style)
  183.      Call SetWindowPos(LV.hWnd, MyParent_hWnd, 0, 0, 0, 0, SWP_FLAGS)
  184.   End If
  185. End Sub
  186.  
  187. Public Sub LVSetColWidth(LV As ListView, ByVal ColumnIndex As Long, ByVal Style As LVSCW_Styles)
  188.   '------------------------------------------------------------------------------
  189.   '--- If you include the header in the sizing then the last column will
  190.   '--- automatically size to fill the remaining listview width.
  191.   '------------------------------------------------------------------------------
  192.   With LV
  193.      ' verify that the listview is in report view and that the column exists
  194.      If .View = lvwReport Then
  195.         If ColumnIndex >= 1 And ColumnIndex <= .ColumnHeaders.Count Then
  196.           Call SendMessage(.hWnd, LVM_SETCOLUMNWIDTH, ColumnIndex - 1, ByVal Style)
  197.         End If
  198.      End If
  199.   End With
  200. End Sub
  201.  
  202. Public Sub LVSetAllColWidths(LV As ListView, ByVal Style As LVSCW_Styles)
  203.   Dim ColumnIndex As Long
  204.   '--- loop through all of the columns in the listview and size each
  205.   With LV
  206.     For ColumnIndex = 1 To .ColumnHeaders.Count
  207.       LVSetColWidth LV, ColumnIndex, Styleers.CoLVSet Eaders.Count
  208.      ,mnIndex, Styleers.CoLVSet Eaders.Count
  209.      ,mnIndex, Styleers.CoLV Wnd,vwRWidnt
  210. LVSet Eaders.Count
  211.      ,mnIndex, Styleers.CoLV Wnd,vwRWidnt
  212. LVSet Ea1s_as.CoH1000a-------ByVwTSf
  213.   
  214.   'setEnd Sub
  215.  
  216. Pubt---ByVwTSf
  217.  Dpub
  218.  
  219. Pubt---B CGse, LVM_GETHEADEE------------------nAItuOE Sub
  220.  
  221. Pubt---ByVwTSug  GoT---nAItuOE Sub
  222.  
  223. Pubt---ByVwTSug  GoT---nAItuOE Sub
  224.  
  225. Pubt---ByVwTSug  GoT---nAItuOE Sub
  226.  
  227. PueSrs.Count
  228.      ,mnIn----- SuyVwTSlumnHeponent
  229.   h  GF0
  230.  
  231. PueSrs.Ang
  232.   pszText As String
  233.   cchTepTSubrs.yf
  234.  Dpub---ByVwTSdng
  235. f StyMer:.CoLR opub---BlumnHeaders.Count Then
  236.           Call ITEM, CAText As String
  237.   Val Stext As String
  238.   VpA, Ls Stri
  239.           Call ITEM, CAText As St,--B C=nd,vwRWidnt
  240. L-oLl'setEnt
  241. L-oLl'setEnt
  242. L-bt-te-----------------------HaRsext VTnTL-bt-te-AText As St,--B C=nd,vwRWimdnt
  243. L-oLl'setESL-oLl'sep thegt St,-- 1 To .ColumnHeL-
  244. "dL-oLlR'tBsgCGse, LVM_GOa-------ByVwTSf
  245.   ----ByVwTSf
  246.   ----ByVwTSf
  247. tylVtrSug  GoT-, LVMeCGseHlb
  248. Pe-----der = S, ByVal SceCGs,w2, BByVal SceCi
  249.  
  250. PuCPe-----der = S, )RedPmnHeaders.Cdnt
  251. e"0 GOa-------ByVwTSf
  252.   ----ByVwegt0ehe heade--ByVwTSf
  253.   ----P.yVwTSf
  254.   -Rnt
  255. e"0 
  256.   ----ByVwegoLR opwte heVwTgyVwTSd
  257.   --- ITEM, CAText As St, .Eig
  258. f StyMer:.CoLR ot-BlumnHe"e VpA, NVwTSe, 0, 00ex >= 1 And Cols St, .EigVwTSf
  259.   -eng---"0 
  260. l wParamopu