Sign in to follow this  
Followers 0
Juanola

Background Color Column ListView [SOLVED]

14 posts in this topic

#1 ·  Posted (edited)

How can I change the backgroud color of only the first column of one ListView?

I have it script, but it change the background color of all the odd columns and I only want change the background color of the first column.

Any help please?

Thank you.

#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)

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

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

;Add items
For $i = 1 To 10
    _GUICtrlListView_AddItem($hListView, "Row" & $i & ": Col 1", $i-1)
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
                   
                    $iItem = DllStructGetData($tCustDraw, 'ItemSpec')
                    $iSubitem = DllStructGetData($tCustDraw, 'SubItem')
                    
                    
                    Switch $iItem
                        Case 0 To 9 ;for rows 1-10 lets do this
                            $iColor1 = RGB2BGR(0xFBFFD8)
                                               
                            If Mod($iSubitem, 2) Then ;odd columns
                                DllStructSetData($tCustDraw, 'clrTextBk', $iColor1)
                                DllStructSetData($tCustDraw, 'clrText', 0)
                             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
Edited by Juanola

Share this post


Link to post
Share on other sites



Did you even look at the code?

Maybe change this:

Switch $iItem
                        Case 0 To 9;for rows 1-10 lets do this
                            $iColor1 = RGB2BGR(0xFBFFD8)
                                               
                            If Mod($iSubitem, 2) Then;odd columns
                                DllStructSetData($tCustDraw, 'clrTextBk', $iColor1)
                                DllStructSetData($tCustDraw, 'clrText', 0)
                             EndIf
                    EndSwitch

To this:

Switch $iItem
                        Case 0;for rows 1-10 lets do this
                            $iColor1 = RGB2BGR(0xFBFFD8)
                                               
                           ;If Mod($iSubitem, 2) Then;odd columns
                                DllStructSetData($tCustDraw, 'clrTextBk', $iColor1)
                                DllStructSetData($tCustDraw, 'clrText', 0)
                            ;EndIf
                    EndSwitch

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Did you even look at the code?

Maybe change this:

Switch $iItem
                        Case 0 To 9;for rows 1-10 lets do this
                            $iColor1 = RGB2BGR(0xFBFFD8)
                                               
                            If Mod($iSubitem, 2) Then;odd columns
                                DllStructSetData($tCustDraw, 'clrTextBk', $iColor1)
                                DllStructSetData($tCustDraw, 'clrText', 0)
                             EndIf
                    EndSwitch

To this:

Switch $iItem
                        Case 0;for rows 1-10 lets do this
                            $iColor1 = RGB2BGR(0xFBFFD8)
                                               
                    ;If Mod($iSubitem, 2) Then;odd columns
                                DllStructSetData($tCustDraw, 'clrTextBk', $iColor1)
                                DllStructSetData($tCustDraw, 'clrText', 0)
            ;EndIf
                    EndSwitch
Thank you, but it doesn't working.

I want paint only the first COLUMN.

Your script paint only the first ROW, but I want COLUMN.

Tkanks for reply me.

I see what you are developer.

Could you add one function for change the background color of one column complete? There is functions for change the background color of one row of one listview, but there isn't any function for change the background color of one COLUMN.

Thank you!

Edited by Juanola

Share this post


Link to post
Share on other sites

This works for me

Switch $iItem                           
                         Case 0 To 9 ;for rows 1-10 lets do this
                            $iColor1 = RGB2BGR(0xFBFFD8)
                            If $iSubitem = 0 Then ; column1
                                DllStructSetData($tCustDraw, 'clrTextBk', $iColor1)
                                DllStructSetData($tCustDraw, 'clrText', 0)
                            Else
                                DllStructSetData($tCustDraw, 'clrTextBk', -1)   ; white
                                DllStructSetData($tCustDraw, 'clrText', 0)
                            EndIf
                    EndSwitch

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

This works for me

