Jump to content

ColorPicker UDF


Yashied
 Share

Recommended Posts

LAST VERSION - 1.5

07-Dec-10

Creates a button to quickly select a color from the specified palette. It is possible to change the appearance, at its discretion, determine their own palette, call a standard Windows dialog for selecting colors, as well as change the appearance of buttons. See my example, to understand how it works and how to use it. UDF is written entirely in AutoIt and Windows API. No ActiveX and third-party DLL. I hope you enjoy. I look forward to any feedback and suggestions.

ColorPicker.png

History

1.5

  • Added _GUIColorPicker_Release() function to delete all Color Picker controls for the specified window (GUI).
  • Added ability to set their own function for "Color Chooser" dialog box (see description for the _GUIColorPicker_Create() function), default is using the standard Windows dialog, like _ChooseColor().
  • Added support for collaborative work with the ColorChooser UDF library.
1.4
  • Added ability to define your own cursor for the Color Picker dialog box. (See the second example)
  • Removed the $CP_FLAG_HANDCURSOR flag as unnecessary.
  • Changed the header for the _GUIColorPicker_Create() function.
  • Fixed a bug related to the declaration of variables.
  • Few internal code changed.
1.3
  • Fixed bug that consist in aborting script if the specified palette dimentions exceeds the number of colors in the palette.
  • Few internal code changed.
1.2
  • Added ability to create a palette of arbitrary size.
  • Added ability to specify text for the button associated with the Color Chooser dialog box (default is "Custom...").
  • Added support for mouse wheel when choosing colors for the control.
  • Added new style for the control - button with the arrow.
  • Added text tip for the color palette.
  • Added ability to disable the magnification in the Color Picker dialog box.
  • Added ability to set the "Hand" cursor for the Color Picker dialog box.
  • Added ability to assign names for the colors in the palette.

Available functions

_GUIColorPicker_Create

_GUIColorPicker_Delete

_GUIColorPicker_Release

_GUIColorPicker_GetColor

_GUIColorPicker_SetColor

_GUIColorPicker_GetPalette

_GUIColorPicker_SetPalette

ColorPicker UDF Library v1.5

Previous downloads: 1007

ColorPicker.au3

Example1

#Include <ColorPicker.au3>

Opt('MustDeclareVars', 1)

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

$hForm = GUICreate('Color Picker', 179, 100)
$Label = GUICtrlCreateLabel('', 5, 5, 90, 90, $SS_SUNKEN)
GUICtrlSetBkColor(-1, 0xFF6600)

; Create Picker
$Picker = _GUIColorPicker_Create('Color...', 102, 70, 70, 23, 0xFF6600, BitOR($CP_FLAG_DEFAULT, $CP_FLAG_TIP))

GUISetState()

While 1
    $Msg = GUIGetMsg()
    Switch $Msg
        Case $GUI_EVENT_CLOSE
            ExitLoop
        Case $Picker
            GUICtrlSetBkColor($Label, _GUIColorPicker_GetColor($Picker))
    EndSwitch
WEnd

Example2

#Include <ColorPicker.au3>
#Include <WinAPI.au3>

Opt('MustDeclareVars', 1)

Global $hForm, $Msg, $Label, $Picker1, $Picker2, $Picker3, $Data, $hInstance, $hCursor

$hForm = GUICreate('Color Picker', 300, 200)

; Load cursor
$hInstance = _WinAPI_LoadLibrary(@SystemDir & '\mspaint.exe')
$hCursor = DllCall('user32.dll', 'ptr', 'LoadCursor', 'ptr', $hInstance, 'dword', 1204)
$hCursor = $hCursor[0]
_WinAPI_FreeLibrary($hInstance)

; Create Picker1 with custom cursor
$Picker1 = _GUIColorPicker_Create('', 100, 50, 44, 44, 0xFF6600, BitOR($CP_FLAG_DEFAULT, $CP_FLAG_CHOOSERBUTTON), 0, -1, -1, $hCursor, 'Simple Text')

; Free cursor
DllCall('user32.dll', 'int', 'DestroyCursor', 'ptr', $hCursor)

