home *** CD-ROM | disk | FTP | other *** search
/ Planet Source Code Jumbo …e CD Visual Basic 1 to 7 / 1_2002.ISO / Data / Zips / CODE_UPLOAD80587232000.psc / modListViewEnh.bas < prev    next >
Encoding:
BASIC Source File  |  2000-07-23  |  11.5 KB  |  443 lines

  1. Attribute VB_Name = "modListViewEnh"
  2.  
  3.  
  4. '=====
  5. ' needed for Enhancements
  6. Private Const LVIS_STATEIMAGEMASK As Long = &HF000
  7.  
  8. Private Type LVITEM
  9.     mask         As Long
  10.     iItem        As Long
  11.     iSubItem     As Long
  12.     state        As Long
  13.     stateMask    As Long
  14.     pszText      As String
  15.     cchTextMax   As Long
  16.     iImage       As Long
  17.     lParam       As Long
  18.     iIndent      As Long
  19. End Type
  20.  
  21. Const SWP_DRAWFRAME = &H20
  22. Const SWP_NOMOVE = &H2
  23. Const SWP_NOSIZE = &H1
  24. Const SWP_NOZORDER = &H4
  25.  
  26. Private Const LVS_EX_FULLROWSELECT = &H20
  27. Private Const LVS_EX_GRIDLINES = &H1
  28. Private Const LVS_EX_CHECKBOXES As Long = &H4
  29. Private Const LVS_EX_HEADERDRAGDROP = &H10
  30. Private Const LVS_EX_TRACKSELECT = &H8
  31. Private Const LVS_EX_ONECLICKACTIVATE = &H40
  32. Private Const LVS_EX_TWOCLICKACTIVATE = &H80
  33. Private Const LVS_EX_SUBITEMIMAGES = &H2
  34.  
  35. Private Const LVM_FIRST = &H1000
  36. Private Const LVM_SETEXTENDEDLISTVIEWSTYLE = LVM_FIRST + 54
  37. Private Const LVM_GETEXTENDEDLISTVIEWSTYLE = LVM_FIRST + 55
  38. Private Const LVM_GETHEADER = (LVM_FIRST + 31)
  39.  
  40. Public Const LVIF_STATE = &H8
  41. Public Const LVM_SETITEMSTATE = (LVM_FIRST + 43)
  42. Public Const LVM_GETITEMSTATE As Long = (LVM_FIRST + 44)
  43.  
  44. Private Const HDS_BUTTONS = &H2
  45. Private Const GWL_STYLE = (-16)
  46.  
  47. Private Const SWP_FLAGS = SWP_NOZORDER Or SWP_NOSIZE Or SWP_NOMOVE Or SWP_DRAWFRAME
  48.  
  49. Public Declare Function SendMessageAny _
  50.                         Lib "user32" _
  51.                         Alias "SendMessageA" _
  52.                         (ByVal hwnd As Long, _
  53.                         ByVal Msg As Long, _
  54.                         ByVal wParam As Long, _
  55.                         lParam As Any) _
  56.                         As Long
  57.  
  58. Private Declare Function SendMessageLong Lib _
  59.                         "user32" Alias _
  60.                         "SendMessageA" _
  61.                         (ByVal hwnd As Long, _
  62.                         ByVal Msg As Long, _
  63.                         ByVal wParam As Long, _
  64.                         ByVal lParam As Long) _
  65.                         As Long
  66.                         
  67. Private Declare Function GetWindowLong _
  68.                         Lib "user32" _
  69.                         Alias "GetWindowLongA" _
  70.                         (ByVal hwnd As Long, _
  71.                         ByVal nIndex As Long) _
  72.                         As Long
  73.                         
  74. Private Declare Function SetWindowLong _
  75.                         Lib "user32" _
  76.                         Alias "SetWindowLongA" _
  77.                         (ByVal hwnd As Long, _
  78.                         ByVal nIndex As Long, _
  79.                         ByVal dwNewLong As Long) _
  80.                         As Long
  81.                         
  82. Private Declare Function SetWindowPos _
  83.                         Lib "user32" _
  84.                         (ByVal hwnd As Long, _
  85.                         ByVal hWndInsertAfter As Long, _
  86.                         ByVal x As Long, _
  87.                         ByVal Y As Long, _
  88.                         ByVal cx As Long, _
  89.                         ByVal cy As Long, _
  90.                         ByVal wFlags As Long) _
  91.                         As Long
  92. '=====
  93.  
  94. '=====
  95. Public LengthPerCharacter As Long
  96. '=====
  97.  
  98.  
  99.  
  100.  
  101.  
  102.  
  103.  
  104.  
  105. '=====
  106. ' Description: Enables SubItem Images in a ListView
  107. '=====
  108. Public Function EnhListView_Add_SubitemImages( _
  109.                 lstListViewName As ListView, _
  110.                 Optional bolShowErrors As Boolean) _
  111.                 As Boolean
  112.     
  113.     '
  114.     ' initiate error handler
  115.     On Error GoTo err_EnhListView_Add_SubitemImages
  116.     
  117.     '
  118.     ' set function return to true
  119.     EnhListView_Add_SubitemImages = True
  120.     
  121.     '
  122.     ' setup variables
  123.     Dim rStyle  As Long
  124.     Dim r       As Long
  125.     
  126.     '
  127.     ' get the current styles
  128.     rStyle = SendMessageLong(lstListViewName.hwnd, LVM_GETEXTENDEDLISTVIEWSTYLE, 0&, 0&)
  129.     
  130.     '
  131.     ' add the selected style to the current styles
  132.     rStyle = rStyle Or LVS_EX_SUBITEMIMAGES
  133.     
  134.     '
  135.     ' update the listview styles
  136.     SendMessageLong lstListViewName.hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, 0&, rStyle
  137.     
  138.     '
  139.     ' exit before error handler
  140.     Exit Function
  141.     
  142. '
  143. ' deal with errors
  144. err_EnhListView_Add_SubitemImages:
  145.     
  146.     '
  147.     ' set function return to false
  148.     EnhListView_Add_SubitemImages = False
  149.     '
  150.     ' if you want notification on an error
  151.     If bolShowErrors = True Then
  152.  
  153.     End If
  154.     
  155.     '
  156.     ' initiate debug
  157.     Debug.Print Now & vbTab & "Error in function: EnhListView_Add_SubitemImages" _
  158.                 & vbCrLf & _
  159.                 Err.Number & vbTab & Err.Description
  160.     Debug.Assert False
  161.     
  162.     '
  163.     ' exit
  164.     Exit Function
  165.     
  166. End Function
  167. '=====
  168.  
  169.  
  170.  
  171. '=====
  172. ' Description: Checks all Items in the ListView
  173. '=====
  174. Public Function EnhLitView_CheckAllItems( _
  175.                 lstListViewName As ListView, _
  176.                 Optional bolShowErrors As Boolean) _
  177.                 As Boolean
  178.     
  179.     '
  180.     ' initiate error handler
  181.     On Error GoTo err_EnhLitView_CheckAllItems
  182.     
  183.     '
  184.     ' set function return to true
  185.     EnhLitView_CheckAllItems = True
  186.     
  187.     '
  188.     ' setup variables
  189.     Dim LV          As LVITEM
  190.     Dim lvCount     As Long
  191.     Dim lvIndex     As Long
  192.     Dim lvState     As Long
  193.     Dim r           As Long
  194.     
  195.     '
  196.     lvState = IIf(True, &H2000, &H1000)
  197.     lvCount = lstListViewName.ListItems.Count - 1
  198.     Do
  199.         With LV
  200.             .mask = LVIF_STATE
  201.             .state = lvState
  202.             .stateMask = LVIS_STATEIMAGEMASK
  203.         End With
  204.         r = SendMessageAny(lstListViewName.hwnd, LVM_SETITEMSTATE, lvIndex, LV)
  205.         lvIndex = lvIndex + 1
  206.     Loop Until lvIndex > lvCount
  207.     
  208.     '
  209.     ' exit before error handler
  210.     Exit Function
  211.     
  212. '
  213. ' deal with errors
  214. err_EnhLitView_CheckAllItems:
  215.     
  216.     '
  217.     ' set function return to false
  218.     EnhLitView_CheckAllItems = False
  219.     '
  220.     ' if you want notification on an error
  221.     If bolShowErrors = True Then
  222.  
  223.     End If
  224.     
  225.     '
  226.     ' initiate debug
  227.     Debug.Print Now & vbTab & "Error in function: EnhLitView_CheckAllItems" _
  228.                 & vbCrLf & _
  229.                 Err.Number & vbTab & Err.Description
  230.     Debug.Assert False
  231.     
  232.     '
  233.     ' exit
  234.     Exit Function
  235.     
  236. End Function
  237. '=====
  238.  
  239. '=====
  240. ' Description: Unchecks all items in a ListView
  241. '=====
  242. Public Function EnhLitView_UnCheckAllItems( _
  243.                 lstListViewName As ListView, _
  244.                 Optional bolShowErrors As Boolean) _
  245.                 As Boolean
  246.     
  247.     '
  248.     ' initiate error handler
  249.     On Error GoTo err_EnhLitView_UnCheckAllItems
  250.     
  251.     '
  252.     ' set function return to true
  253.     EnhLitView_UnCheckAllItems = True
  254.     
  255.     '
  256.     ' setup variables
  257.     Dim LV          As LVITEM
  258.     Dim lvCount     As Long
  259.     Dim lvIndex     As Long
  260.     Dim lvState     As Long
  261.     Dim r           As Long
  262.     
  263.     '
  264.     lvState = IIf(True, &H2000, &H1000)
  265.     lvCount = lstListViewName.ListItems.Count - 1
  266.     Do
  267.         With LV
  268.             .mask = LVIF_STATE
  269.             .state = lvState
  270.             .stateMask = LVIS_STATEIMAGEMASK
  271.         End With
  272.         r = SendMessageAny(lstListViewName.hwnd, LVM_SETITEMSTATE, lvIndex, LV)
  273.         lvIndex = lvIndex + 1
  274.     Loop Until lvIndex > lvCount
  275.     
  276.     '
  277.     ' exit before error handler
  278.     Exit Function
  279.     
  280. '
  281. ' deal with errors
  282. err_EnhLitView_UnCheckAllItems:
  283.     
  284.     '
  285.     ' set function return to false
  286.     EnhLitView_UnCheckAllItems = False
  287.     '
  288.     ' if you want notification on an error
  289.     If bolShowErrors = True Then
  290.  
  291.     End If
  292.     
  293.     '
  294.     ' initiate debug
  295.     Debug.Print Now & vbTab & "Error in function: EnhLitView_UnCheckAllItems" _
  296.                 & vbCrLf & _
  297.                 Err.Number & vbTab & Err.Description
  298.     Debug.Assert False
  299.     
  300.     '
  301.     ' exit
  302.     Exit Function
  303.     
  304. End Function
  305. '=====
  306.  
  307.  
  308. '=====
  309. ' Description: Inverts all checked items in a ListView
  310. '=====
  311. Public Function EnhListView_InvertAllChecks( _
  312.                 lstListViewName As ListView, _
  313.                 Optional bolShowErrors As Boolean) _
  314.                 As Boolean
  315.     
  316.     '
  317.     ' initiate error handler
  318.     On Error GoTo err_EnhListView_InvertAllChecks
  319.     
  320.     '
  321.     ' set function return to true
  322.     EnhListView_InvertAllChecks = True
  323.     
  324.     '
  325.     ' setup variables
  326.     Dim LV          As LVITEM
  327.     Dim r           As Long
  328.     Dim lvCount     As Long
  329.     Dim lvIndex     As Long
  330.     
  331.     '
  332.     lvCount = lstListViewName.ListItems.Count - 1
  333.     Do
  334.         r = SendMessageLong(lstListViewName.hwnd, LVM_GETITEMSTATE, lvIndex, LVIS_STATEIMAGEMASK)
  335.         With LV
  336.             .mask = LVIF_STATE
  337.             .stateMask = LVIS_STATEIMAGEMASK
  338.             If r And &H2000& Then
  339.                 .state = &H1000
  340.             Else
  341.                 .state = &H2000
  342.             End If
  343.         End With
  344.         r = SendMessageAny(lstListViewName.hwnd, LVM_SETITEMSTATE, lvIndex, LV)
  345.         lvIndex = lvIndex + 1
  346.     Loop Until lvIndex > lvCount
  347.     
  348.     '
  349.     ' exit before error handler
  350.     Exit Function
  351.     
  352. '
  353. ' deal with errors
  354. err_EnhListView_InvertAllChecks:
  355.     
  356.     '
  357.     ' set function return to false
  358.     EnhListView_InvertAllChecks = False
  359.     '
  360.     ' if you want notification on an error
  361.     If bolShowErrors = True Then
  362.  
  363.     End If
  364.     
  365.     '
  366.     ' initiate debug
  367.     Debug.Print Now & vbTab & "Error in function: EnhListView_InvertAllChecks" _
  368.                 & vbCrLf & _
  369.                 Err.Number & vbTab & Err.Description
  370.     Debug.Assert False
  371.     
  372.     '
  373.     ' exit
  374.     Exit Function
  375.     
  376. End Function
  377. '=====
  378.  
  379. '=====
  380. ' Description: Toggles FlatColumnHeaders in a ListView
  381. '=====
  382. Public Function EnhListView_Toggle_FlatColumnHeaders( _
  383.                 frmFormName As Form, _
  384.                 lstListViewName As ListView, _
  385.                 Optional bolShowErrors As Boolean) _
  386.                 As Boolean
  387.     
  388.     '
  389.     ' initiate error handler
  390.     On Error GoTo err_EnhListView_Toggle_FlatColumnHeaders
  391.     
  392.     '
  393.     ' set function return to true
  394.     EnhListView_Toggle_FlatColumnHeaders = True
  395.     
  396.     '
  397.     SetWindowLong SendMessageLong(lstListViewName.hwnd, _
  398.                                  LVM_GETHEADER, _
  399.                                  0, _
  400.                                  ByVal 0&), _
  401.                                  GWL_STYLE, _
  402.                                  GetWindowLong(SendMessageLong(lstListViewName.hwnd, _
  403.                                                                LVM_GETHEADER, _
  404.                                                                0, _
  405.                                                                ByVal _
  406.                                                                0&), _
  407.                                                                GWL_STYLE) _
  408.                                                                Xor HDS_BUTTONS
  409.     SetWindowPos lstListViewName.hwnd, _
  410.                  frmFormName.hwnd, _
  411.                  0, _
  412.                  0, _
  413.                  0, _
  414.                  0, _
  415.                  SWP_FLAGS
  416.     
  417.     '
  418.     ' exit before error handler
  419.     Exit Function
  420.     
  421. '
  422. ' deal with errors
  423. err_EnhListView_Toggle_FlatColumnHeaders:
  424.     
  425.     '
  426.     ' set function return to false
  427.     EnhListView_Toggle_FlatColumnHeaders = False
  428.     '
  429.  
  430.     If bolShowErrors = True Then
  431.  
  432.     End If
  433.     
  434.     Debug.Print Now & vbTab & "Error in function: EnhListView_Toggle_FlatColumnHeaders" _
  435.                 & vbCrLf & _
  436.                 Err.Number & vbTab & Err.Description
  437.     Debug.Assert False
  438.  
  439.     Exit Function
  440.     
  441. End Function
  442.  
  443.