Jump to content
Sign in to follow this  
d0n

getting listbox text color

Recommended Posts

d0n

which function should i look at to get the text color inside a listbox?

Share this post


Link to post
Share on other sites
Melba23

d0n,

If it is your own editbox, you should know already! :(

But I wrote this a while ago to get the colours from a control - it is a bit "rough and ready", but it seems to do the trick. Just remember to allow for the editbox border:

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

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

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

$hEdit = GUICtrlCreateEdit("Testing" & @CRLF & "Testing!" , 10, 10, 200, 202)
GUICtrlSetColor(-1, $aSetColors[0])
GUICtrlSetBkColor(-1, $aSetColors[1])

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

GUISetState()

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $hButton
            $aGetColors = _GetColors($hEdit)
            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") + 4 ; Need to get over the border pixels
    $aPos[1] = DllStructGetData($tpoint, "Y") + 4

    ; read colour at top left - assume it is background
    $aColors[1] = PixelGetColor($aPos[0], $aPos[1])
    ; Sweep through first character of control to find another colour
    For $iX = $aPos[0] To $aPos[0] + 10
        For $iY = $aPos[1] To $aPos[1] + 10
            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

I hope it helps. :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 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

 

Share this post


Link to post
Share on other sites
d0n

well its not mine :mellow:

and is there a way to read it without using pixelgetcolor?

Share this post


Link to post
Share on other sites
Melba23

d0n,

Perhaps this topic might help. :mellow:

M23

P.S. The Search button is at the top on the right. :(


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

 

Share this post


Link to post
Share on other sites
d0n

i've tried that one, I can't get it to work with a listbox :mellow:

Share this post


Link to post
Share on other sites
Melba23

d0n,

I never got it to work with anything, which is why I wrote the function I posted above. :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 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

 

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  

×