Jump to content

Color only parts of row


Recommended Posts

OK, I have my app below. It does what I want but I need to have only conlumns 1 and 2 colored light green BUT ONLY if it is YES. I can't find out how to do that.

Cut and paste the following HEX string into the input box for testing if necessary:

0xE001FFFD7D5F0400007000140000435FFF32

P.S. This is a cluge of many others works. I don't remember where they all came from but am sure glad this forum and the folks willing to help is here!!

Thanks

E

#include <Color.au3>
#include <GUIConstantsEX.au3>
#include <GuiListView.au3>
#include <GuiImageList.au3>
#include <String.au3>
#include <WindowsConstants.au3>
Global Const $HX_REF="0123456789ABCDEF"
Global Const $color1 = 0x99A8AC
Global Const $color2 = 0xFFFFFF

;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("Plan Decoder", 400, 350, 161, 166)
GUISetIcon (@windowsdir & "system32Calc.exe",-1,$Gui)
$Size = WinGetClientSize($Gui)
$GoButton = GUICtrlCreateButton ("Go", 300, 100, 60, 20)
GUICtrlSetBkColor(-1,0xA1AFB2)
$label = GUICtrlCreateLabel("", 10, 15, 50, 15)
GUICtrlSetBkColor(-1,0xA1AFB2)
$labelout2 = GUICtrlCreateLabel("Cut and paste the HEX information below", 10, 5, 300, 15)
GUICtrlSetBkColor(-1,0xAEBABD)
$labelout = GUICtrlCreateLabel("Plan", 10, 45, 70, 15)
GUICtrlSetBkColor(-1,0xAEBABD)
$Input1 = GUICtrlCreateInput("", 100, 40, 250, 21)
;~ $list1 = GUICtrlCreateList("Ch # Selected",50, 75, 250, 250, BitOr($WS_BORDER, $WS_VSCROLL))
    Local $list1 = GUICtrlCreateListView("", 10, 75, 300 - 20, 250, BitOR($LVS_REPORT, $LVS_SINGLESEL, $WS_BORDER), $LVS_EX_FULLROWSELECT)
$hListView = ControlGetHandle($gui, '', $list1)
_GUICtrlListView_InsertColumn($hListView, 0, "Ch #", 40,2)
_GUICtrlListView_InsertColumn($hListView, 1, "Selected", 60, 2)
_GUICtrlListView_InsertColumn($hListView, 2, "Test info", 140, 2)
_GUICtrlCreateGradient($color1, $color2, 0, 0, $size[0]*1.5, $size[1])
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
GUISetState()

While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop
        Case $msg = $GoButton
   ; delete anything in the listview first
    _GUICtrlListView_DeleteAllItems($list1)
   $input2process = GUICtrlRead($Input1)
   $inputNew = stringmid($input2process, 7, stringlen($input2process) - 8)
   $BinaryString = StringMid(_HexToBinaryString(StringStripWS($inputNew,8)), 1, 124)
   ConsoleWrite('Binary String returned: ' & $BinaryString & @CRLF & 'Binary len: ' & StringLen($BinaryString) & @CRLF)
   if $BinaryString = 0 Then
    MsgBox(0,"Error","Wrong input, try again ...")
    ContinueLoop
   EndIf
   $y = 1
   for $i = 1 to StringLen($BinaryString)
    ConsoleWrite($i + 4 & " - " & StringMid($BinaryString, $i, 1) & @CRLF)
    Switch $i + 4
     Case 5 To 9
      $channelNum = '   ' & $i + 4
     Case 10 To 99
      $channelNum = '  ' & $i + 4
     Case 100 To 999
      $channelNum = ' ' & $i + 4
     Case Else
      $channelNum = $i + 4
    EndSwitch
    if StringMid($BinaryString, $i, 1) = 1 Then
     $chanSelected = "  Yes"
    Else
     $chanSelected = ""
    EndIf
    $ch = ""
    ; check the len of the input line anfor output to the screen for the channel hex information
    if $y <= StringLen($inputNew) Then
     switch $i
      case 1
       $ch = 'Channels 005-012: 0x' & StringLower(StringMid($inputNew, $y, 2))
      case 2
       $ch = 'Channels 013-020: 0x' & StringLower(StringMid($inputNew, $y, 2))
      Case 3
       $ch = 'Channels 021-028: 0x' & StringLower(StringMid($inputNew, $y, 2))
      Case 4
       $ch = 'Channels 029-036: 0x' & StringLower(StringMid($inputNew, $y, 2))
      Case 5
       $ch = 'Channels 037-044: 0x' & StringLower(StringMid($inputNew, $y, 2))
      Case 6
       $ch = 'Channels 045-052: 0x' & StringLower(StringMid($inputNew, $y, 2))
      Case 7
       $ch = 'Channels 053-060: 0x' & StringLower(StringMid($inputNew, $y, 2))
      Case 8
       $ch = 'Channels 061-068: 0x' & StringLower(StringMid($inputNew, $y, 2))
      Case 9
       $ch = 'Channels 069-076: 0x' & StringLower(StringMid($inputNew, $y, 2))
      Case 10
       $ch = 'Channels 077-084: 0x' & StringLower(StringMid($inputNew, $y, 2))
      Case 11
       $ch = 'Channels 085-092: 0x' & StringLower(StringMid($inputNew, $y, 2))
      Case 12
       $ch = 'Channels 093-100: 0x' & StringLower(StringMid($inputNew, $y, 2))
      Case 13
       $ch = 'Channels 101-108: 0x' & StringLower(StringMid($inputNew, $y, 2))
      Case 14
       $ch = 'Channels 109-116: 0x' & StringLower(StringMid($inputNew, $y, 2))
      Case 15
       $ch = 'Channels 117-124: 0x' & StringLower(StringMid($inputNew, $y, 2))
      Case 16 to 1000
       $ch = ''
        EndSwitch
        $y += 2
    EndIf
    ConsoleWrite("I = " & $i & '   Channels variable: ' & $ch & @CRLF)
    _GUICtrlListView_AddItem($hListView, $i+4, $channelNum, $i-1)
    _GUICtrlListView_AddSubItem ($hListView, $i-1,  $chanSelected, 1)
    _GUICtrlListView_AddSubItem ($hListView, $i-1,  $ch, 2)
   Next
    EndSelect
