Jump to content

Recommended Posts

Posted (edited)

Bah!

Never factored that I have multiple Listviews in my gui.  This tries to apply the colours to listviews which are different and subsequently crashes.

Tried to first check if the correct tab was active in WM_NOTIFY, but the WM_NOTIFY function appears to be actioned before the tab appears and I can get the text from it.

EDIT:

Never mind, answer >here.

Just need ti implement it in my code.

Edited by JohnOne

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Posted

Never factored that I have multiple Listviews in my gui.  This tries to apply the colours to listviews which are different and subsequently crashes.

 

Strange, I had no crash. :mellow:

If you learn from It, it's not a mistake

  • 4 years later...
Posted (edited)

Sorry, I know this is old thread but as I am trying out @LarsJ code so asking here.

@LarsJ

Is there any other way to color ListView specific cell if logic is true. Without using DllStruct.
I don’t understand DllStructucture logic properly & in my case Array size is no to big [30][15].
So can it be done using GUICtrlSetBkColor or _GUICtrlListView_CreateSolidBitMap?

Edited by jugador
Posted

The custom draw technique is the great, right, flexible and fast way to apply colors in a listview. Read about DllStruct in the help file and just ask more questions if you have any doubts.

Posted

@LarsJ

ok I get it how to color listview but
No I didnt get it how DllStruct work 😂.

I use @mikell code to understand how it work.

#include <GUIConstantsEx.au3>
#include <GuiListView.au3>
#include <WindowsConstants.au3>

Global $myitem = -1, $mysubitem = -1

$Form1 = GUICreate("Form1", 350, 250, -1, -1)
$ListView1 = GUICtrlCreateListView("Header|Header|Header", 0, 0, 350, 200)

GuiCtrlCreateListViewItem('White|White|White',$ListView1)
GuiCtrlCreateListViewItem('Pink|Green|Pink',$ListView1)
GuiCtrlCreateListViewItem('White|White|White',$ListView1)
$btn = GuiCtrlCreateButton('button', 20, 210, 50, 25)

$iRows = 3
$iCols = 3
Global $aColors[$iRows][$iCols]

For $i = 0 To $iRows - 1
    For $j = 0 To $iCols - 1
        If $i = 1 Then
            If $j = 1 Then
                $aColors[$i][$j] = RGB2BGR(0x00aa00)  ; green
            Else
                $aColors[$i][$j] = RGB2BGR(0xffaaff)  ; pink
            EndIf
        Else
            $aColors[$i][$j] = RGB2BGR(0xFFFFFF)  ; white
        EndIf
    Next
Next

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

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $btn
            $aColors[1][1] = RGB2BGR(0xFF0000)  ; red
            _GUICtrlListView_SetItemText($ListView1, 1, "Red", 1)
    EndSwitch
WEnd



Func WM_NOTIFY($hWnd, $Msg, $wParam, $lParam)
     Local $tNMHDR, $hWndFrom, $iCode
     $tNMHDR = DllStructCreate($tagNMHDR, $lParam)
     $hWndFrom = DllStructGetData($tNMHDR, "hWndFrom")
     $iCode = DllStructGetData($tNMHDR, "Code")
     $hListView = GuiCtrlGetHandle($ListView1)

    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")
                    DllStructSetData($tCustDraw, "clrTextBk", $aColors[$iItem][$iSubItem]) ; background color
                    Return $CDRF_NEWFONT
             EndSwitch
     EndSwitch
    Return $GUI_RUNDEFMSG
 EndFunc   ;==>WM_NOTIFY


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

 

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...