Jump to content
Sign in to follow this  

_ChooseColor() Example

Recommended Posts


#include <GUIConstants.au3>
#include <Misc.au3>

$GUI = GUICreate("_ChooseColor() Example", 100, 100, -1, -1)
$Button = GUICtrlCreateButton("Choose", 10, 10, 80, 40)
$Label = GUICtrlCreateLabel("", 10, 60, 80, 30)

While 1
    $nMsg = GUIGetMsg()
    Case $nMsg = $GUI_EVENT_CLOSE
    Case $nMsg = $Button
        $Choose = _ChooseColor(2)
        GUICtrlSetBkColor($Label, $Choose)
        MsgBox(0, "Color", "Hex of the color you choose: " & $Choose)

Was bored and want to make an Example ^^

Well, here it is :P


A minesweeper game created in autoit, source available.


An UDF for registering functions to mouse events, made in pure autoit.

2D Hitbox Editor

A 2D hitbox editor for quick creation of 2D sphere and rectangle hitboxes.

Share this post

Link to post
Share on other sites

Find another hobby when you are bored :P.

Share this post

Link to post
Share on other sites

#AutoIt3Wrapper_au3check_parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6

#include <GUIConstantsEx.au3>
#include <Misc.au3>

Opt('MustDeclareVars', 1)


Func _Color_Example()
    Local $GUI, $Btn_COLORREF, $Btn_BGR, $Btn_RGB, $iMemo

    $GUI = GUICreate("_ChooseColor() Example", 400, 300)
    $iMemo = GUICtrlCreateEdit("", 2, 55, 396, 200, BitOR($WS_VSCROLL, $WS_HSCROLL))
    GUICtrlSetFont($iMemo, 10, 400, 0, "Courier New")
    $Btn_COLORREF = GUICtrlCreateButton("COLORREF", 70, 10, 80, 40)
    $Btn_BGR = GUICtrlCreateButton("BGR", 160, 10, 80, 40)
    $Btn_RGB = GUICtrlCreateButton("RGB", 250, 10, 80, 40)

    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
            Case $Btn_COLORREF
                _ShowChoice($GUI, $iMemo, 0, _ChooseColor(0, 255, 0, $GUI), "COLORREF color of your choice: ")
            Case $Btn_BGR
                _ShowChoice($GUI, $iMemo, 1, _ChooseColor(1, 0x808000, 1, $GUI), "BGR Hex color of your choice: ")
            Case $Btn_RGB
                _ShowChoice($GUI, $iMemo, 2, _ChooseColor(2, 0x0080C0, 2, $GUI), "RGB Hex color of your choice: ")
EndFunc   ;==>_Color_Example

Func _ShowChoice($GUI, $iMemo, $Type, $Choose, $sMessage)
    Local $oldOpt, $cr
    If $Choose <> -1 Then
        $oldOpt = Opt('ColorMode', 0) ;Colors are defined as RGB
        If $Type = 1 Then Opt('ColorMode', 1) ;Colors are defined as BGR
        If $Type = 0 Then ; convert COLORREF to RGB for this example
            $cr = Hex($Choose, 6)
            GUISetBkColor('0x' & StringMid($cr, 5, 2) & StringMid($cr, 3, 2) & StringMid($cr, 1, 2), $GUI)
            GUISetBkColor($Choose, $GUI)
        GUICtrlSetData($iMemo, $sMessage & $Choose & @CRLF, 1)

        Opt('ColorMode', $oldOpt) ; reset colormode
        GUICtrlSetData($iMemo, "User Canceled Selction" & @CRLF, 1)
EndFunc   ;==>_ShowChoice

SciTE for AutoItDirections for Submitting Standard UDFs


Don't argue with an idiot; people watching may not be able to tell the difference.


Share this post

Link to post
Share on other sites

Sorry to bring up an old topic, but is there anyway to inverse the return value of _ChooseColor() if i set the return value to RGB hex?


#include <Misc.au3>
$Test = _ChooseColor ( 2 )

If $Test = -1 Then Exit

$Inverse = _InverseHex($Test)

MsgBox ( 0, "", "Inverse of your selection equals: " & $Inverse )

Func _InverseHex($Hex)
;inverse thingy here


Solved it, set the return value to colorref then $RGB = Hex(BitNot($Test),6) then do the stringmid thingy and get the RGB value :D


Edited by SxyfrG

My scripts:AppLauncherTRAY - Awesome app launcher that runs from the system tray NEW VERSION! | Run Length Encoding - VERY simple compression in pure autoit | Simple Minesweeper Game - Fun little game :)My website

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