#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GuiListView.au3>
#include <FontConstants.au3>
#include <WinAPI.au3>
Global Const $CDDS_SUBITEMPREPAINT = BitOR($CDDS_ITEM, $CDDS_SUBITEM, $CDDS_PREPAINT)
Global $Font1 = _WinAPI_CreateFont(14, 0, 0, 0, $FW_BOLD)
Global $Font2 = _WinAPI_CreateFont(14, 0, 0, 0, $FW_NORMAL, False, False, False, $DEFAULT_CHARSET, $OUT_DEFAULT_PRECIS, _
$CLIP_DEFAULT_PRECIS, $DEFAULT_QUALITY, 0, "MS Sans Serif")
$hGUI = GUICreate("Test", 300, 200)
$hListView = _GUICtrlListView_Create($hGUI, "Items|SubItems|", 10, 10, 280, 180, $LVS_REPORT, $WS_EX_CLIENTEDGE)
_GUICtrlListView_SetExtendedListViewStyle($hListView, BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT, $LVS_EX_INFOTIP))
For $i = 1 To 10
_GUICtrlListView_AddItem($hListView, "Item" & $i)
_GUICtrlListView_AddSubItem($hListView, $i - 1, "SubItem" & $i, 1)
_GUICtrlListView_AddSubItem($hListView, $i - 1, "SubItem" & $i, 2)
Next
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
GUISetState()
Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE
_WinAPI_DeleteObject($Font1)
_WinAPI_DeleteObject($Font2)
Func WM_NOTIFY($hWnd, $Msg, $wParam, $lParam)
Local $tNMHDR, $hWndFrom, $iCode
$tNMHDR = DllStructCreate($tagNMHDR, $lParam)
$hWndFrom = DllStructGetData($tNMHDR, "hWndFrom")
$iCode = DllStructGetData($tNMHDR, "Code")
Switch $hWndFrom
Case $hListView
Switch $iCode
Case $NM_CUSTOMDRAW
Local $tCustDraw = DllStructCreate($tagNMLVCUSTOMDRAW, $lParam)
Local $iDrawStage = DllStructGetData($tCustDraw, "dwDrawStage")
If $iDrawStage = $CDDS_PREPAINT Then Return $CDRF_NOTIFYITEMDRAW
If $iDrawStage = $CDDS_ITEMPREPAINT Then Return $CDRF_NOTIFYSUBITEMDRAW
Local $iSubItem = DllStructGetData($tCustDraw, "iSubItem")
Local $iItem = DllStructGetData($tCustDraw, "dwItemSpec")
Local $iColor, $hDC
Switch $iItem
Case 5
$hDC = DllStructGetData($tCustDraw, "hdc")
If $iSubItem = 0 Then
$iColor = RGB2BGR(0xFF0000)
_WinAPI_SelectObject($hDC, $Font1)
DllStructSetData($tCustDraw, "clrText", $iColor)
ElseIf $iSubItem = 1 Then
$iColor = RGB2BGR(0x000000)
_WinAPI_SelectObject($hDC, $Font2)
DllStructSetData($tCustDraw, "clrText", $iColor)
DllStructSetData($tCustDraw, "clrTextBk", RGB2BGR(0xFFFF80))
ElseIf $iSubItem = 2 Then
$iColor = RGB2BGR(0x008080)
_WinAPI_SelectObject($hDC, $Font1)
DllStructSetData($tCustDraw, "clrText", $iColor)
DllStructSetData($tCustDraw, "clrTextBk", RGB2BGR(0xFFFFFF))
EndIf
Return $CDRF_NEWFONT
EndSwitch
EndSwitch
EndSwitch
Return $GUI_RUNDEFMSG
EndFunc ;==>WM_NOTIFY
Func RGB2BGR($iColor)
Return BitAND(BitShift(String(Binary($iColor)), 8), 0xFFFFFF)
EndFunc ;==>RGB2BGR()
截获$NM_CUSTOMDRAW消息比较耗显卡和CPU,你看着办吧 |