找回密码
 加入
搜索
查看: 7840|回复: 35

[AU3基础] 如何更改LISTVIEW单元格的字体颜色【已解决】

 火.. [复制链接]
发表于 2017-8-29 16:49:05 | 显示全部楼层 |阅读模式
本帖最后由 dnvplj 于 2017-8-30 23:11 编辑

请问各位朋友,如何更改下面代码“颜色3”单元格里的字体颜色?
说明:下面代码是afan版主写的,我多加了一列,感谢afan版主的代码。地址:http://www.autoitx.com/forum.php ... mp;page=1#pid184386
#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)

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
发表于 2017-8-29 18:34:30 | 显示全部楼层
回复 1# dnvplj
$b = ControlListView($Form1, "", $ListView1, "FindItem", "CCTV_66")
GUICtrlSetColor(_GUICtrlListView_GetItemParam($ListView1, $b), '0x0000FF') ;兰
发表于 2017-8-29 19:21:54 | 显示全部楼层
回复 2# chzj589

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?加入

×
 楼主| 发表于 2017-8-29 21:15:55 | 显示全部楼层
回复 3# chzj589
ghzj589朋友,感谢您的回复,我的要求是:只是改:颜色3这个单元格的颜色,其他单元格的颜色不改也行或没有颜色都可以。
发表于 2017-8-29 21:28:14 | 显示全部楼层
回复 4# dnvplj

把2楼的代码插入你的代码第26行,就可以了
 楼主| 发表于 2017-8-29 21:31:28 | 显示全部楼层
还是整行显示,不是只显示“颜色3”单元格里的字体颜色。
发表于 2017-8-29 21:53:15 | 显示全部楼层
发表于 2017-8-30 09:11:50 | 显示全部楼层
回复 7# chzj589
修改一下:

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?加入

×
 楼主| 发表于 2017-8-30 15:06:32 | 显示全部楼层
回复 8# chzj589
朋友您好,是你这代码的效果,但你给的地址用楼主的代码运行后没有效果?我的系统是:win7x64.
发表于 2017-8-30 15:13:39 | 显示全部楼层
回复 9# dnvplj


    請提供擬修改過後的 程式碼 謝謝
 楼主| 发表于 2017-8-30 15:20:03 | 显示全部楼层
回复 10# kk_lee69
朋友你好,因7楼朋友给的地址里面的代码运行后没有效果,不知怎么修改?
发表于 2017-8-30 15:23:35 | 显示全部楼层
回复 11# dnvplj

你的意思是 蛋大 的 範例 沒有效果嗎??
发表于 2017-8-30 15:29:09 | 显示全部楼层
回复 11# dnvplj

給你個範例 剩下的自己研究嚕


#Include <GuiConstantsEx.au3>
#Include <GuiListView.au3>
#include <WindowsConstants.au3>


;fonts for custom draw example
;bold
Global $aFont1 = DLLCall("gdi32.dll","int","CreateFont", "int", 14, "int", 0, "int", 0, "int", 0, "int", 700, _
                        "dword", 0, "dword", 0, "dword", 0, "dword", 0, "dword", 0, "dword", 0, "dword", 0, _
                        "dword", 0, "str", "")
;italic
Global $aFont2 = DLLCall("gdi32.dll","int","CreateFont", "int", 14, "int", 0, "int", 0, "int", 0, "int", 400, _
                        "dword", 1, "dword", 0, "dword", 0, "dword", 0, "dword", 0, "dword", 0, "dword", 0, _
                        "dword", 0, "str", "")
                        


$GUI = GUICreate("Listview Custom Draw", 400, 300)

$cListView = GUICtrlCreateListView("", 2, 2, 394, 268)
$hListView = GUICtrlGetHandle($cListView)
;or
;~ $hListView = _GUICtrlListView_Create($GUI, "", 2, 2, 394, 268)

_GUICtrlListView_SetExtendedListViewStyle($hListView, BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT))

_GUICtrlListView_InsertColumn($hListView, 0, "Column 1", 100)
_GUICtrlListView_InsertColumn($hListView, 1, "Column 2", 100)
_GUICtrlListView_InsertColumn($hListView, 2, "Column 3", 100)

; Add items
For $i = 1 To 30
    _GUICtrlListView_AddItem($hListView, "Row" & $i & ": Col 1", $i-1)
    For $j = 1 To 2
        _GUICtrlListView_AddSubItem ($hListView, $i-1, "Row" & $i & ": Col " & $j+1, $j)
    Next
Next

GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
GUISetState()

Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE
DLLCall("gdi32.dll","int","DeleteObject", "hwnd", $aFont1[0])
DLLCall("gdi32.dll","int","DeleteObject", "hwnd", $aFont2[0])
Exit

