Jump to content

Retrieve Text colour of label.


JohnOne
 Share

Recommended Posts

Is there anyway to retrieve the current text colour of a label control, as set by GUICtrlSetColor() ?

Ive doen a thorough search of help file but cannot find an answer.

Just hoping that there is a solution.

Appreciate any pointers.

EDIT: (extra info)

Its to add to this function I've been doing (live log) http://www.autoitscript.com/forum/index.php?showtopic=110023

The function srolls my code log via a GUI on the fly, and I want it to show and warnings or errors up in certain colours you see.

Edited by JohnOne

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

Monkey's are, like, natures humans.

Link to comment
Share on other sites

  • Moderators

JohnOne,

As you can see here a request for the GUICtrlGet* commands was rejected by the Devs a long time ago.

I just wrote this little function, which you might find useful - although it does depend on there being some text to get the colour from: :mellow:

#include <GUIConstantsEx.au3>
#include <WinAPI.au3>

Global $aSetColors[2] = [0xFF0000, 0x00FF00]

$hGUI = GUICreate("Test", 500, 500)

$hLabel = GUICtrlCreateLabel("Testing", 10, 10, 100, 20)
GUICtrlSetColor(-1, 0xFF0000)
GUICtrlSetBkColor(-1, 0x00FF00)

$hButton = GUICtrlCreateButton("Get Colours", 10, 50, 80, 30)

GUISetState()

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $hButton
            $aGetColors = _GetColors($hLabel)
            If @error Then
                ConsoleWrite("No text available to read" & _
                @CRLF & "Background:   Set: " & Hex($aSetColors[1], 6) & " - Get: " & Hex($aGetColors[1], 6) & @CRLF)
            Else
                ConsoleWrite("Foreground:   Set: " & Hex($aSetColors[0], 6) & " - Get: " & Hex($aGetColors[0], 6) & _
                     @CRLF & "Background:   Set: " & Hex($aSetColors[1], 6) & " - Get: " & Hex($aGetColors[1], 6) & @CRLF)
            EndIf
    EndSwitch

WEnd

Func _GetColors($hControl)

    Local $aColors[2], $tpoint = DllStructCreate("int X;int Y")

    ; Get position of control
    Local $aPos = ControlGetPos($hGUI, "", $hControl)
    ; Convert to screen coords
    DllStructSetData($tpoint, "X", $aPos[0])
    DllStructSetData($tpoint, "Y", $aPos[1])
    _WinAPI_ClientToScreen($hGUI, $tPoint)
    $aPos[0] = DllStructGetData($tpoint, "X") + 1 ; Needs the added 1 to hit the first coloured pixel
    $aPos[1] = DllStructGetData($tpoint, "Y") + 1 ; I have no idea why

    ; read colour at top left - assume it is background
    $aColors[1] = PixelGetColor($aPos[0], $aPos[1])
    ; Sweep through control to find another colour
    For $iX = $aPos[0] To $aPos[0] + $aPos[2] - 2 ; Again the need to adjust the coords returned by ControlGetPos
        For $iY = $aPos[1] To $aPos[1] + $aPos[3] - 2 ; And here too
            If PixelGetColor($iX, $iY) <> $aColors[1] Then
                ; Assume that it is text colour
                $aColors[0] = PixelGetColor($iX, $iY)
                Return $aColors
            EndIf
        Next
    Next

    ; Text colour not found, so return array, but set error as a flag
    $aColors[0] = 0
    Return SetError(-1, 0, $aColors)

EndFunc

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 comment
Share on other sites

Thanks M23, Superb mate.

I'd have been able to do that in a couple of years time, not dared venture into dll stuff yet or winapi for that matter.

Much Apreciated Amigo, will get to work trying to understand it, and apply it to my code.

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

Monkey's are, like, natures humans.

Link to comment
Share on other sites

  • Moderators

JohnOne ,

