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.

ChangeLog
ColorPicker UDF Library v1.5
(Previous downloads: 1007)
ColorPicker.au3 36.78K
1009 downloadsExample1
#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.au3)
#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.







