Jump to content



Photo

ColorPicker UDF


  • Please log in to reply
37 replies to this topic

#1 Yashied

Yashied

    Happy in Moscow

  • MVPs
  • 2,512 posts

Posted 09 June 2009 - 10:05 PM

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.


Posted Image


ChangeLog

Spoiler


ColorPicker UDF Library v1.5
(Previous downloads: 1007)

Attached File  ColorPicker.au3   36.78K   1009 downloads


Example1

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

AutoIt         
#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.au3)

AutoIt         
#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, 07 December 2010 - 08:36 AM.






#2 Ashalshaikh

Ashalshaikh

    Wayfarer

  • Active Members
  • Pip
  • 97 posts

Posted 09 June 2009 - 10:25 PM

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, 09 June 2009 - 10:47 PM.


#3 Yashied

Yashied

    Happy in Moscow

  • MVPs
  • 2,512 posts

Posted 09 June 2009 - 10:41 PM

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.

#4 WideBoyDixon

WideBoyDixon

    Code Monkey

  • Active Members
  • PipPipPipPipPipPip
  • 381 posts

Posted 10 June 2009 - 12:48 AM

This really is very nice indeed!

WBD

#5 Yashied

Yashied

    Happy in Moscow

  • MVPs
  • 2,512 posts

Posted 10 June 2009 - 02:17 PM

In weekends, I make a new version of UDF, where you can specify an arbitrary size (number of colors) palette.

#6 Zedna

Zedna

    AutoIt rulez!

  • MVPs
  • 8,315 posts

Posted 10 June 2009 - 02:37 PM

It's COOOL!!  :D :D

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

Edited by Zedna, 10 June 2009 - 02:38 PM.


#7 Yashied

Yashied

    Happy in Moscow

  • MVPs
  • 2,512 posts

Posted 10 June 2009 - 02:49 PM

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.

#8 Yashied

Yashied

    Happy in Moscow

  • MVPs
  • 2,512 posts

Posted 12 June 2009 - 07:48 PM

The library has been updated. See post #1.

Edited by Yashied, 07 November 2009 - 12:46 AM.


#9 Zedna

Zedna

    AutoIt rulez!

  • MVPs
  • 8,315 posts

Posted 12 June 2009 - 11:19 PM

The library has been updated. See post #1.


Bad link to attachment.

#10 trancexx

trancexx

    Hm, I really shouldn't.

  • Active Members
  • PipPipPipPipPipPip
  • 5,186 posts

Posted 12 June 2009 - 11:35 PM

Bad link to attachment.

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.

eMyvnE


#11 Yashied

Yashied

    Happy in Moscow

  • MVPs
  • 2,512 posts

Posted 12 June 2009 - 11:37 PM

Bad link to attachment.

??? Works.

#12 Yashied

Yashied

    Happy in Moscow

  • MVPs
  • 2,512 posts

Posted 12 June 2009 - 11:39 PM

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.

#13 Zedna

Zedna

    AutoIt rulez!

  • MVPs
  • 8,315 posts

Posted 12 June 2009 - 11:40 PM

??? Works.


Now it works for me too.


For the first time this reported red error page about bad link (link to ColorPicker.au3 in post #1).

#14 froufrou

froufrou

    Wayfarer

  • Active Members
  • Pip
  • 71 posts

Posted 13 June 2009 - 06:40 AM

This is really good! I wanted something like this for users of certain scripts i make to customize GUI colors.
Thank-You for this. :D :D

#15 Yashied

Yashied

    Happy in Moscow

  • MVPs
  • 2,512 posts

Posted 27 June 2009 - 02:55 PM

A small change in the library. I changed the return value of the WM_ACTIVATE handler.

Return 'GUI_RUNDEFMSG' instead Return 0

Without this, you may have problems with the focus.

#16 Yashied

Yashied

    Happy in Moscow

  • MVPs
  • 2,512 posts

Posted 03 July 2009 - 07:57 PM

Probably because of the forum software update, all the examples is deteriorated. Fixed.

#17 Yashied

Yashied

    Happy in Moscow

  • MVPs
  • 2,512 posts

Posted 07 August 2009 - 10:54 AM

The library has been updated.

Replaced Posted Image instead Posted Image

#18 WideBoyDixon

WideBoyDixon

    Code Monkey

  • Active Members
  • PipPipPipPipPipPip
  • 381 posts

Posted 07 August 2009 - 03:15 PM

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

WBD

#19 Yashied

Yashied

    Happy in Moscow

  • MVPs
  • 2,512 posts

Posted 07 August 2009 - 03:20 PM

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

WBD

I am glad to see you again.

#20 Yashied

Yashied

    Happy in Moscow

  • MVPs
  • 2,512 posts

Posted 06 November 2009 - 11:36 PM

The library has been updated.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users