Big difference between direct DLL calls and the WinAPI UDF - although the latter are actually just wrappers around DLL calls themselves!

The UDF is as easy to use as "normal" AutoIt functions and it offers a huge range of powers which would be very difficult to achieve with direct DLL calls by the likes of you and me. Yashied has also produced WinAPIEx.au3 to give even more access to the power of the API. The various WinAPI functions are clearly explained the Help file - give them a look over. As in this case you will realise that they are not difficult to use - but if you do not even realise that they are there..... :mellow:

M23

Edit: I do not know why I needed that adjustment for the label position earlier - it worked as I expected when I tried it a moment ago. Just to prove it, the label can be moved around the GUI and still return the corerct values!

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <MenuConstants.au3>
#include <SendMessage.au3>
#include <WinAPI.au3>

Global $aSetColors[2] = [0xFF0000, 0x00FF00]

$hGUI = GUICreate("Test", 500, 500)

$hLabel = GUICtrlCreateLabel("Move Me Around", 10, 10, 100, 20)
GUICtrlSetColor(-1, 0xFF0000)
GUICtrlSetBkColor(-1, 0x00FF00)

$hButton = GUICtrlCreateButton("Get Colours", 10, 50, 80, 30)

GUISetState()

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $GUI_EVENT_PRIMARYDOWN
            _ControlMove($hLabel)
        Case $hButton
            $aGetColors = _GetColors($hLabel)
            If @error Then
                ConsoleWrite("No text available to read" & _
                @CRLF & "Background:   Set: " & Hex($aSetColors[1], 6) & " - Get: " & Hex($aGetColors[1], 6) & @CRLF)
            Else
                ConsoleWrite("Foreground:   Set: " & Hex($aSetColors[0], 6) & " - Get: " & Hex($aGetColors[0], 6) & _
                     @CRLF & "Background:   Set: " & Hex($aSetColors[1], 6) & " - Get: " & Hex($aGetColors[1], 6) & @CRLF)
            EndIf
    EndSwitch

WEnd

Func _ControlMove($hControl)

    Local $aCurPos = GUIGetCursorInfo()
    If @error Then Return False
    If $aCurPos[4] = $hControl Then _SendMessage(GUICtrlGetHandle($hControl), $WM_SYSCOMMAND, BitOR($SC_MOVE, $HTCAPTION), 0)
    Return True

EndFunc

Func _GetColors($hControl)

    Local $aColors[2], $tpoint = DllStructCreate("int X;int Y")

    ; Get position of control
    Local $aPos = ControlGetPos($hGUI, "", $hControl)
    ; Convert to screen coords
    DllStructSetData($tpoint, "X", $aPos[0])
    DllStructSetData($tpoint, "Y", $aPos[1])
    _WinAPI_ClientToScreen($hGUI, $tPoint)
    $aPos[0] = DllStructGetData($tpoint, "X")
    $aPos[1] = DllStructGetData($tpoint, "Y")

    ; read colour at top left - assume it is background
    $aColors[1] = PixelGetColor($aPos[0], $aPos[1])
    ; Sweep through control to find another colour
    For $iX = $aPos[0] To $aPos[0] + $aPos[2] - 1
        For $iY = $aPos[1] To $aPos[1] + $aPos[3] - 1
            If PixelGetColor($iX, $iY) <> $aColors[1] Then
                ; Assume that it is text colour
                $aColors[0] = PixelGetColor($iX, $iY)
                Return $aColors
            EndIf
        Next
    Next

    ; Text colour not found, so return array, but set error as a flag
    $aColors[0] = 0
    Return SetError(-1, 0, $aColors)

EndFunc
Edited by Melba23

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 comment
Share on other sites

I am aware of the API fuctions in the helpfile, I just havent felt confident enough to use, them yet.

Until now, the autoit built in functions have more or less provided everything I need apart from some cutsom functions.

I have a feeling Im about to embark on an educational journey now though.

The function you wrote above _GetColors() has a couple of problems (on my machine anyway)