Func WM_NOTIFY($hWnd, $Msg, $wParam, $lParam)
    Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR

    $tNMHDR = DllStructCreate($tagNMHDR, $lParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    $iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
    $iCode = DllStructGetData($tNMHDR, "Code")
    Switch $hWndFrom
        Case $hListView
            Switch $iCode
                Case $NM_CUSTOMDRAW
                    If Not _GUICtrlListView_GetViewDetails($hWndFrom) Then Return $GUI_RUNDEFMSG
                     Local $tCustDraw = DllStructCreate('hwnd hwndFrom;int idFrom;int code;' & _
                                        'dword DrawStage;hwnd hdc;long rect[4];dword ItemSpec;int ItemState;dword Itemlparam;' & _
                                        'dword clrText;dword clrTextBk;int SubItem;' & _
                                        'dword ItemType;dword clrFace;int IconEffect;int IconPhase;int PartID;int StateID;long rectText[4];int Align', _ ;winxp or later
                                        $lParam), $iDrawStage, $iItem, $iSubitem, $hDC, $iColor1, $iColor2, $iColor3
                    $iDrawStage = DllStructGetData($tCustDraw, 'DrawStage')
                    If $iDrawStage = $CDDS_PREPAINT Then Return $CDRF_NOTIFYITEMDRAW ;request custom drawing of items
                    If $iDrawStage = $CDDS_ITEMPREPAINT Then Return $CDRF_NOTIFYSUBITEMDRAW ;request drawing each cell separately
                    If Not BitAND($iDrawStage, $CDDS_SUBITEM) Then Return $CDRF_DODEFAULT
                    $iItem = DllStructGetData($tCustDraw, 'ItemSpec')
                    $iSubitem = DllStructGetData($tCustDraw, 'SubItem')
                    Switch $iItem
                        Case 0 To 9 ;for rows 1-10 lets do this
                            $iColor1 = RGB2BGR(0xFBFFD8)
                            $iColor2 = RGB2BGR(-1)
                            $iColor3 = RGB2BGR(0xFF0000)
                            If Mod($iSubitem, 2) Then ;odd columns
                                DllStructSetData($tCustDraw, 'clrTextBk', $iColor1)
                                DllStructSetData($tCustDraw, 'clrText', 0)
                            Else ;even columns
                                DllStructSetData($tCustDraw, 'clrTextBk', $iColor2)
                                DllStructSetData($tCustDraw, 'clrText', $iColor3)
                            EndIf
                        Case 10 To 19 ;for rows 11-20 lets do this
                            $iColor1 = RGB2BGR(0xFBFFD8)
                            $iColor2 = RGB2BGR(0x3DF8FF)
                            $hDC = DllStructGetData($tCustDraw, 'hdc')
                            If Mod($iItem, 2) Then
                                If Mod($iSubitem, 2) Then
                                    DllStructSetData($tCustDraw, 'clrTextBk', $iColor1)
                                Else
                                    DllStructSetData($tCustDraw, 'clrTextBk', $iColor2)
                                EndIf
                                DLLCall("gdi32.dll","hwnd","SelectObject", "hwnd", $hDC, "hwnd", $aFont1[0]) ;select our chosen font into DC
                            Else
                                If Mod($iSubitem, 2) Then
                                    DllStructSetData($tCustDraw, 'clrTextBk', $iColor2)
                                Else
                                    DllStructSetData($tCustDraw, 'clrTextBk', $iColor1)
                                EndIf
                                DLLCall("gdi32.dll","hwnd","SelectObject", "hwnd", $hDC, "hwnd", $aFont2[0])
                            EndIf
                        Case 20 To 29 ;for rows 21-30 lets do this
                            $iColor1 = RGB2BGR(0xFBFFD8)
                            $iColor2 = RGB2BGR(-1)
                            If Mod($iItem, 2) Then ;odd rows
                                DllStructSetData($tCustDraw, 'clrTextBk', $iColor2)
                            Else
                                DllStructSetData($tCustDraw, 'clrTextBk', $iColor1)
                            EndIf                     
                    EndSwitch
                    Return $CDRF_NEWFONT
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY

Func RGB2BGR($iColor)
    Return BitAND(BitShift(String(Binary($iColor)), 8), 0xFFFFFF)
EndFunc
 楼主| 发表于 2017-8-30 15:29:46 | 显示全部楼层
回复 12# kk_lee69
在我的机上运行没有效果,我的是:WIN7x64。
 楼主| 发表于 2017-8-30 15:36:57 | 显示全部楼层
回复 13# kk_lee69
这个代码在我的机器上运行后也没有效果,难到是我机器的事?
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-4-26 19:29 , Processed in 0.081324 second(s), 20 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表