kk_lee69
发表于 2017-8-30 15:39:40
你用哪個版本
dnvplj
发表于 2017-8-30 15:41:47
回复 16# kk_lee69
windows 7 x64
kk_lee69
发表于 2017-8-30 15:42:44
回复 17# dnvplj
AU3 的版本
dnvplj
发表于 2017-8-30 15:43:44
回复 18# kk_lee69
AUTOIT_3.3.6.1-2
kk_lee69
发表于 2017-8-30 15:45:18
回复 17# dnvplj
執行這個看看
dnvplj
发表于 2017-8-30 15:48:35
回复 20# kk_lee69
这个有效果,有源码吗?或帮我个改下1楼的代码。多谢了
yamakawa
发表于 2017-8-30 15:58:07
本帖最后由 yamakawa 于 2017-8-30 16:05 编辑
这个效果??
win10 x64.。autoit3 版本 3.3.14.2#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <WindowsConstants.au3>
#include <GuiListView.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 591, 349, 192, 114)
$ListView1 = GUICtrlCreateListView("", 24, 24, 546, 302)
GUICtrlSendMsg($ListView1, $LVM_SETEXTENDEDLISTVIEWSTYLE, $LVS_EX_GRIDLINES, $LVS_EX_GRIDLINES)
_GUICtrlListView_AddColumn($ListView1, "任务", 150)
_GUICtrlListView_AddColumn($ListView1, "状态", 100)
_GUICtrlListView_AddColumn($ListView1, "颜色", 200)
GUICtrlCreateListViewItem("CCTV_64|正在运行|颜色1", $ListView1)
GUICtrlCreateListViewItem("CCTV_65|正在运行|颜色2", $ListView1)
GUICtrlCreateListViewItem("CCTV_66|正在运行|颜色3", $ListView1)
GUICtrlCreateListViewItem("CCTV_01|CCTV_65|颜色4", $ListView1)
GUICtrlCreateListViewItem("CCTV_03|CCTV_65|颜色5", $ListView1)
;============
GUIRegisterMsg($WM_NOTIFY, "wm_notify")
;============
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
;~ $a = ControlListView($Form1, "", $ListView1, "FindItem", "CCTV_65")
;~ GUICtrlSetColor(_GUICtrlListView_GetItemParam($ListView1, $a), '0xFF0000') ;红
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
EndSwitch
WEnd
Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam)
#forceref $hWnd, $iMsg, $wParam
Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndListView, $tInfo
$hWndListView = $ListView1
If Not IsHWnd($ListView1) Then $hWndListView = GUICtrlGetHandle($ListView1)
$tNMHDR = DllStructCreate($tagNMHDR, $lParam)
$hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
$iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
$iCode = DllStructGetData($tNMHDR, "Code")
Switch $hWndFrom
Case $hWndListView
Switch $iCode
Case $NM_CUSTOMDRAW
Local $tDraw = DllStructCreate($tagNMLVCUSTOMDRAW, $lParam)
Local $iDrawStage = $tDraw.dwDrawStage
Local $iItemSpec = $tDraw.dwItemSpec
Local $iSub = $tDraw.iSubItem
Switch $iDrawStage
Case $CDDS_PREPAINT
Return $CDRF_NOTIFYITEMDRAW
Case $CDDS_ITEMPREPAINT
Return $CDRF_NOTIFYSUBITEMDRAW
Case BitOR($CDDS_ITEMPREPAINT, $CDDS_SUBITEM)
If $iItemSpec = 1 Then $tDraw.clrText = 0x0000ff
$tDraw.clrTextBk = _GUICtrlListView_GetItemText($hWndListView,$iItemSpec,$iSub) = "颜色3"? 0x00cc00:0xffffff
Return $CDRF_NEWFONT
EndSwitch
EndSwitch
EndSwitch
Return $GUI_RUNDEFMSG
EndFunc ;==>WM_NOTIFY
dnvplj
发表于 2017-8-30 16:02:54
回复 22# yamakawa
谢谢你朋友,运行后报错,见下图。
kk_lee69
发表于 2017-8-30 16:05:30
回复 21# dnvplj
就是我剛剛發的所以請更新你的 AU3版本
yamakawa
发表于 2017-8-30 16:06:41
回复 23# dnvplj
你的autoit3版本太低了。所以不支持我的这种写法。。。。更新你的autoit3吧。论坛的。3.3.14.2就可以
chzj589
发表于 2017-8-30 16:16:44
回复 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
chzj589
发表于 2017-8-30 16:20:17
回复 26# chzj589
忘了说:
在我的XP系统,3.3.6.1版本测试通过
yamakawa
发表于 2017-8-30 16:20:36
回复 26# chzj589
kk给的代码和你这一样的,,也不能用。。只能是autoit版本问题了。。说实话,我玩au3最开始碰的就是3.3.14.2.。所以之前的旧版本都没玩过。说实话,也没打算去兼容了。。3.3.14.2已经是好久以前的版本了。。更旧的,个人感觉没有去兼容的必要了
dnvplj
发表于 2017-8-30 16:25:08
回复 27# chzj589
感谢各位朋友的回复,chzj589朋友的代码解决了我的问题,在次感谢chzj589朋友。
yamakawa
发表于 2017-8-30 16:28:56
回复 27# chzj589
{:face (394):}你竟然有那么旧的版本。。佩服佩服。。看来是au3老手啊。。。。。