It very much slows down my log (by about 30x) maybe more.

And (I think due to the nature of a font) does not get the correct color, so I get like a faded effect of the color I input.

I was using a mouse click to test it.

The bottom colour is what I origionaly set and the colours above are got from the one below it.

Posted Image

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

Monkey's are, like, natures humans.

Link to comment
Share on other sites

  • Moderators

JohnOne,

The great disadvantage of API calls is that they sometimes tend to take a bit of time to complete - relative to normal computer speed of course! :mellow:

Can you post your code so I can take a look? It worked correctly on my test script as you saw.

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 comment
Share on other sites

Without colours

#include <Array.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GDIPlus.au3>

Global $aGuiData[20]
Global $Gui
Global $Newdata

Func _GuiCreate(ByRef $aGuiData)
    $Gui = GUICreate("Test", 400, 400, 500, 100)
    Local $a = 0
    For $i = 5 To 290 Step 15
        $aGuiData[$a] = GUICtrlCreateLabel($a, 5, $i, 390, 20)
        $a += 1
    Next

    GUISetState()
EndFunc   ;==>_GuiCreate

Func _UpdateGui($Newdata)
    Local $temp
    For $i = 0 To 18
        $temp = GUICtrlRead($aGuiData[$i + 1])
        GUICtrlSetData($aGuiData[$i], $temp)
    Next
        GUICtrlSetData($aGuiData[19], $Newdata)


EndFunc   ;==>_UpdateGui

_GuiCreate($aGuiData)
For $i = 20 To 100
    ;Sleep(60)
    _UpdateGui($i)
Next

While 1
    Sleep(10)
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            Exit
    EndSelect
WEnd

With colours

#include <Array.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GDIPlus.au3>

Global $aGuiData[20]
Global $hGui
Global $Newdata
Global $Color = 0x000000

Func _GuiCreate(ByRef $aGuiData)
    $hGui = GUICreate("Test", 400, 400, 500, 100)
    Local $a = 0
    For $i = 5 To 290 Step 15
        $aGuiData[$a] = GUICtrlCreateLabel($a, 5, $i, 390, 20)
        $a += 1
    Next

    GUISetState()
EndFunc   ;==>_GuiCreate

Func _UpdateGui($Newdata, $Colour)
    Local $temp
    For $i = 0 To 18
        $temp = GUICtrlRead($aGuiData[$i + 1])
        $tempc = _GetColors($aGuiData[$i + 1])
        GUICtrlSetData($aGuiData[$i], $temp)
        GUICtrlSetColor($aGuiData[$i], $tempc[0])
    Next
        GUICtrlSetData($aGuiData[19], $Newdata)
        GUICtrlSetColor($aGuiData[19], $Color)


EndFunc   ;==>_UpdateGui

_GuiCreate($aGuiData)
For $i = 20 To 100
    ;Sleep(60)
    _UpdateGui($i, $Color)
Next

While 1
    Sleep(50)
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            Exit
    EndSelect
WEnd

Func _GetColors($hControl)

    Local $aColors[2], $tpoint = DllStructCreate("int X;int Y")

    ; Get position of control
    Local $aPos = ControlGetPos($hGUI, "", $hControl)
    ; Convert to screen coords
    DllStructSetData($tpoint, "X", $aPos[0])
    DllStructSetData($tpoint, "Y", $aPos[1])
    _WinAPI_ClientToScreen($hGUI, $tPoint)
    $aPos[0] = DllStructGetData($tpoint, "X") ; Needs the added 1 to hit the first coloured pixel
    $aPos[1] = DllStructGetData($tpoint, "Y") ; I have no idea why

    ; read colour at top left - assume it is background
    $aColors[1] = PixelGetColor($aPos[0], $aPos[1])
    ; Sweep through control to find another colour
    For $iX = $aPos[0] To $aPos[0] + $aPos[2] - 2 ; Again the need to adjust the coords returned by ControlGetPos
        For $iY = $aPos[1] To $aPos[1] + $aPos[3] - 2 ; And here too
            If PixelGetColor($iX, $iY) <> $aColors[1] Then
                ; Assume that it is text colour
                $aColors[0] = PixelGetColor($iX, $iY)
                Return $aColors
            EndIf
        Next
    Next

    ; Text colour not found, so return array, but set error as a flag
    $aColors[0] = 0
    Return SetError(-1, 0, $aColors)