Switch $iItem                           
                         Case 0 To 9 ;for rows 1-10 lets do this
                            $iColor1 = RGB2BGR(0xFBFFD8)
                            If $iSubitem = 0 Then ; column1
                                DllStructSetData($tCustDraw, 'clrTextBk', $iColor1)
                                DllStructSetData($tCustDraw, 'clrText', 0)
                            Else
                                DllStructSetData($tCustDraw, 'clrTextBk', -1)   ; white
                                DllStructSetData($tCustDraw, 'clrText', 0)
                            EndIf
                    EndSwitch
Thank you for your help!!!

But I can't use it method, because I have all the other rows with one different background color. If I use your script all the other columns lost his background color.

I do it

Posted Image

BUT I want It

Posted Image

I want one script what only change the background color of the first COLUMN and it doesn't change nothing more of the other columns.

Is there any solution?

Thank you!

Edited by Juanola

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

Is impossible do it with Autoit?

I only want change the background color of the first column and don't change the color of the others columns.

If not there is any more method for change the background color of one column, somebody can explain me how I can read the data values of the cells with the first function of the first post????

I want read the data values of the cells for know what color background paint and I don't know how read it values with it function.

Switch $iItem

Case 0 To

$iColor1 = RGB2BGR(0xFBFFD8)

If $iSubitem = 0 Then ; column1

DllStructSetData($tCustDraw, 'clrTextBk', $iColor1)

DllStructSetData($tCustDraw, 'clrText', 0)

Else

..................................................................

.................................................................. <--- Code for read data value of the cells with it script????

Endif

Thank you!

Edited by Juanola

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

Please.

I want only change the background of the first COLUMN and don't change nothing more.

I'm newbie and I can't understand the fuction for change the background color of one column.

Is there any function more easy what the fuction DllStructCreate()????

I'm newbie. And if there isn't any more function, somebody could explainme how I read data values of one cell with the funtion dllStructCreate?

Thank you.

Edited by Juanola

Share this post


Link to post
Share on other sites

Please post the script that is replicating your problem with what has been posted!

Also, remember to bump your posts no less than once every 24 hours!

Brett

Share this post


Link to post
Share on other sites

How can I change the backgroud color of only the first column of one ListView?

I have it script, but it change the background color of all the odd columns and I only want change the background color of the first column.

Any help please?

Thank you.

#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)

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

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

;Add items
For $i = 1 To 10
    _GUICtrlListView_AddItem($hListView, "Row" & $i & ": Col 1", $i-1)
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
                   
                    $iItem = DllStructGetData($tCustDraw, 'ItemSpec')
                    $iSubitem = DllStructGetData($tCustDraw, 'SubItem')
                    
                    
                    Switch $iItem
                        Case 0 To 9 ;for rows 1-10 lets do this
                            $iColor1 = RGB2BGR(0xFBFFD8)
                                               
                            If Mod($iSubitem, 2) Then ;odd columns
                                DllStructSetData($tCustDraw, 'clrTextBk', $iColor1)
                                DllStructSetData($tCustDraw, 'clrText', 0)
                             EndIf
                    EndSwitch
                    Return $CDRF_NEWFONT
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY

Func RGB2BGR($iColor)
    Return BitAND(BitShift(String(Binary($iColor)), 8), 0xFFFFFF)
