Jump to content

Is there a GUICtrlGetColor function?


Recommended Posts

I have a status line in my GUI that has various messages, but has green text when things are good and red otherwise.  I was hoping to avoid keeping another state variable around and just read back the color when I need to know the status.  AutoIT internally must know the color of what you set it to, but there doesn't seem to be a way to get to it?

I saw this thread, but that's about the background color, and is definitely a long way to get there:

Is there an easy solution, or should I just bite the bullet and add a line to update a new state variable every place the status is updated?


Link to comment
Share on other sites

What in your script dictates/sets the color of the text?  What kind of control is it (label)?

Are you able to post a reproducer/demo script?

edit: Without testing, this seems plausible  Couldn't get this to work.  

#include <WinAPI.au3>
#include <WinAPIGdi.au3>

Func GUICtrlGetTextColor($hWnd)
    If Not IsHWnd($hWnd) Then
        $hWnd = GUICtrlGetHandle($hWnd)
    Local $hDC = _WinAPI_GetDC($hWnd)
    Local $iColor = _WinAPI_GetTextColor($hDC)
    _WinAPI_ReleaseDC($hWnd, $hDC)
    Return $iColor

Found another example on the forum, but it's also a bit complicated (requires registermsg) and I get get that one to work either... :blink:

Edited by spudw2k
Link to comment
Share on other sites

Sorry.   I was just using GuiCtrlSetColor() to set the color on a label, then hoping for an easy way to retrieve it later.

I see GUICtrlGetHandle, but I'm not sure what you can do with a handle.  (I'm kind of new to the whole AutoIT world - I'm using it as an easy tool to test out my embedded program on a USB device, and definitely not a Windows expert).

Too bad that example didn't work, it looks promising.

Link to comment
Share on other sites

Yea, drag.  So I'm not sure where to go from here in regards to retrieving the control color.  If it were me I'd just track the state/value/what-have-you when you apply the color in a global variable.  Seems just as effective to me...but I'm probably not seeing the entire picture here.

Link to comment
Share on other sites

You're right, tracking the state is the easiest solution.  It's no deal-breaker, I can keep going. 

I'm just not that familiar with the language yet, so I assumed if you can set something, there exists a complementary function to get that value.  That does not seem to be the case.  I know when I write Python code, it looks like a C programmer wrote it.  I'm trying to avoid that here.


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

  • Recently Browsing   0 members

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