Jump to content

ColorChooser UDF


Yashied
 Share

Recommended Posts

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
Link to comment
Share on other sites

  • 3 weeks later...

The library has been updated.

v1.1

Changes

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

Link to comment
Share on other sites

  • 1 month later...

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)
Link to comment
Share on other sites

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:

Link to comment
Share on other sites

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

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
Link to comment
Share on other sites

  • 2 years later...
  • Moderators

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:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

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:

When the words fail... music speaks.

Link to comment
Share on other sites

  • 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
 Share

  • Recently Browsing   0 members

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