EndFunc

Pretty wierd.

Edited by JohnOne

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

Monkey's are, like, natures humans.

Link to comment
Share on other sites

  • Moderators

JohnOne,

It is working fine for me - the colours move up as they should. Try this "rainbow" version and see if you still have the same problem - I get the same colours in the same order throughout:

#include <Array.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GDIPlus.au3>

Global $aGuiData[20]
Global $hGui
Global $Newdata
Global $aColors[7] = [0x000000, 0xFF0000, 0xFFFF00, 0x80FF80, 0x80FFFF, 0x0000FF, 0xFF00FF]
Global $Color = 0x000000

Func _GuiCreate(ByRef $aGuiData)
    $hGui = GUICreate("Test", 400, 400, 500, 100)
    Local $a = 0
    For $i = 0 To 19
        $sText = $a & " - " & $a & " - " & $a & " - " & $a & " - " & $a
        $aGuiData[$a] = GUICtrlCreateLabel($sText, 5, 5 + ($i * 15), 390, 20)
        GUICtrlSetBkColor(-1, 0xC4C4C4)
        GUICtrlSetColor(-1, 0xFF0000)
        $a += 1
    Next

    GUISetState()
EndFunc   ;==>_GuiCreate

Func _UpdateGui($Newdata, $Colour)
    Local $temp
    For $i = 0 To 18
        $temp = GUICtrlRead($aGuiData[$i + 1])
        $tempc = _GetColors($aGuiData[$i + 1])
        GUICtrlSetData($aGuiData[$i], $temp)
        GUICtrlSetColor($aGuiData[$i], $tempc[0])
    Next

    $sText = $Newdata & " - " & $Newdata & " - " & $Newdata& " - " & $Newdata & " - " & $Newdata
    GUICtrlSetData($aGuiData[19], $sText)
    GUICtrlSetColor($aGuiData[19], $Color)

EndFunc   ;==>_UpdateGui

_GuiCreate($aGuiData)

For $i = 20 To 100

    _UpdateGui($i, $Color)

    Local $iIndex = Mod($i, 7)
    $Color = $aColors[$iIndex]

Next

While 1
    ;Sleep(50)   ; Not needed with GUIGetMsg
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            Exit
    EndSelect
WEnd

Func _GetColors($hControl)

    Local $aColors[2], $tpoint = DllStructCreate("int X;int Y")

    ; Get position of control
    Local $aPos = ControlGetPos($hGUI, "", $hControl)
    ; Convert to screen coords
    DllStructSetData($tpoint, "X", $aPos[0])
    DllStructSetData($tpoint, "Y", $aPos[1])
    _WinAPI_ClientToScreen($hGUI, $tPoint)
    $aPos[0] = DllStructGetData($tpoint, "X") ; Needs the added 1 to hit the first coloured pixel
    $aPos[1] = DllStructGetData($tpoint, "Y") ; I have no idea why

    ; read colour at top left - assume it is background
    $aColors[1] = PixelGetColor($aPos[0], $aPos[1])
    ; Sweep through control to find another colour
    For $iX = $aPos[0] To $aPos[0] + $aPos[2] - 2 ; Again the need to adjust the coords returned by ControlGetPos
        For $iY = $aPos[1] To $aPos[1] + $aPos[3] - 2 ; And here too
            If PixelGetColor($iX, $iY) <> $aColors[1] Then
                ; Assume that it is text colour
                $aColors[0] = PixelGetColor($iX, $iY)
                Return $aColors
            EndIf
        Next
    Next

    ; Text colour not found, so return array, but set error as a flag
    $aColors[0] = 0
    Return SetError(-1, 0, $aColors)