EndFuncoÝ÷ Ûú®¢×ºÚ"µÍÒ[ÛYH ÑÝZPÛÛÝ[Ñ^]LÉÝÂÒ[ÛYH ÑÝZSÝY]Ë]LÉÝÂÚ[ÛYH ÝÚ[ÝÜØÛÛÝ[Ë]LÉÝÂÙÛÈÜÝÝÛH]È^[BØÛÛØ[  ÌÍØQÛHHØ[
    ][ÝÙÙLÌ ][ÝË  ][ÝÚ[ ][ÝË  ][ÝÐÜX]QÛ   ][ÝË  ][ÝÚ[ ][ÝËM ][ÝÚ[ ][ÝË  ][ÝÚ[ ][ÝË  ][ÝÚ[ ][ÝË  ][ÝÚ[ ][ÝË
Ì    ][ÝÙÛÜ  ][ÝË  ][ÝÙÛÜ  ][ÝË  ][ÝÙÛÜ  ][ÝË  ][ÝÙÛÜ  ][ÝË  ][ÝÙÛÜ  ][ÝË  ][ÝÙÛÜ  ][ÝË  ][ÝÙÛÜ  ][ÝË    ][ÝÙÛÜ  ][ÝË  ][ÝÜÝ][ÝË  ][ÝÉ][ÝÊBÚ][XÂÛØ[   ÌÍØQÛHØ[
    ][ÝÙÙLÌ ][ÝË  ][ÝÚ[ ][ÝË  ][ÝÐÜX]QÛ   ][ÝË  ][ÝÚ[ ][ÝËM ][ÝÚ[ ][ÝË  ][ÝÚ[ ][ÝË  ][ÝÚ[ ][ÝË  ][ÝÚ[ ][ÝË
  ][ÝÙÛÜ  ][ÝËK ][ÝÙÛÜ  ][ÝË  ][ÝÙÛÜ  ][ÝË  ][ÝÙÛÜ  ][ÝË  ][ÝÙÛÜ  ][ÝË  ][ÝÙÛÜ  ][ÝË  ][ÝÙÛÜ  ][ÝË    ][ÝÙÛÜ  ][ÝË  ][ÝÜÝ][ÝË  ][ÝÉ][ÝÊBÌÍÑÕRHHÕRPÜX]J   ][ÝÓÝY]ÈÝÝÛH]É][ÝË
Ì
BÌÍØÓÝY]ÈHÕRPÝÜX]SÝY]Ê   ][ÝÉ][ÝËÎM
BÌÍÚÝY]ÈHÕRPÝÙ][J   ÌÍØÓÝY]ÊBÑÕRPÝÝY]×ÔÙ]^[YÝY]ÔÝ[J ÌÍÚÝY]Ë]Ô ÌÍÓ×ÑVÑÔQSTË    ÌÍÓ×ÑVÑSÕÔÑSPÕ
JBÑÕRPÝÝY]×Ò[ÙÛÛ[[ ÌÍÚÝY]Ë    ][ÝÐÛÛ[[I][ÝËL
BÑÕRPÝÝY]×Ò[ÙÛÛ[[  ÌÍÚÝY]ËK   ][ÝÐÛÛ[[][ÝËL
BÐY][ÂÜ  ÌÍÚHHHÈLÑÕRPÝÝY]×ÐY][J    ÌÍÚÝY]Ë    ][ÝÔÝÉ][ÝÈ    [È ÌÍÚH [È ][ÝÎÛÛI][ÝË   ÌÍÚKLJB^ÕRTYÚÝÙÊ    ÌÍÕÓWÓÕQK ][ÝÕÓWÓÕQI][ÝÊBÕRTÙ]Ý]J
BÂ[[ÕRQÙ]ÙÊ
HH  ÌÍÑÕRWÑUSÐÓÔÑBØ[
    ][ÝÙÙLÌ ][ÝË  ][ÝÚ[ ][ÝË  ][ÝÑ[]SØXÝ  ][ÝË  ][ÝÚÛ    ][ÝË  ÌÍØQÛVÌJBØ[
    ][ÝÙÙLÌ ][ÝË  ][ÝÚ[ ][ÝË  ][ÝÑ[]SØXÝ  ][ÝË  ][ÝÚÛ    ][ÝË  ÌÍØQÛÌJB^][ÈÓWÓÕQJ ÌÍÚÛ    ÌÍÓÙË  ÌÍÝÔ[K  ÌÍÛ[JBØØ[  ÌÍÚÛÛK ÌÍÚRQÛK ÌÍÚPÛÙK    ÌÍÝR ÌÍÝRHÝXÝÜX]J  ÌÍÝYÓR  ÌÍÛ[JB   ÌÍÚÛÛHHÛ
ÝXÝÙ]]J  ÌÍÝR ][ÝÚÛÛI][ÝÊJB ÌÍÚRQÛHHÝXÝÙ]]J  ÌÍÝR ][ÝÒQÛI][ÝÊB   ÌÍÚPÛÙHHÝXÝÙ]]J ÌÍÝR ][ÝÐÛÙI][ÝÊBÝÚ]Ú   ÌÍÚÛÛBØÙH    ÌÍÚÝY]ÂÝÚ]Ú ÌÍÚPÛÙBØÙH   ÌÍÓWÐÕTÕÓQUÂYÝÑÕRPÝÝY]×ÑÙ]Y]Ñ]Z[Ê ÌÍÚÛÛJH[]  ÌÍÑÕRWÔSQTÑÂØØ[    ÌÍÝÝÝ]ÈHÝXÝÜX]J    ÌÎNÚÛÛÛNÚ[YÛNÚ[ÛÙNÉÌÎNÈ  [È   ÌÎNÙÛÜ]ÔÝYÙNÚÛÎÛÛÈXÝÍNÙÛÜ][TÜXÎÚ[][TÝ]NÙÛÜ][[[NÉÌÎNÈ  [È   ÌÎNÙÛÜÛ^ÙÛÜÛ^ÎÚ[ÝX][NÉÌÎNÈ [È   ÌÎNÙÛÜ][UNÙÛÜÛXÙNÚ[XÛÛYXÝÚ[XÛÛÙNÚ[QÚ[Ý]RQÛÛÈXÝ^ÍNÚ[[YÛÌÎNËÈÝÚ[Ü] ÌÍÛ[JK   ÌÍÚQ]ÔÝYÙK    ÌÍÚR][K  ÌÍÚTÝX][K   ÌÍÚË    ÌÍÚPÛÛÜK  ÌÍÚPÛÛÜ   ÌÍÚPÛÛÜ ÌÍÚQ]ÔÝYÙHHÝXÝÙ]]J ÌÍÝÝÝ]Ë   ÌÎNÑ]ÔÝYÙIÌÎNÊBY   ÌÍÚQ]ÔÝYÙHH   ÌÍÐÑ×ÔTRS[]   ÌÍÐÑÓÕQRUSQUÈÜ]YÝÝÝÛH]Ú[ÈÙ][ÂY  ÌÍÚQ]ÔÝYÙHH   ÌÍÐÑ×ÒUSTTRS[]    ÌÍÐÑÓÕQTÕPUSQUÈÜ]YÝ]Ú[ÈXXÚÙ[Ù][B ÌÍÚR][HHÝXÝÙ]]J   ÌÍÝÝÝ]Ë   ÌÎNÒ][TÜXÉÌÎNÊB ÌÍÚTÝX][HHÝXÝÙ]]J    ÌÍÝÝÝ]Ë   ÌÎNÔÝX][IÌÎNÊBBBBBBBIÌÍÚPÛÛÜHHÐÔ
BBBBBBBIÌÍÚPÛÛÜHLBBBBBBBIÌÍÚPÛÛÜÈHÐÔÌÐÌ
BBBBBH  ÌÍÚPÛÛÜHÐÔM
BBBBBBBIÌÍÚPÛÛÜHHÐÔ
Î
BBBBBBBIÌÍÚPÛÛÜHÐÔBBBBBBBIÌÍÚPÛÛÜÈHÐÔÌÌÌ
BBBBBBBIÌÍÚPÛÛÜHÐÔ
BBBBBBBBBBBBBBÝÚ]Ú   ÌÍÚR][BBBBHØÙHBBBBTÝÚ]Ú ÌÍÚTÝX][BBBBBPØÙHBBBBQÝXÝÙ]]J  ÌÍÝÝÝ]Ë   ÌÎNØÛ^ÉÌÎNË ÌÍÚPÛÛÜJBBBBBQÝXÝÙ]]J  ÌÍÝÝÝ]Ë   ÌÎNØÛ^  ÌÎNË
BBBBBPØÙHBBBBBQÝXÝÙ]]J ÌÍÝÝÝ]Ë   ÌÎNØÛ^ÉÌÎNË ÌÍÚPÛÛÜBBBBBQÝXÝÙ]]J   ÌÍÝÝÝ]Ë   ÌÎNØÛ^  ÌÎNË
BBBBBQ[ÝÚ]ÚBBBBBBBBBBBBBBBPØÙHBBBBBTÝÚ]Ú    ÌÍÚTÝX][BBBBBPØÙHBBBBQÝXÝÙ]]J  ÌÍÝÝÝ]Ë   ÌÎNØÛ^ÉÌÎNË ÌÍÚPÛÛÜÊBBBBBQÝXÝÙ]]J ÌÍÝÝÝ]Ë   ÌÎNØÛ^  ÌÎNË
BBBBBPØÙHBBBBBQÝXÝÙ]]J ÌÍÝÝÝ]Ë   ÌÎNØÛ^ÉÌÎNË ÌÍÚPÛÛÜBBBBBQÝXÝÙ]]J   ÌÍÝÝÝ]Ë   ÌÎNØÛ^  ÌÎNË
BBBBBQ[ÝÚ]ÚBBHBBBHBBBHBBBHØÙHBBBBTÝÚ]Ú  ÌÍÚTÝX][BBBBBPØÙHBBBBQÝXÝÙ]]J  ÌÍÝÝÝ]Ë   ÌÎNØÛ^ÉÌÎNË ÌÍÚPÛÛÜ
BBBBBQÝXÝÙ]]J    ÌÍÝÝÝ]Ë   ÌÎNØÛ^  ÌÎNË
BBBBBPØÙHBBBBBQÝXÝÙ]]J ÌÍÝÝÝ]Ë   ÌÎNØÛ^ÉÌÎNË ÌÍÚPÛÛÜBBBBBQÝXÝÙ]]J   ÌÍÝÝÝ]Ë   ÌÎNØÛ^  ÌÎNË
BBBBBQ[ÝÚ]ÚBBBBBBBBBBBBBBBBBBBPØÙHÂBBBBTÝÚ]Ú   ÌÍÚTÝX][BBBBBPØÙHBBBBQÝXÝÙ]]J  ÌÍÝÝÝ]Ë   ÌÎNØÛ^ÉÌÎNË ÌÍÚPÛÛÜJBBBBBQÝXÝÙ]]J  ÌÍÝÝÝ]Ë   ÌÎNØÛ^  ÌÎNË
BBBBBPØÙHBBBBBQÝXÝÙ]]J ÌÍÝÝÝ]Ë   ÌÎNØÛ^ÉÌÎNË ÌÍÚPÛÛÜBBBBBQÝXÝÙ]]J   ÌÍÝÝÝ]Ë   ÌÎNØÛ^  ÌÎNË
BBBBBQ[ÝÚ]ÚBBBHBBBHBBBBBBBHØÙH
BBBBTÝÚ]Ú    ÌÍÚTÝX][BBBBBPØÙHBBBBQÝXÝÙ]]J  ÌÍÝÝÝ]Ë   ÌÎNØÛ^ÉÌÎNË ÌÍÚPÛÛÜBBBBBQÝXÝÙ]]J   ÌÍÝÝÝ]Ë   ÌÎNØÛ^  ÌÎNË
BBBBBPØÙHBBBBBQÝXÝÙ]]J ÌÍÝÝÝ]Ë   ÌÎNØÛ^ÉÌÎNË ÌÍÚPÛÛÜBBBBBQÝXÝÙ]]J   ÌÍÝÝÝ]Ë   ÌÎNØÛ^  ÌÎNË
BBBBBQ[ÝÚ]ÚBBBBBBBBBBBBBBBBBBBPØÙH
BBBBBTÝÚ]Ú   ÌÍÚTÝX][BBBBBPØÙHBBBBQÝXÝÙ]]J  ÌÍÝÝÝ]Ë   ÌÎNØÛ^ÉÌÎNË ÌÍÚPÛÛÜÊBBBBBQÝXÝÙ]]J ÌÍÝÝÝ]Ë   ÌÎNØÛ^  ÌÎNË
BBBBBPØÙHBBBBBQÝXÝÙ]]J ÌÍÝÝÝ]Ë   ÌÎNØÛ^ÉÌÎNË ÌÍÚPÛÛÜBBBBBQÝXÝÙ]]J   ÌÍÝÝÝ]Ë   ÌÎNØÛ^  ÌÎNË
BBBBBQ[ÝÚ]ÚBBBHBBBBBBBBBBBBBBPØÙH
BBBBTÝÚ]Ú    ÌÍÚTÝX][BBBBBPØÙHBBBBQÝXÝÙ]]J  ÌÍÝÝÝ]Ë   ÌÎNØÛ^ÉÌÎNË ÌÍÚPÛÛÜ
BBBBBQÝXÝÙ]]J    ÌÍÝÝÝ]Ë   ÌÎNØÛ^  ÌÎNË
BBBBBPØÙHBBBBBQÝXÝÙ]]J ÌÍÝÝÝ]Ë   ÌÎNØÛ^ÉÌÎNË ÌÍÚPÛÛÜBBBBBQÝXÝÙ]]J   ÌÍÝÝÝ]Ë   ÌÎNØÛ^  ÌÎNË
BBBBBQ[ÝÚ]ÚBBBBBBBBBBBBBBBBBBBPØÙH
ÂBBBBTÝÚ]Ú  ÌÍÚTÝX][BBBBBPØÙHBBBBQÝXÝÙ]]J  ÌÍÝÝÝ]Ë   ÌÎNØÛ^ÉÌÎNË ÌÍÚPÛÛÜJBBBBBQÝXÝÙ]]J  ÌÍÝÝÝ]Ë   ÌÎNØÛ^  ÌÎNË
BBBBBPØÙHBBBBBQÝXÝÙ]]J ÌÍÝÝÝ]Ë   ÌÎNØÛ^ÉÌÎNË ÌÍÚPÛÛÜBBBBBQÝXÝÙ]]J   ÌÍÝÝÝ]Ë   ÌÎNØÛ^  ÌÎNË
BBBBBQ[ÝÚ]ÚBBBHBBBBBBBBBBBBBBPØÙHBBBBTÝÚ]Ú  ÌÍÚTÝX][BBBBBPØÙHBBBBQÝXÝÙ]]J  ÌÍÝÝÝ]Ë   ÌÎNØÛ^ÉÌÎNË ÌÍÚPÛÛÜJBBBBBQÝXÝÙ]]J  ÌÍÝÝÝ]Ë   ÌÎNØÛ^  ÌÎNË
BBBBBPØÙHBBBBBQÝXÝÙ]]J ÌÍÝÝÝ]Ë   ÌÎNØÛ^ÉÌÎNË ÌÍÚPÛÛÜBBBBBQÝXÝÙ]]J   ÌÍÝÝÝ]Ë   ÌÎNØÛ^  ÌÎNË
BBBBBQ[ÝÚ]ÚBBBBBBBBBBBBBBBBBBBPØÙHBBBBBTÝÚ]Ú    ÌÍÚTÝX][BBBBHØÙHBBBBQÝXÝÙ]]J   ÌÍÝÝÝ]Ë   ÌÎNØÛ^ÉÌÎNË ÌÍÚPÛÛÜJBBBBBQÝXÝÙ]]J  ÌÍÝÝÝ]Ë   ÌÎNØÛ^  ÌÎNË
BBBBBPØÙHBBBBBQÝXÝÙ]]J ÌÍÝÝÝ]Ë   ÌÎNØÛ^ÉÌÎNË ÌÍÚPÛÛÜBBBBBQÝXÝÙ]]J   ÌÍÝÝÝ]Ë   ÌÎNØÛ^  ÌÎNË
BBBBBQ[ÝÚ]ÚBBBHBBBHBBBHBBBH[ÝÚ]ÚBBBT] ÌÍÐÑÓUÑÓBBBBBBBBQ[ÝÚ]Ú[ÝÚ]Ú]   ÌÍÑÕRWÔSQTÑÂ[[ÈÏOIÝÕÓWÓÕQB[ÈÐÔ ÌÍÚPÛÛÜB]]S
]ÚY
Ý[Ê[J ÌÍÚPÛÛÜJK
KB[[

صرح السماء كان هنا

 

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

Thank you!!!

But I want know as read data value of the cells with it function.

I want read the data value of the cells because here I have the group of every cell.

For example

1.1 College and University

I read the three firts characters and save it data in one variable

$group_var="1.1"

I search the string "1.1" in the column 3 and I find:

1.1.1 Courses

1.1.2 Departments and Programs

1.1.3 Graduate Programs

1.1.4 Organization Programs

All the rows what have the string "1.1" I change the background color row to blue.

I search the string "1.2" in the column 2 and I find

1.2.1 Reading

1.2.2 Teacher Resources

All the rows what have the string "1.2" I change the background color row to orange.

OK?

What is my problem?

What I change all the background color of all the row, but I would like don't change the first column!!

All the cells of the first COLUMN I would change the background color to yellow as in the images what I have posted.

Can I do it with Autoit?

Thank you!

Edited by Juanola

Share this post


Link to post
Share on other sites

Thank you!!!

But I want know as read data value of the cells with it function.

I want read the data value of the cells because here I have the group of every cell.

For example

1.1 College and University

I read the three firts characters and save it data in one variable

$group_var="1.1"

I search the string "1.1" in the column 3 and I find:

1.1.1 Courses

1.1.2 Departments and Programs

1.1.3 Graduate Programs

1.1.4 Organization Programs

All the rows what have the string "1.1" I change the background color row to blue.

I search the string "1.2" in the column 2 and I find

1.2.1 Reading

1.2.2 Teacher Resources

All the rows what have the string "1.2" I change the background color row to orange.

OK?

What is my problem?

What I change all the background color of all the row, but I would like don't change the first column!!

All the cells of the first COLUMN I would change the background color to yellow as in the images what I have posted.

Can I do it with Autoit?

Thank you!

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


Global $ArrayColor[1][3]
$ArrayColor[0][0] = 0
$Start = 1
AddiColor(0x8080FF,"1.1")
AddiColor(0xFF8040,"1.2")
;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)

_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 10
_GUICtrlListView_AddItem($hListView, "Row" & $i & ": Col 1", $i-1)
Next




_GUICtrlListView_SetItemText($hListView, 0, "1.2.1 Reading", 1)
_GUICtrlListView_SetItemText($hListView, 1, "1.2.2 Teacher Resources", 1)
_GUICtrlListView_SetItemText($hListView, 0, "1.1.1 Courses", 2)
_GUICtrlListView_SetItemText($hListView, 1, "1.1.2 Departments and Programs", 2)
_GUICtrlListView_SetItemText($hListView, 2, "1.1.3 Graduate Programs", 2)
_GUICtrlListView_SetItemText($hListView, 3, "1.1.4 Organization Programs", 2)





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 AddiColor($iColor ,$string)
$ArrayColor[0][1] = "string"
$ArrayColor[0][2] = "iColor"
ReDim $ArrayColor[$ArrayColor[0][0] + 2][3]
$ArrayColor[$ArrayColor[0][0] + 1][1] = $string
$ArrayColor[$ArrayColor[0][0] + 1][2] = RGB2BGR($iColor)
$ArrayColor[0][0] = $ArrayColor[0][0] + 1
EndFunc

Func GetiColor($string)
$string = StringLeft($string, 3)
For $i = 1 To $ArrayColor[0][0]
if StringUpper($string) =  StringUpper($ArrayColor[$i][1]) _
Then Return $ArrayColor[$i][2]
Next
Return -1
EndFunc

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
                   
                    $iItem = DllStructGetData($tCustDraw, 'ItemSpec')
                    $iSubitem = DllStructGetData($tCustDraw, 'SubItem')
                    $string = _GUICtrlListView_GetItemText($cListView, $iItem, $iSubitem)
                    $iColor = GetiColor($string)
                    DllStructSetData($tCustDraw, 'clrTextBk', $iColor)
                    DllStructSetData($tCustDraw, 'clrText', 0)
                    
                    
            Return $CDRF_NEWFONT
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY

Func RGB2BGR($iColor)
    Return BitAND(BitShift(String(Binary($iColor)), 8), 0xFFFFFF)
EndFunc

صرح السماء كان هنا

 

Share this post


Link to post
Share on other sites

#13 ·  Posted (edited)

or

#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)

_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 10
_GUICtrlListView_AddItem($hListView, "Row" & $i & ": Col 1", $i-1)
Next




_GUICtrlListView_SetItemText($hListView, 0, "1.2.1 Reading", 1)
_GUICtrlListView_SetItemText($hListView, 1, "1.2.2 Teacher Resources", 1)
_GUICtrlListView_SetItemText($hListView, 0, "1.1.1 Courses", 2)
_GUICtrlListView_SetItemText($hListView, 1, "1.1.2 Departments and Programs", 2)
_GUICtrlListView_SetItemText($hListView, 2, "1.1.3 Graduate Programs", 2)
_GUICtrlListView_SetItemText($hListView, 3, "1.1.4 Organization Programs", 2)





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


Global $ArrayColor[1][3]
$ArrayColor[0][0] = 0
$SetColor = 0
AddiColor(0x8080FF,"1.1")
AddiColor(0xFF8040,"1.2")


$column__No = 3
$Txt1 = "1.1"
FindcolumnText_Replace_Color($cListView,$column__No,$Txt1)


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

Func FindcolumnText_Replace_Color($cListView,$column_No,$Txt1)
$Count = _GUICtrlListView_GetItemCount($cListView)
For $i = 0 To $Count Step 1
$Txt2 = _GUICtrlListView_GetItemText($cListView, $i, $column_No - 1)
if StringLeft($Txt2 ,3) = $Txt1 Then 
EnvSetiColor($i ,$column_No,$Txt1)
EndIf
Next
_WinAPI_RedrawWindow($GUI,0,0, 5)
EndFunc

Func EnvSetiColor($iItem ,$column_No,$Txt1)
EnvSet($iItem & ($column_No - 1), GetiColor($Txt1))
EndFunc

Func AddiColor($iColor ,$string)
$ArrayColor[0][1] = "string"
$ArrayColor[0][2] = "iColor"
ReDim $ArrayColor[$ArrayColor[0][0] + 2][3]
$ArrayColor[$ArrayColor[0][0] + 1][1] = $string
$ArrayColor[$ArrayColor[0][0] + 1][2] = RGB2BGR($iColor)
$ArrayColor[0][0] = $ArrayColor[0][0] + 1
EndFunc

Func GetiColor($string)
$string = StringLeft($string, 3)
For $i = 1 To $ArrayColor[0][0]
if StringUpper($string) =  StringUpper($ArrayColor[$i][1]) _
Then Return $ArrayColor[$i][2]
Next
Return -1
EndFunc

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
                   
                    $iItem = DllStructGetData($tCustDraw, 'ItemSpec')
                    $iSubitem = DllStructGetData($tCustDraw, 'SubItem')
                    $iColor = EnvGet($iItem & $iSubitem )
                    if $iColor <> "" Then
                    DllStructSetData($tCustDraw, 'clrTextBk', $iColor)
                    DllStructSetData($tCustDraw, 'clrText', 0)
                    Else
                    DllStructSetData($tCustDraw, 'clrTextBk', -1)
                    DllStructSetData($tCustDraw, 'clrText', 0)
                    EndIf
            Return $CDRF_NEWFONT
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY

Func RGB2BGR($iColor)
    Return BitAND(BitShift(String(Binary($iColor)), 8), 0xFFFFFF)
EndFunc
Edited by wolf9228

صرح السماء كان هنا

 

Share this post


Link to post
Share on other sites

Thank you very much!!!

Your script is great!!!! It have solved my problem!!!

Greetings!!!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0