回复 23# dnvplj
#RequireAdmin
#AutoIt3Wrapper_Icon=118.ico; zzsy.ico; C:\WINDOWS\system32\SHELL32.dll|-39.ico
#AutoIt3Wrapper_OutFile= ListView条目颜色.exe ;输出文件名
#AutoIt3Wrapper_Res_LegalCopyright=Copyright (c) chzj589 2016
#AutoIt3Wrapper_OutFile_Type=exe ;文件类型
#AutoIt3Wrapper_UseX64 = n
#AutoIt3Wrapper_Compression=4 ;压缩等级
#AutoIt3Wrapper_UseUPX=y
Global $tagTEXTMETRIC
#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GuiListView.au3>
#include <FontConstants.au3>
#include <WinAPI.au3>
#include <ColorConstants.au3>
#include <GuiImageList.au3>
Opt('GUIOnEventMode', 1)
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")
Global $hGUI, $hListView
Example()
While 1
Sleep(1000)
WEnd
Func Example()
$hGUI = GUICreate("ListView条目颜色", 300, 200)
GUISetBkColor(0xfbfcfd)
GUISetOnEvent($GUI_EVENT_CLOSE, "Form1Close")
$hListView = _GUICtrlListView_Create($hGUI, "", 10, 10, 280, 180, $LVS_REPORT, $WS_EX_CLIENTEDGE)
_GUICtrlListView_SetExtendedListViewStyle($hListView, BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT, $LVS_EX_INFOTIP))
; 设置颜色
_GUICtrlListView_SetTextBkColor($hListView, 16710321);0xCDCDCD);$CLR_MONEYGREEN)
_GUICtrlListView_SetBkColor($hListView, 14675183)
$hImage = _GUIImageList_Create(1, 16);30为每行的间距(即网格高度)
_GUICtrlListView_SetImageList($hListView, $hImage, 1)
; 添加列
_GUICtrlListView_InsertColumn($hListView, 0, "任务", 70); 任务|状态|颜色
_GUICtrlListView_InsertColumn($hListView, 1, "状态", 90)
_GUICtrlListView_InsertColumn($hListView, 2, "颜色", 80)
_GUICtrlListView_AddItem($hListView, "CCTV_64", 0)
_GUICtrlListView_AddSubItem($hListView, 0, "正在运行", 1)
_GUICtrlListView_AddSubItem($hListView, 0, "颜色1", 2)
_GUICtrlListView_AddItem($hListView, "CCTV_65", 0)
_GUICtrlListView_AddSubItem($hListView, 1, "正在运行", 1)
_GUICtrlListView_AddSubItem($hListView, 1, "颜色2", 2)
_GUICtrlListView_AddItem($hListView, "CCTV_66", 0)
_GUICtrlListView_AddSubItem($hListView, 2, "正在运行", 1)
_GUICtrlListView_AddSubItem($hListView, 2, "颜色3", 2)
_GUICtrlListView_AddItem($hListView, "CCTV_01", 0)
_GUICtrlListView_AddSubItem($hListView, 3, "CCTV_65", 1)
_GUICtrlListView_AddSubItem($hListView, 3, "颜色4", 2)
_GUICtrlListView_AddItem($hListView, "CCTV_03", 0)
_GUICtrlListView_AddSubItem($hListView, 4, "CCTV_65", 1)
_GUICtrlListView_AddSubItem($hListView, 4, "颜色5", 2)
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
GUISetState(@SW_SHOW, $hGUI)
;_WinAPI_DeleteObject($Font1)
;_WinAPI_DeleteObject($Font2)
EndFunc ;==>Example
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 2;条目行数
$hDC = DllStructGetData($tCustDraw, "hdc")
If $iSubItem = 0 Then ;设置首列, 即项目
;$iColor = RGB2BGR(0xFF0000)
;_WinAPI_SelectObject($hDC, $Font1)
DllStructSetData($tCustDraw, "clrText", $iColor)
ElseIf $iSubItem = 1 Then ;设置子项, 即列索引大于0时
;$iColor = RGB2BGR(0xc0c000)
;_WinAPI_SelectObject($hDC, $Font2) ;设置用于设备场景内文本的字体
;DllStructSetData($tCustDraw, "clrText", $iColor) ;设置文本色
;DllStructSetData($tCustDraw, "clrTextBk", RGB2BGR(0xFFFF80)) ;设置文本背景色
ElseIf $iSubItem = 2 Then
$iColor = RGB2BGR(0xFF00FF);0x008080)
;_WinAPI_SelectObject($hDC, $Font1)
DllStructSetData($tCustDraw, "clrText", $iColor)
DllStructSetData($tCustDraw, "clrTextBk", RGB2BGR(16710321))
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
Func Form1Close()
GUIDelete()
Exit
EndFunc ;==>Form1Close
|