Jump to content

_WinAPI_GetSysColor


rasim
 Share

Recommended Posts

Hi, how use the _WinAPI_GetSysColor function properly? Why background color of a label control green?

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

GUICreate("My GUI", 300, 200)

$button = GUICtrlCreateButton("Test", 50, 50, 75, 23)

$RGB = _WinAPI_GetSysColor($COLOR_ACTIVECAPTION) ;Active caption is blue

$Red = _ColorGetRed($RGB)
$Green = _ColorGetGreen($RGB)
$Blue = _ColorGetBlue($RGB)

$color = $Red & $Green & $Blue

;MsgBox(0, "", $color)

GUICtrlCreateLabel("", 50, 100, 100, 20)
GUICtrlSetBkColor(-1, "0x" & $color)

GUISetState()

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            ExitLoop
    EndSwitch
WEnd
Edited by rasim
Link to comment
Share on other sites

  • Moderators

Try removing the "0x" from GUICtrlSetBckColor() and just use the decimal it gives you.

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

You are doing it wrong, sorry.

Notice this: MsgBox(0, "", $Red & @LF & $Green & @LF & $Blue)

You should know that hex values are always 2 digits, on my system the $red value is 3 (it's 106). The _ColorGet* functions are not returning the colors in hex format, they are returning in decimal format. Ideally, you would just use the return straight from _WinAPI_GetSysColor() but there is an issue with that because _WinAPI_GetSysColor() is returning the color in BGR format instead of RGB, so your colour comes out kinda backwards.

Try this code:

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

GUICreate("My GUI", 300, 200)

$button = GUICtrlCreateButton("Test", 50, 50, 75, 23)

$BGR = _WinAPI_GetSysColor($COLOR_ACTIVECAPTION);Active caption is blue

GUICtrlCreateLabel("", 50, 100, 100, 20)
GUICtrlSetBkColor(-1, _ColorBGRToRGB($BGR))

GUISetState()

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            ExitLoop
    EndSwitch
WEnd

Func _ColorBGRToRGB($BGR)
    Local $RGB = BitShift($BGR, -16)
    $RGB += BitAND($BGR, 0xff00)
    $RGB += BitShift($BGR, 16)
    Return BitAND($RGB, 0xffffff)
EndFunc
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...