; Create custom (4 x 5) color palette
Dim $aPalette[20] = _
    [0xFFFFFF, 0x000000, 0xC0C0C0, 0x808080, _
     0xFF0000, 0x800000, 0xFFFF00, 0x808000, _
     0x00FF00, 0x008000, 0x00FFFF, 0x008080, _
     0x0000FF, 0x000080, 0xFF00FF, 0x800080, _
     0xC0DCC0, 0xA6CAF0, 0xFFFBF0, 0xA0A0A4]

; Create Picker2 with custom color palette
$Picker2 = _GUIColorPicker_Create('', 7, 170, 50, 23, 0xFF00FF, BitOR($CP_FLAG_CHOOSERBUTTON, $CP_FLAG_ARROWSTYLE, $CP_FLAG_MOUSEWHEEL), $aPalette, 4, 5, 0, '', 'More...')

; Create custom (8 x 8) color palette
Dim $aPalette[64]
For $i = 0 To UBound($aPalette) - 1
    $aPalette[$i] = BitOR($i, BitShift($i * 4, -8), BitShift($i, -16))
Next

; Create Picker3 with custom color palette
$Picker3 = _GUIColorPicker_Create('Color...', 223, 170, 70, 23, 0x2DB42D, BitOR($CP_FLAG_TIP, $CP_FLAG_MAGNIFICATION), $aPalette, 8, 8)
$Label = GUICtrlCreateLabel('', 194, 171, 22, 22, $SS_SUNKEN)
GUICtrlSetBkColor(-1, 0x2DB42D)
GUICtrlSetTip(-1, '2DB42D')

GUISetState()

While 1
    $Msg = GUIGetMsg()
    Switch $Msg ; Color Picker sends the message that the color is selected
        Case -3
            ExitLoop
        Case $Picker1
            $Data = _GUIColorPicker_GetColor($Picker1, 1)
            If $Data[1] = '' Then
                $Data[1] = 'Custom'
            EndIf
            ConsoleWrite('Picker1: 0x' & Hex($Data[0], 6) & ' (' & $Data[1] & ')' & @CR)
        Case $Picker2
            ConsoleWrite('Picker2: 0x' & Hex(_GUIColorPicker_GetColor($Picker2), 6) & @CR)
        Case $Picker3
            $Data = _GUIColorPicker_GetColor($Picker3)
            ConsoleWrite('Picker3: 0x' & Hex($Data, 6) & @CR)
            GUICtrlSetBkColor($Label, $Data)
            GUICtrlSetTip($Label, Hex($Data, 6))
    EndSwitch
WEnd

Example3 (required ColorChooser 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

Very Nice ... Great ....

There is a simple error ..

===============

ColorPicker.au3(204,21) WARNING: $iFlags: possibly used before declaration.

If BitAND($iFlags,

~~~~~~~~~~~~~~~~~^

======================

I added this

Global $iFlags

Then It worked ..

Thank You

Edited by Ashalshaikh
Link to comment
Share on other sites

Very Nice ... Great ....

There is a simple error ..

===============

ColorPicker.au3(204,21) WARNING: $iFlags: possibly used before declaration.

If BitAND($iFlags,

~~~~~~~~~~~~~~~~~^

======================

I added this

Global $iFlags

Then worked ..

Thank You

Thanks.

I fixed it, download again.

Link to comment
Share on other sites

This really is very nice indeed!

WBD

Link to comment
Share on other sites

It's COOOL!! :D:D

Thanks.

Anyway here is idea for improvement:

Make some way for specifying internationalized label for button text "Custom..."

maybe as new optional parameter which default value will be "Custom..."

GUICtrlCreateButton('Custom...', ...
You are right, agreed.
Link to comment
Share on other sites

Well, he is linking to a post. :D Isn't he?

There is a small mistake with the example. It should be (line 47 - array element):

ConsoleWrite('Picker1: 0x' & Hex($Data[0], 6) & ' (' & $Data[1] &')' & @CR)

Nice job Yashied. Another one.

Thanks, fixed.
Link to comment
Share on other sites

  • 2 weeks later...
Link to comment
Share on other sites

  • 1 month later...

Nice one! Makes my stock tracker look better without me having to do anything >_<

WBD

Link to comment
Share on other sites

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