Find all our projects in development below.
All source code is GNU General Public License (GPL)
Browsing QuickQuery HL Edition/ListViewFunctionsMod.bas (3.45 KB)
Attribute VB_Name = "ListViewFunctionsMod"
Private Const LVM_FIRST = &H1000
Private Const LVM_DELETEITEM = (LVM_FIRST + 8)
Private Const LVM_GETITEMSTATE = (LVM_FIRST + 44)
Private Const LVM_SETITEMSTATE = (LVM_FIRST + 43)
Private Const LVM_GETITEMTEXT = (LVM_FIRST + 45)
Private Const LVIF_TEXT = &H1
Private Const LVIF_STATE = &H8
Private Const LVIS_STATEIMAGEMASK = &HF000
Private Const LVM_HITTEST = (LVM_FIRST + 18)
Private Const LVM_SUBITEMHITTEST = (LVM_FIRST + 57)
Private Const LVHT_NOWHERE = &H1
Private Const LVHT_ONITEMICON = &H2
Private Const LVHT_ONITEMLABEL = &H4
Private Const LVHT_ONITEMSTATEICON = &H8
Private Const LVHT_ONITEM = (LVHT_ONITEMICON Or LVHT_ONITEMLABEL Or LVHT_ONITEMSTATEICON)
Private Type POINTAPI
X As Long
Y As Long
End Type
Private Type LVHITTESTINFO
pt As POINTAPI
flags As Long
iItem As Long
iSubItem As Long
End Type
Private Type LV_ITEM
mask As Long
iItem As Long
iSubItem As Long
state As Long
stateMask As Long
pszText As String
cchTextMax As Long
iImage As Long
lParam As Long
iIndent As Long
End Type
Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Private Declare Function ScreenToClient Lib "user32" (ByVal hWnd As Long, lpPoint As POINTAPI) As Long
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Public Function LV_DeleteItem(ListViewObj As ListView, ByVal hIndex As Long) As Long
LV_DeleteItem = SendMessage(ListViewObj.hWnd, LVM_DELETEITEM, hIndex, 0&)
End Function
Public Function LV_GetSelectedItem(ListViewObj As ListView) As Long
Dim HTI As LVHITTESTINFO
Dim pt As POINTAPI
GetCursorPos pt
ScreenToClient ListViewObj.hWnd, pt
With HTI
.pt.X = pt.X
.pt.Y = pt.Y
.flags = LVHT_ONITEM
End With
SendMessage ListViewObj.hWnd, LVM_SUBITEMHITTEST, 0&, HTI
LV_GetSelectedItem = HTI.iItem
End Function
Public Function LV_IsItemChecked(hWnd As Long, ByVal hIndex As Long) As Boolean
LV_IsItemChecked = SendMessage(hWnd, LVM_GETITEMSTATE, hIndex, ByVal LVIS_STATEIMAGEMASK) And &H2000&
End Function
Public Sub LV_GetCheckedItems(ListViewObj As ListView, iArray() As Long)
Dim i As Long
ReDim iArray(0)
For i = 0 To ListViewObj.ListItems.Count - 1
If SendMessage(ListViewObj.hWnd, LVM_GETITEMSTATE, i, ByVal LVIS_STATEIMAGEMASK) And &H2000& Then
ReDim Preserve iArray(UBound(iArray) + 1)
iArray(UBound(iArray)) = i
End If
Next i
End Sub
Public Function LV_GetItemValue(ListViewObj As ListView, ByVal hIndex As Long, ByVal iSubItem As Long) As String
Dim objItem As LV_ITEM
Dim RetVal As Long
objItem.mask = LVIF_TEXT
objItem.iSubItem = iSubItem
objItem.pszText = Space(128)
objItem.cchTextMax = Len(objItem.pszText)
RetVal = SendMessage(ListViewObj.hWnd, LVM_GETITEMTEXT, hIndex, objItem)
If RetVal > 0 Then LV_GetItemValue = Left(objItem.pszText, RetVal)
End Function
Public Function LV_CheckItem(ListViewObj As ListView, ByVal hIndex As Long, ByVal bState As Boolean) As Long
Dim LV As LV_ITEM
With LV
.mask = LVIF_STATE
.state = IIf(bState, &H2000, &H1000)
.stateMask = LVIS_STATEIMAGEMASK
End With
LV_CheckItem = SendMessage(ListViewObj.hWnd, LVM_SETITEMSTATE, hIndex, LV)
End Function
Download QuickQuery HL Edition/ListViewFunctionsMod.bas