Jump to content

_ChooseColor() Example


AlmarM
 Share

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)
GUISetState(@SW_SHOW)

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

Was bored and want to make an Example ^^

Well, here it is :P

Minesweeper

A minesweeper game created in autoit, source available.

_Mouse_UDF

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.

Link to comment
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)

_Color_Example()

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)
    GUISetState()

    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ExitLoop
            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: ")
        EndSwitch
    WEnd
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)
        Else
            GUISetBkColor($Choose, $GUI)
        EndIf
        
        GUICtrlSetData($iMemo, $sMessage & $Choose & @CRLF, 1)

        Opt('ColorMode', $oldOpt) ; reset colormode
    Else
        GUICtrlSetData($iMemo, "User Canceled Selction" & @CRLF, 1)
    EndIf
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.

 

Link to comment
Share on other sites

  • 5 months later...

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?

i.e.

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

*EDIT*

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

: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

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