Jump to content

GUICtrlSetBkColor on ListView works inconsistant


Kohr
 Share

Recommended Posts

Does anyone know why the attached code I am working on does not set the color correctly for the ListView. If I force in the number values for the 2 loops I am using then the colors are set correctly in the control. They do not get set if I use values from array either directly or indirectly.

The attached code works. Just make sure the region is not white (have all windows minimized) and you will see each row BkColor is correct (unless you actually use a white BG).

Any ideas on why it doesn't work using an array directly instead of forcing the numbers in the loop?

Kohr

#include <GUIConstants.au3>
#include <Date.au3>
#include <Array.au3>
#Include <Misc.au3>
#include <GuiListView.au3>

Opt("GUIOnEventMode", 1)
Opt("MouseCoordMode", 0)
Global $GUI = 9999
Global $gEditText
Global $gBoxSize[5] = [5, 0, 0, 0, 0]


HotKeySet("{HOME}", "DrawBox")
HotKeySet("{END}", "CloseClicked")
GUICreate("1", 240, 950, 1035, 0)
$btnDrawBox = GUICtrlCreateButton("DrawBox", 10, 10, 70, 20)
GUICtrlSetOnEvent($btnDrawBox, "DrawBox")
$btnGetColors = GUICtrlCreateButton("GetColors", 10, 40, 70, 20)
GUICtrlSetOnEvent($btnGetColors, "GetColors")

$lvColors = GUICtrlCreateListView("Color|X|Y", 10, 200, 220, 700, $LVS_SHOWSELALWAYS, $LVS_EX_FULLROWSELECT + $WS_EX_CLIENTEDGE + $LVS_EX_GRIDLINES)
_GUICtrlListViewSetColumnWidth($lvColors, 0, 80)
_GUICtrlListViewSetColumnWidth($lvColors, 1, 20)
_GUICtrlListViewSetColumnWidth($lvColors, 2, 20)

GUISetState()
GUISetOnEvent($GUI_EVENT_CLOSE, "CloseClicked")

While 1
    Sleep(200)
WEnd
Func GetColors()
    ConsoleWrite($gBoxSize[1] & @CRLF)
    ConsoleWrite($gBoxSize[2] & @CRLF)
    ConsoleWrite($gBoxSize[3] & @CRLF)
    ConsoleWrite($gBoxSize[4] & @CRLF)
    GUICtrlSendMsg($lvColors, $LVM_DELETEALLITEMS, 0, 0)
    ;   For $y = Number($gBoxSize[2]) To Number($gBoxSize[4])   ;DOES NOT WORK
    ;       For $x = $gBoxSize[1] To $gBoxSize[3]               ;DOES NOT WORK
;~  $a = Number($gBoxSize[2])                               ;DOES NOT WORK
;~  $b = Number($gBoxSize[4])                               ;DOES NOT WORK
;~  $c = Number($gBoxSize[1])                               ;DOES NOT WORK
;~  $d = Number($gBoxSize[3])                               ;DOES NOT WORK
;~  $a = 93         ;WORKS
;~  $b = 95         ;WORKS
;~  $c = 371        ;WORKS
;~  $d = 380        ;WORKS
;~      For $y = $a To $b
;~          For $x = $c To $d
    For $y = 93 To 95
        For $x = 371 To 380
            $Color = Hex(PixelGetColor($x, $y), 6)
            GUICtrlCreateListViewItem($Color & "|" & $x & "|" & $y, $lvColors)
            GUICtrlSetBkColor(-1, "0x" & $Color)
        Next
    Next
EndFunc   ;==>GetColors
Func DrawBox()
    Opt("MouseCoordMode", 1)
    GUIDelete($GUI)
    GUICtrlSetData($btnDrawBox, "Drawing...")
    Local $ScanWidth = 1, $ScanHeight = 1
    While 1
        If _IsPressed(01) Then
            $pos = MouseGetPos()
            ExitLoop
        EndIf
    WEnd
    $x = $pos[0]
    $y = $pos[1]
    $GUI = GUICreate("", 0, 0, $x, $y, $WS_POPUP)
    $Top = GUICreate("Top Line", $ScanWidth, 2, $x, $y, $WS_POPUP, -1, $GUI)
    GUISetBkColor(0xFF0000)
    GUISetState()
    $Left = GUICreate("Left Line", 2, $ScanHeight, $x, $y, $WS_POPUP, -1, $GUI)
    GUISetBkColor(0xFF0000)
    GUISetState()
    $Right = GUICreate("Right Line", 2, $ScanHeight, $x + $ScanWidth - 2, $y, $WS_POPUP, -1, $GUI)
    GUISetBkColor(0xFF0000)
    GUISetState()
    $Bottom = GUICreate("Bottom Line", $ScanWidth, 2, $x, $y + $ScanHeight, $WS_POPUP, -1, $GUI)
    GUISetBkColor(0xFF0000)
    GUISetState()
    Sleep(800)
    While 1
        $MousePos = MouseGetPos()
        WinMove($Top, "", $x, $y, $ScanWidth, 2)
        WinMove($Left, "", $x, $y, 2, $ScanHeight)
        WinMove($Right, "", $x + $ScanWidth - 2, $y, 2, $ScanHeight)
        WinMove($Bottom, "", $x, $y + $ScanHeight, $ScanWidth, 2)
        If Not (($MousePos[0] - $x) <= 0) Then
            $ScanWidth = $MousePos[0] - $x + 1
        EndIf
        If Not (($MousePos[1] - $y) <= 0) Then
            $ScanHeight = $MousePos[1] - $y - 1
        EndIf
        If _IsPressed(01) Then
            ExitLoop
        EndIf
    WEnd
    $gBoxSize[1] = $pos[0]
    $gBoxSize[2] = $pos[1]
    $gBoxSize[3] = $MousePos[0]
    $gBoxSize[4] = $MousePos[1]
    GUICtrlSetData($btnDrawBox, "DrawBox")
    Return 1
EndFunc   ;==>DrawBox
Func CloseClicked()
    Exit
EndFunc   ;==>CloseClicked
Link to comment
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
 Share

  • Recently Browsing   0 members

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