#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>
#include <FontConstants.au3>
#include <GuiListView.au3>
#include <Constants.au3>
#include <WinAPIEx.au3>
Global $hGUI, $cListView, $hListView,$hDC,$hFont,$hOldFont
Global $iDllUSER32 = DllOpen("user32.dll")
Global $aCol[3][2] = [[0xFFFF00, 0xFF0000],[0x0, 0x0000FF],[0xFF00FF, 0x00FF00]]
For $i = 0 To UBound($aCol) - 1
$aCol[$i][0] = _BGR2RGB($aCol[$i][0])
$aCol[$i][1] = _BGR2RGB($aCol[$i][1])
Next
$hGUI = GUICreate("", 500, 300)
;~ GUISetBkColor(0x0)
$cListView = GUICtrlCreateListView("项目|子项目1|子项目2", 10, 10, 480, 280)
$hListView = GUICtrlGetHandle($cListView)
_GUICtrlListView_SetExtendedListViewStyle($hListView, BitOR($LVS_EX_DOUBLEBUFFER, $LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT))
;~ GUICtrlSetFont(-1, 9, 800, 0, "Comic Sans MS", $ANTIALIASED_QUALITY)
Global $hHeader = HWnd(_GUICtrlListView_GetHeader($cListView))
_WinAPI_SetWindowTheme($hHeader, "", "")
Global $wProcNew = DllCallbackRegister("_LVWndProc", "ptr", "hwnd;uint;wparam;lparam")
Global $wProcOld = _WinAPI_SetWindowLong($hListView, $GWL_WNDPROC, DllCallbackGetPtr($wProcNew))
Global $iStyle = _WinAPI_GetWindowLong($hHeader, $GWL_STYLE)
_WinAPI_SetWindowLong($hHeader, $GWL_STYLE, BitOR($iStyle, $HDS_FLAT))
For $i = 1 To 15
_GUICtrlListView_AddItem($hListView, "Item" & $i)
_GUICtrlListView_AddSubItem($hListView, $i - 1, "SubItem" & $i, 1)
_GUICtrlListView_AddSubItem($hListView, $i - 1, "SubItem" & $i, 2)
Next
_GUICtrlListView_SetColumnWidth($hListView, 0, $LVSCW_AUTOSIZE_USEHEADER)
_GUICtrlListView_SetColumnWidth($hListView, 1, $LVSCW_AUTOSIZE_USEHEADER)
_GUICtrlListView_SetColumnWidth($hListView, 2, $LVSCW_AUTOSIZE_USEHEADER)
GUISetState()
Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE
If $wProcOld Then _WinAPI_SetWindowLong($hListView, $GWL_WNDPROC, $wProcOld)
If $wProcNew Then DllCallbackFree($wProcNew)
_WinAPI_SelectObject($hDC, $hOldFont)
_WinAPI_DeleteObject($hFont)
_WinAPI_ReleaseDC(0, $hDC)
GUIDelete()
Exit
Func _LVWndProc($hWnd, $iMsg, $wParam, $lParam)
#forceref $hWnd, $iMsg, $wParam
If $iMsg = $WM_NOTIFY Then
Local $tNMHDR, $hWndFrom, $iCode, $iItem, $hDC
$tNMHDR = DllStructCreate($tagNMHDR, $lParam)
$hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
$iCode = DllStructGetData($tNMHDR, "Code")
Switch $hWndFrom
Case $hHeader
Switch $iCode
Case $NM_CUSTOMDRAW
Local $tCustDraw = DllStructCreate($tagNMLVCUSTOMDRAW, $lParam)
Switch DllStructGetData($tCustDraw, "dwDrawStage")
Case $CDDS_PREPAINT
Return $CDRF_NOTIFYITEMDRAW
Case $CDDS_ITEMPREPAINT
$hDC = DllStructGetData($tCustDraw, "hDC")
$iItem = DllStructGetData($tCustDraw, "dwItemSpec")
$hFont = _WinAPI_CreateFont(12, 0, 0, 0, 400, False, False, False, $DEFAULT_CHARSET, $OUT_DEFAULT_PRECIS, $CLIP_DEFAULT_PRECIS, $ANTIALIASED_QUALITY, 0, '黑体')
$hOldFont = _WinAPI_SelectObject($hDC, $hFont)
_WinAPI_SetTextColor($hDC, $aCol[$iItem][0])
_WinAPI_SetBkColor($hDC, $aCol[$iItem][1])
Return $CDRF_NEWFONT
Return $CDRF_SKIPDEFAULT
EndSwitch
EndSwitch
EndSwitch
EndIf
Return _WinAPI_CallWindowProc($wProcOld, $hWnd, $iMsg, $wParam, $lParam)
EndFunc ;==>_LVWndProc
Func _BGR2RGB($iColor)
Return BitOR(BitShift(BitAND($iColor, 0x0000FF), -16), BitAND($iColor, 0x00FF00), BitShift(BitAND($iColor, 0xFF0000), 16))
EndFunc ;==>_BGR2RGB
|