WEnd
; Conversion Code - Chart
; DECIMAL  0    1   2   3   4   5   6   7   8   9   10   11   12   13   14   15   16
; HEX     0 1   2   3   4   5   6   7   8   9   A   B   C   D   E   F   10
; BINARY 0000 0001 0010 0011 0100 0101 0110 0111 1000 1001 1010 1011 1100 1101 1110 1111  10000

; --------------------- Functions -----------------------------
; Hex To Binary
Func _HexToBinaryString($hexvalue)
    Local $Allowed = '0123456789ABCDEF'
    Local $Test,$n
    Local $Result = ''
    if $hexvalue = '' then
        SetError(-2)
        Return
    EndIf
    $hexvalue = StringSplit($hexvalue,'')
    for $n = 1 to $hexValue[0]
        if not StringInStr($Allowed,$hexvalue[$n]) Then
            SetError(-1)
            return 0
        EndIf
    Next
    Local $bits = "0000|0001|0010|0011|0100|0101|0110|0111|1000|1001|1010|1011|1100|1101|1110|1111"
    $bits = stringsplit($bits,'|')
    for $n = 1 to $hexvalue[0]
        $Result &=  $bits[Dec($hexvalue[$n])+1]
    Next
    Return $Result
EndFunc
Func _GUICtrlCreateGradient($nStartColor, $nEndColor, $nX, $nY, $nWidth, $nHeight)
    Local $color1R = _ColorGetRed($nStartColor)
    Local $color1G = _ColorGetGreen($nStartColor)
    Local $color1B = _ColorGetBlue($nStartColor)
    Local $nStepR = (_ColorGetRed($nEndColor) - $color1R) / $nHeight
    Local $nStepG = (_ColorGetGreen($nEndColor) - $color1G) / $nHeight
    Local $nStepB = (_ColorGetBlue($nEndColor) - $color1B) / $nHeight
    GuiCtrlCreateGraphic($nX, $nY, $nWidth, $nHeight)
    For $i = 0 To $nHeight - $nY
        $sColor = "0x" & StringFormat("%02X%02X%02X", $color1R+$nStepR*$i, $color1G+$nStepG*$i, $color1B+$nStepB*$i)
        GUICtrlSetGraphic(-1, $GUI_GR_COLOR, $sColor, 0xffffff)
        GUICtrlSetGraphic(-1, $GUI_GR_MOVE, 0, $i)
        GUICtrlSetGraphic(-1, $GUI_GR_LINE, $nWidth, $i)
    Next
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
                    If Not BitAND($iDrawStage, $CDDS_SUBITEM) Then Return $CDRF_DODEFAULT
                    $iItem = DllStructGetData($tCustDraw, 'ItemSpec')
                    $iSubitem = DllStructGetData($tCustDraw, 'SubItem')
;~
                    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 dickep
Link to post
Share on other sites

Thanks Zedna, but I am still confused.

How do I just do the first 2 columns of the 3 IF and ONLY IF the variable $chanSelected is "Yes"?

I looked over the thread you referenced, but I guess my feeble mind can't figure out how to put that to use in my app.

Again, thanks and hope you can understand that I am not an expert programmer, more of an advanced novice.

Link to post
Share on other sites

Very simple way is to use global array and store $chanSelected yes/no state for each listview item into it.

Index of that array will be the same as listview item index.

In WM_NOTIFY you can find appropriate yes/no state from that array based on item index

and set appropriate color for subitems (of that particular item).

Now I have no time to write sample script for you ...

Link to post
Share on other sites
  • Moderators

dickep,

Add these few lines to your exiting code: :rip:

$iItem = DllStructGetData($tCustDraw, 'ItemSpec')
$iSubitem = DllStructGetData($tCustDraw, 'SubItem')

; ~~~~~~~~~~ NEW ~~~~~~~~~~~~~~~~

; Does the second column say "Yes"
If StringInStr(_GUICtrlListView_GetItemText($hListView, $iItem, 1), "Yes") Then
    ; Then colour the first 2 rows
    If $iSubitem <> 2 Then
        DllStructSetData($tCustDraw, 'clrTextBk', 0x88FF88)
    Else
        DllStructSetData($tCustDraw, 'clrTextBk', 0xFEFEFE)
    EndIf
EndIf

; ~~~~~~~~~~ NEW ~~~~~~~~~~~~~~~~

Return $CDRF_NEWFONT

That works for me. :oops:

Thanks for the question - I learnt a lot about colouring ListViews today. :D

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

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

    No registered users viewing this page.

×
×
  • Create New...