Code : Tout sélectionner
#cs
AutoIt Version: 3.1.1 (beta)
Language: English
Platform: WinXP
Author: Cybie
Script Function:
Color-picker function for use as a GUI Control
#ce
#include <WinAPI.au3>
#include <GuiConstants.au3>
;~ Opt("GUICoordMode", 0)
;~ Opt("WinTitleMatchMode", 3)
;~ $Color = 0x000000;First color displayed in all boxes
FileInstall("pipette.jpg", @TempDir & "\pipette.jpg")
FileInstall("pipette2.jpg", @TempDir & "\pipette2.jpg")
$ttt=GUICreate("Color Picker Demo", 200,100)
GUISetBkColor(0xFFFFFF)
Local $toolpicker = GUICtrlCreatePic(@TempDir & "\pipette.jpg", 0, 0, 25, 25)
; ----------------------------------------------------------------------------
;INPUT FIELDS
; ----------------------------------------------------------------------------
;~ GUICtrlCreateLabel ("Background Color:", 5, 7, 100, 20, 0x0002)
$ColorBox1 = GUICtrlCreateLabel("", 25, 0,75,25, $WS_BORDER)
$Background = GUICtrlCreateInput("#FFFFFF", 40, 30, 60, 25)
;~ GuiCtrlSetBkColor ($ColorBox1, $Color)
;~ GUICtrlCreateLabel ("Text Color:", -210, 25, 100, 20, 0x0002)
;~ $TxtColor = GUICtrlCreateInput ("#000000", 105, -2, 100, 20)
;~ $ColorBox2 = GuiCtrlCreateLabel ("", 105, 0, 20, 20)
;~ GuiCtrlSetBkColor ($ColorBox2, $Color)
;~ GUICtrlCreateLabel ("Link Color:", -210, 25, 100, 20, 0x0002)
;~ $Links = GUICtrlCreateInput ("#0000FF", 105, -2, 100, 20)
;~ $ColorBox3 = GuiCtrlCreateLabel ("", 105, 0, 20, 20)
;~ GuiCtrlSetBkColor ($ColorBox3, $Color)
GUISetState(@SW_SHOW)
clipput(_WinAPI_GetClassName($ttt))
;~ MsgBox($MB_SYSTEMMODAL, "Get ClassName", "ClassName of " & $ttt & ": " & )
; ----------------------------------------------------------------------------
;RUN LOOP
; ----------------------------------------------------------------------------
$msg = 0
While $msg <> $GUI_EVENT_CLOSE
$msg = GUIGetMsg()
Select
Case $msg = $toolpicker
$CurrentColorBox = $ColorBox1
$CurrentColorInput = $Background
ColorPicker()
;~ Case $msg = $ColorBox2
;~ $CurrentColorBox = $ColorBox2
;~ $CurrentColorInput = $TxtColor
;~ ColorPicker()
;~ Case $msg = $ColorBox3
;~ $CurrentColorBox = $ColorBox3
;~ $CurrentColorInput = $Links
;~ ColorPicker()
EndSelect
WEnd
; ----------------------------------------------------------------------------
; FUNCTIONS
; ----------------------------------------------------------------------------
Func ColorPicker()
GUICreate("Color Picker Mask", @DesktopWidth, @DesktopHeight, -1, -1, 0x80000000)
WinSetTrans("Color Picker Mask", "", 1);big trans window...
$Capture = GUICtrlCreateButton("", 0, 0, @DesktopWidth, @DesktopHeight)
GUISetState(@SW_SHOW)
GUISetCursor(3, 1)
Local $SRCCOPY = 0x00CC0020
Local $MousePos
ToolTip("AU3MAG", 0, 0)
$MyhWnd = WinGetHandle("classname=AutoIt v3 GUI")
;~ $CrntColor = $Color
$msg2 = 0
While 1;$Color = $CrntColor
$msg2 = GUIGetMsg()
$MousePos = MouseGetPos()
$PixColor = PixelGetColor($MousePos[0], $MousePos[1])
$TempColor = "0x" & Hex($PixColor, 6)
GUICtrlSetBkColor($CurrentColorBox, $TempColor)
Select
Case $msg2 = $Capture
GUICtrlSetData($toolpicker, @TempDir & "\pipette2.jpg")
$MousePos = MouseGetPos()
$PixColor = PixelGetColor($MousePos[0], $MousePos[1])
$Color = "0x" & Hex($PixColor, 6)
ToolTip("", 0, 0)
GUICtrlSetBkColor($CurrentColorBox, $Color)
GUICtrlSetData($CurrentColorInput, StringReplace($Color, "0x", "#"))
GUISetState(@SW_HIDE)
GUICtrlSetData($toolpicker, @TempDir & "\pipette.jpg")
ExitLoop
EndSelect
Sleep(25)
$MyHDC = DllCall("user32.dll", "int", "GetDC", "hwnd", $MyhWnd)
If @error Then Return
$DeskHDC = DllCall("user32.dll", "int", "GetDC", "hwnd", 0)
If Not @error Then
$xy = MouseGetPos()
If Not @error Then
$l = $xy[0] - 10
$t = $xy[1] - 10
DllCall("gdi32.dll", "int", "StretchBlt", "int", $MyHDC[0], "int", _
0, "int", 0, "int", 100, "int", 100, "int", $DeskHDC[0], "int", _
$l, "int", $t, "int", 20, "int", 20, "long", $SRCCOPY)
WinMove($MyhWnd, "", $xy[0] + 20, $xy[1] + 20, 100, 100)
EndIf
DllCall("user32.dll", "int", "ReleaseDC", "int", $DeskHDC[0], "hwnd", 0)
EndIf
DllCall("user32.dll", "int", "ReleaseDC", "int", $MyHDC[0], "hwnd", $MyhWnd)
WEnd
EndFunc ;==>ColorPicker