Listview的API全集(2)--------www.mvps.org
Public Function ListView_CreateDragImage(hWnd As Long, i As Long, lpptUpLeft As POINTAPI) As Long
ListView_CreateDragImage = SendMessage(hWnd, LVM_CREATEDRAGIMAGE, ByVal i, lpptUpLeft)
End Function
Public Function ListView_GetViewRect(hWnd As Long, prc As RECT) As Boolean
ListView_GetViewRect = SendMessage(hWnd, LVM_GETVIEWRECT, 0, prc)
End Function
Public Function ListView_GetTextColor(hWnd As Long) As Long
ListView_GetTextColor = SendMessage(hWnd, LVM_GETTEXTCOLOR, 0, 0)
End Function
Public Function ListView_SetTextColor(hWnd As Long, clrText As Long) As Boolean
ListView_SetTextColor = SendMessage(hWnd, LVM_SETTEXTCOLOR, 0, ByVal clrText)
End Function
Public Function ListView_GetTextBkColor(hWnd As Long) As Long
ListView_GetTextBkColor = SendMessage(hWnd, LVM_GETTEXTBKCOLOR, 0, 0)
End Function
Public Function ListView_SetTextBkColor(hWnd As Long, clrTextBk As Long) As Boolean
ListView_SetTextBkColor = SendMessage(hWnd, LVM_SETTEXTBKCOLOR, 0, ByVal clrTextBk)
End Function
Public Function ListView_GetTopIndex(hwndLV As Long) As Long
ListView_GetTopIndex = SendMessage(hwndLV, LVM_GETTOPINDEX, 0, 0)
End Function
Public Function ListView_GetCountPerPage(hwndLV As Long) As Long
ListView_GetCountPerPage = SendMessage(hwndLV, LVM_GETCOUNTPERPAGE, 0, 0)
End Function
Public Function ListView_GetOrigin(hwndLV As Long, ppt As POINTAPI) As Boolean
ListView_GetOrigin = SendMessage(hwndLV, LVM_GETORIGIN, 0, ppt)
End Function
Public Function ListView_Update(hwndLV As Long, i As Long) As Boolean
ListView_Update = SendMessage(hwndLV, LVM_UPDATE, ByVal i, 0)
End Function
Public Function ListView_SetItemState(hwndLV As Long, i As Long, state As LVITEM_state, mask As LVITEM_state) As Boolean
Dim lvi As LVITEM
lvi.state = state
lvi.stateMask = mask
ListView_SetItemState = SendMessage(hwndLV, LVM_SETITEMSTATE, ByVal i, lvi)
End Function
Public Function ListView_GetItemState(hwndLV As Long, i As Long, mask As LVITEM_state) As Long ' LVITEM_state
ListView_GetItemState = SendMessage(hwndLV, LVM_GETITEMSTATE, ByVal i, ByVal mask)
End Function
#If (WIN32_IE >= &H300) Then
Public Function ListView_GetCheckState(hwndLV As Long, iIndex As Long) As Long ' updated
Dim dwState As Long
dwState = SendMessage(hwndLV, LVM_GETITEMSTATE, ByVal iIndex, ByVal LVIS_STATEIMAGEMASK)
ListView_GetCheckState = (dwState \ 2 ^ 12) - 1
'((((UINT)(SendMessage(hwndLV, LVM_GETITEMSTATE, ByVal i, LVIS_STATEIMAGEMASK))) >> 12) -1)
End Function
'
#End If
Public Sub ListView_GetItemText(hwndLV As Long, i As Long, iSubItem As Long, _
pszText As Long, cchTextMax As Long)
Dim lvi As LVITEM
lvi.iSubItem = iSubItem
lvi.cchTextMax = cchTextMax
lvi.pszText = pszText
SendMessage hwndLV, LVM_GETITEMTEXT, ByVal i, lvi
pszText = lvi.pszText ' fills pszText w/ pointer
End Sub
Public Sub ListView_SetItemText(hwndLV As Long, i As Long, iSubItem As Long, pszText As Long)
Dim lvi As LVITEM
lvi.iSubItem = iSubItem
lvi.pszText = pszText
SendMessage hwndLV, LVM_SETITEMTEXT, ByVal i, lvi
End Sub
Public Sub ListView_SetItemCount(hwndLV As Long, cItems As Long)
SendMessage hwndLV, LVM_SETITEMCOUNT, ByVal cItems, 0
End Sub
#If (WIN32_IE >= &H300) Then
Public Sub ListView_SetItemCountEx(hwndLV As Long, cItems As Long, dwFlags As Long)
SendMessage hwndLV, LVM_SETITEMCOUNT, ByVal cItems, ByVal dwFlags
End Sub
'
#End If
Public Function ListView_SortItems(hwndLV As Long, pfnCompare As Long, lParamSort As Long) As Boolean
ListView_SortItems = SendMessage(hwndLV, LVM_SORTITEMS, ByVal lParamSort, ByVal pfnCompare)
End Function
Public Sub ListView_SetItemPosition32(hwndLV As Long, i As Long, x As Long, y As Long)
Dim ptNewPos As POINTAPI
ptNewPos.x = x
ptNewPos.y = y
SendMessage hwndLV, LVM_SETITEMPOSITION32, ByVal i, ptNewPos
End Sub
Public Function ListView_GetSelectedCount(hwndLV As Long) As Long
ListView_GetSelectedCount = SendMessage(hwndLV, LVM_GETSELECTEDCOUNT, 0, 0)
End Function
Public Function ListView_GetItemSpacing(hwndLV As Long, fSmall As Boolean) As Long
ListView_GetItemSpacing = SendMessage(hwndLV, LVM_GETITEMSPACING, ByVal fSmall, 0)
End Function
Public Function ListView_GetISearchString(hwndLV As Long, lpsz As String) As Boolean
ListView_GetISearchString = SendMessage(hwndLV, LVM_GETISEARCHSTRING, 0, ByVal lpsz)
End Function
' =============================================================
' the next three macros are user-defined
' Returns the index of the item that is selected and has the focus rectangle
Public Function ListView_GetSelectedItem(hwndLV As Long) As Long
ListView_GetSelectedItem = ListView_GetNextItem(hwndLV, -1, LVNI_FOCUSED Or LVNI_SELECTED)
End Function
' Selects the specified item and gives it the focus rectangle.
' does not de-select any currently selected items
Public Function ListView_SetSelectedItem(hwndLV As Long, i As Long) As Boolean
ListView_SetSelectedItem = ListView_SetItemState(hwndLV, i, LVIS_FOCUSED Or LVIS_SELECTED, _
LVIS_FOCUSED Or LVIS_SELECTED)
End Function
' Selects all listview items. The item with the focus rectangle maintains it.
Public Function ListView_SelectAll(hwndLV As Long) As Boolean
ListView_SelectAll = ListView_SetItemState(hwndLV, -1, LVIS_SELECTED, LVIS_SELECTED)
End Function