7,780
社区成员
发帖
与我相关
我的任务
分享
Private Sub Form_Load()
ListView1.View = lvwReport
ListView1.ColumnHeaders.Add , , "A Column", , , 2
ListView1.ColumnHeaders.Item(ListView1.ColumnHeaders.Count).Icon = 1
Dim Counter as long
For Counter = 1 To 500
ListView1.ListItems.Add , , Counter
Next Counter
End Sub
Private CmdChangeIcon__Click()
ShowHeaderIcon 1, 2, True, ListView1, True
End Sub
Private Sub Form_Load()
ListView1.View = lvwReport
ListView1.ColumnHeaders.Add , , "A Column", , , 2
ListView1.ColumnHeaders.Item(ListView1.ColumnHeaders.Count).Icon = 1
Dim Counter as long
For Counter = 1 To 500
ListView1.ListItems.Add , , Counter
Next Counter
End Sub
Private CmdChangeIcon__Click()
ShowHeaderIcon 1, 2, True, ListView1, True
End Sub
Private Const HDF_LEFT As Long = 0
Private Const HDF_RIGHT As Long = 1
Private Const HDF_CENTER As Long = 2
Private Const HDF_CENTER As Long = 2
Private Const HDF_JUSTIFYMASK As Long = &H3
Private Const HDF_RTLREADING As Long = 4
Private Const HDF_IMAGE As Long = &H800
Private Const HDF_OWNERDRAW As Long = &H8000&
Private Const HDF_STRING As Long = &H4000
Private Const HDF_BITMAP As Long = &H2000
'Private Const HDF_BITMAP_ON_RIGHT As Long = &H1000
Private Const HDF_CHECKBOX As Long = &H40
Private Const HDF_CHECKED As Long = &H80
Private Const HDF_FIXEDWIDTH As Long = &H100 ' Can't resize the column; same as LVCFMT_FIXED_WIDTH
Private Const HDF_SPLITBUTTON As Long = &H1000000 'Column is a split button; same as LVCFMT_SPLITBUTTON
Private Const HDF_SORTDOWN As Long = &H400
Private Const HDF_SORTUP As Long = &H200
Private Type HDITEMW
Mask As Long
cxy As Long
pszText As Long
hbm As Long
cchTextMax As Long
fmt As Long
lParam As Long
iImage As Long
iOrder As Long
type As Long ':(?Missing Scope
pvFilter As Long
State As Long 'WIN32_WINNT >= 0x0600
End Type
Private Const LVM_FIRST As Long = &H1000
Private Const LVM_GETHEADER As Long = (LVM_FIRST + 31)
Private Const HDM_FIRST As Long = &H1200
Private Const HDM_GETITEM As Long = (HDM_FIRST + 3)
Private Const HDM_SETITEM As Long = (HDM_FIRST + 4)
Private Const HDF_BITMAP_ON_RIGHT As Long = &H1000
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 ':(?Missing Scope
Private Declare Function SendMessageLong Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Public Sub ShowHeaderIcon(ByVal colNo As Long, ByVal imgIconNo As Long, ByVal bShowImage As Boolean, _
ByVal lvwControl As ListView, Optional alignImageRight As Boolean = True)
Dim lHeader As Long
Dim HD As HDITEMW
Dim imageAlignment As Long
' get a handle to the listview header component
lHeader = SendMessage(lvwControl.hWnd, LVM_GETHEADER, 0, ByVal 0)
imageAlignment = IIf(alignImageRight, HDF_BITMAP_ON_RIGHT, HDF_BITMAP)
' set up the structure entries
With HD
.Mask = HDI_IMAGE Or HDI_FORMAT
If bShowImage Then ' show
.fmt = HDF_STRING Or HDF_IMAGE Or imageAlignment
.iImage = imgIconNo
Else
.fmt = HDF_STRING ' just string
End If
.fmt = .fmt Or GetAlignment(lvwControl.ColumnHeaders(colNo))
End With
' modify the header
Call SendMessage(lHeader, HDM_SETITEM, colNo - 1, HD)
End Sub
Private Function GetAlignment(col As ColumnHeader)
' Get the columns current alignment
With col
Select Case .Alignment
Case lvwColumnRight
GetAlignment = HDF_RIGHT
Case lvwColumnCenter
GetAlignment = HDF_CENTER
Case Else
GetAlignment = HDF_LEFT
End Select
End With
End Function