Jump to content

Recommended Posts

Posted (edited)

LAST VERSION - 1.1

07-Dec-10

This library provides a dialog box to select a color in three color models - RGB (Red, Green, Blue), HSL (Hue, Saturation, Lightness), and HSB (Hue, Saturation, Brightness). This is not a program, this is a function that you can use in your scripts. This function is similar to the _ChooseColor() from Misc UDF library that is included in the AutoIt package. UDF is fully compatible with ColorPicker UDF (v1.5) and can be used as a custom function for a Color Chooser dialog box (see examples). Also there is a tool (pipette) to get the color from the screen. I recommend to first read description inside the library. Please play with this UDF and post any comments and suggestions.

ColorChooser.png

ColorChooser UDF Library v1.1

Previous downloads: 316

ColorChooser.au3

Example1

#Include <ColorChooser.au3>

Opt('MustDeclareVars', 1)

Global $hForm, $Msg, $Label, $Button, $Data, $Color = 0x50CA1B

$hForm = GUICreate('MyGUI', 170, 200)
$Label = GUICtrlCreateLabel('', 15, 15, 140, 140, $SS_SUNKEN)
GUICtrlSetBkColor(-1, $Color)
$Button = GUICtrlCreateButton('Select color...', 35, 166, 100, 23)
GUISetState()

While 1
    $Msg = GUIGetMsg()
    Switch $Msg
        Case $GUI_EVENT_CLOSE
            ExitLoop
        Case $Button
            $Data = _ColorChooserDialog($Color, $hForm)
            If $Data > -1 Then
                GUICtrlSetBkColor($Label, $Data)
                $Color = $Data
            EndIf
    EndSwitch
WEnd

Example2 (required ColorPicker UDF)

#Include <ColorChooser.au3>
#Include <ColorPicker.au3>

Opt('MustDeclareVars', 1)

Global $hForm, $Msg, $Label, $Picker

$hForm = GUICreate('MyGUI', 170, 200)
$Label = GUICtrlCreateLabel('', 15, 15, 140, 140, $SS_SUNKEN)
GUICtrlSetBkColor(-1, 0x50CA1B)
$Picker = _GUIColorPicker_Create('', 55, 166, 60, 23, 0x50CA1B, BitOR($CP_FLAG_CHOOSERBUTTON, $CP_FLAG_MAGNIFICATION, $CP_FLAG_ARROWSTYLE), 0, -1, -1, 0, 'Simple Text', 'Custom...', '_ColorChooserDialog')
GUISetState()

While 1
    $Msg = GUIGetMsg()
    Switch $Msg
        Case $GUI_EVENT_CLOSE
            ExitLoop
        Case $Picker
            GUICtrlSetBkColor($Label, _GUIColorPicker_GetColor($Picker))
    EndSwitch
WEnd
Edited by Yashied
  • 3 weeks later...
Posted

The library has been updated.

v1.1

Changes

  Reveal hidden contents
  • Added the following flags for more appearance changes and functionality of the dialog box.

    $CC_FLAG_SOLIDCOLOR

    $CC_FLAG_CAPTURECOLOR

    $CC_FLAG_USERCOLOR

    $CC_FLAG_DEFAULT

  • Added ability to save up to 20 color values, and use them in other programs that using this library (see $CC_FLAG_USERCOLOR).
  • Fixed several minor bugs.

  • 1 month later...
Posted

Yashid, I get the following errors when running example 1:

F:\AutoIt\Other People Projects and Examples\Yasheid\Color Choser UDF\ColorChooser.au3(1295,47) : ERROR: CP_WM_COMMAND(): undefined function.
        CP_WM_COMMAND($hWnd, $iMsg, $wParam, $lParam)
        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
F:\AutoIt\Other People Projects and Examples\Yasheid\Color Choser UDF\ColorChooser.au3(1469,59) : ERROR: CP_WM_SETCURSOR(): undefined function.
        $Result = CP_WM_SETCURSOR($hWnd, $iMsg, $wParam, $lParam)
Posted

  On 6/4/2010 at 2:42 AM, 'Beege said:

Yashid, I get the following errors when running example 1...

With this code you also get an error, but the code is absolutely correct. Do not pay any attention to it.

If (IsDeclared('A')) And ($A = 1) Then
    MyFunc()
EndIf

:mellow:

  • 4 months later...
  • 4 weeks later...
  • 1 month later...
  • 5 months later...
Posted

when R = 250, G = 250, B = 250, return value of ColorChooser function is H = 160, S = 0, L = 240

why here H = 160, instead of H = 0 ?

  • 2 months later...
Posted (edited)

  On 5/25/2011 at 5:20 PM, 'happytc said:

when R = 250, G = 250, B = 250, return value of ColorChooser function is H = 160, S = 0, L = 240

why here H = 160, instead of H = 0 ?

When Saturation is 0 it really doesnt matter what the Hue is because its still going to be grey/black/white and its very common in this instance for the hue to be set to the center of the colour wheel which is 160 in this case.

EDIT: Freakn great UDF....the color picker tool is just gravy!

Edited by PAEz
  • 2 years later...
  • Moderators
Posted

Andreik,

A quick search (you did do one before posting?) brought up this thread which looks as if it could be useful to you. :)

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 spoiler to see my UDFs:

  Reveal hidden contents

 

Posted

I saw that post but I asked because the UI where you select the color let you see all this color spaces. Following the same logic I asked if wouldn't be good to have an option (second parameter as flag) to get the color in the desired format. :rolleyes:

  • 4 months later...
  • 4 months later...

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