EndFunc

Oh, and I checked the running times: 2276ms if you comment out the 2 lines in _UpdateGui which deal with $tempc; 4729ms if you leave them active. So I resent the x30 times comment - it is only a factor of 2! :mellow:

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 comment
Share on other sites

lol, its most likely my computer machine, my alarm clock has a better spec.

But as for the code, I get the same as before, I only see the bottom few labels before they fade out :mellow:

Posted Image

I'm stumped

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

Monkey's are, like, natures humans.

Link to comment
Share on other sites

Just been going through some of my win7 display settings and clear type text was on (must have been by default)

turned it off and now its working correctly.

Thank you M23 for your time, I really appreciate it.

Posted Image

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

Monkey's are, like, natures humans.

Link to comment
Share on other sites

  • Moderators

JohnOne,

OK, a final try:

Put a Sleep(5000) after the call to _GUICreate and make sure you have the original labels properly set in the GUI before you start to update them. Then put a Sleep(500) at the very beginning of your _UpdateGui function and see if you can spot where it goes wrong as you update.

It is still to wet for golf, so I will be here all afternoon. I hate being bested by a lump of fused silicon with some rare earth impurities - even if it does belong to someone else! I have mine semi-tamed. :(

M23

Edit: Hurrah!!!!!! :mellow:

Edited by Melba23

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 comment
Share on other sites

You people are weird. If you set the color yourself, you already know what color they have. I can't see why you would use the "slower than a snail" Pixel-functions.

:mellow:

Link to comment
Share on other sites

  • Moderators

AdmiralAlkex,

You are quite right. The original question was about getting colours from a control and I did not make the mental jump when I saw how it was to be used. Thanks for the kick! :mellow:

JohnOne,

If you wanted to use an array, you could do it like this:

#include <Array.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GDIPlus.au3>

Global $aGuiData[20][2]
Global $hGui
Global $Newdata
Global $aColors[7] = [0x000000, 0xFF0000, 0xFFFF00, 0x80FF80, 0x80FFFF, 0x0000FF, 0xFF00FF]
Global $Color = 0x000000

Func _GuiCreate(ByRef $aGuiData)
    $hGui = GUICreate("Test", 400, 400, 500, 100)
    For $i = 0 To 19
        $sText = $i & " - " & $i & " - " & $i & " - " & $i & " - " & $i
        $aGuiData[$i][0] = GUICtrlCreateLabel($sText, 5, 5 + ($i * 15), 390, 20)
        $aGuiData[$i][1] = $aColors[Mod($i, 7)]
        GUICtrlSetColor(-1, $aGuiData[$i][1])
        GUICtrlSetBkColor(-1, 0xC4C4C4)
    Next

     GUISetState()
EndFunc   ;==>_GuiCreate

Func _UpdateGui($Newdata, $NewColor)

    Local $temp
    For $i = 0 To 18
        $temp = GUICtrlRead($aGuiData[$i + 1][0])
        $tempc = $aGuiData[$i + 1][1]
        GUICtrlSetData($aGuiData[$i][0], $temp)
        GUICtrlSetColor($aGuiData[$i][0], $tempc)
        $aGuiData[$i][1] = $tempc

    Next

    $sText = $Newdata & " - " & $Newdata & " - " & $Newdata& " - " & $Newdata & " - " & $Newdata
    GUICtrlSetData($aGuiData[19][0], $sText)
    GUICtrlSetColor($aGuiData[19][0], $NewColor)
    $aGuiData[19][1] = $NewColor

EndFunc   ;==>_UpdateGui

_GuiCreate($aGuiData)

$iBegin = TimerInit()

For $i = 20 To 100

    _UpdateGui($i, $Color)
    Local $Color = $aColors[Mod($i, 7)]

Next

ConsoleWrite(TimerDiff($iBegin) & @CRLF)

While 1
    ;Sleep(50)   ; Not needed with GUIGetMsg
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            Exit
    EndSelect
WEnd

And consign my function to the bin of history. :(

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 comment
Share on other sites

You probably think I'm reaally annoying now, but there's still some weirdness left in that. Start with the functions, they should be defined last.

#include <Array.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GDIPlus.au3>

Global $aGuiData[20][2]
Global $hGui
Global $Newdata
Global $aColors[7] = [0x000000, 0xFF0000, 0xFFFF00, 0x80FF80, 0x80FFFF, 0x0000FF, 0xFF00FF]
Global $Color = 0x000000

_GuiCreate($aGuiData)

$iBegin = TimerInit()

For $i = 20 To 100

    _UpdateGui($i, $Color)
    Local $Color = $aColors[Mod($i, 7)]

Next

ConsoleWrite(TimerDiff($iBegin) & @CRLF)

While 1
    ;Sleep(50)   ; Not needed with GUIGetMsg
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            Exit
    EndSelect
WEnd

Func _GuiCreate(ByRef $aGuiData)
    $hGui = GUICreate("Test", 400, 400, 500, 100)
    For $i = 0 To 19
        $sText = $i & " - " & $i & " - " & $i & " - " & $i & " - " & $i
        $aGuiData[$i][0] = GUICtrlCreateLabel($sText, 5, 5 + ($i * 15), 390, 20)
        $aGuiData[$i][1] = $aColors[Mod($i, 7)]
        GUICtrlSetColor(-1, $aGuiData[$i][1])
        GUICtrlSetBkColor(-1, 0xC4C4C4)
    Next

     GUISetState()
EndFunc   ;==>_GuiCreate

Func _UpdateGui($Newdata, $NewColor)

    Local $temp
    For $i = 0 To 18
        $temp = GUICtrlRead($aGuiData[$i + 1][0])
        $tempc = $aGuiData[$i + 1][1]
        GUICtrlSetData($aGuiData[$i][0], $temp)
        GUICtrlSetColor($aGuiData[$i][0], $tempc)
        $aGuiData[$i][1] = $tempc

    Next

    $sText = $Newdata & " - " & $Newdata & " - " & $Newdata& " - " & $Newdata & " - " & $Newdata
    GUICtrlSetData($aGuiData[19][0], $sText)
    GUICtrlSetColor($aGuiData[19][0], $NewColor)
    $aGuiData[19][1] = $NewColor

EndFunc   ;==>_UpdateGui

There's also a lot of flickering with the background, but I'm to hungry (??) to see why. It would probably be better to use GDI+ or SDL for graphical things. Or remove the GUICtrlSetBkColor(), it looks a lot better, but then the light colors get hard to read.

Edited by AdmiralAlkex
Link to comment
Share on other sites

  • Moderators

AdmiralAlkex,

Not annoying........just a bit picky, perhaps! :(

Anyway, if you want to rewrite JohnOne's script, be my guest. I tend only to change things in others' scripts which would cause a real problem.

Oh, and the rainbow colours and background were a short-term fix by me to help watch the labels swap. I do not think the OP intends to keep them - at least for his eyes' sake I hope not! :mellow:

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 comment
Share on other sites

  • Moderators

Yashied,

Maybe this?

Makes my head hurt just to look at it! :mellow:

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 comment
Share on other sites

Maybe this?

In the example codes given in the thread, none return the correct text colour or Ctrlbkcolor.

The last example where the gui background is returned works, but the text colour is returned as "0x000000", when infact it has been set to "GUICtrlSetColor(-1, 0xFF0000)".

I wonder if that could have something to do with my display setting, having turned off clear type.

EDIT: same with clear type on.

Edited by JohnOne

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

Monkey's are, like, natures humans.

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...