Hallo zusammen,
ich erstelle grad ein kleines Tool (habs einfach mal Color Catcher genannt) welche den HEX-Wert einer Farbe bei Mausklick wiedergibt.
Soweit klappt das auch erstmal, nur werden bei direkter Eingabe des HEX-Wertes, die Werte nicht auf die Slider für die RGB Farben übernommen.
Ich muss dazusagen, dass ich viele Codeschnipsel aus einem von BugFix' Tools verwende, da ich sonst gar nicht soweit gekommen wäre mit dem RGB Zeugs.
Hier mal der Code:
Spoiler anzeigen
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <EditConstants.au3>
#Include <Misc.au3>
#include <GDIPlus.au3>
#Include <WinAPI.au3>
#include <StaticConstants.au3>
Global $mainframe, $hImage, $hGraphic, $hImage1, $mouseposi
[/autoit] [autoit][/autoit] [autoit]$colorwheel = FileInstall("C:\Documents and Settings\751076\Desktop\AutoIT Tools\Color Catcher\colorwheel.png", @TempDir & "\colorwheel.png")
$kreispkt2 = FileInstall("C:\Documents and Settings\751076\Desktop\AutoIT Tools\Color Catcher\kreispkt2.png", @TempDir & "\kreispkt2.png")
$mainframe = GUICreate("Color Catcher", 800, 530)
[/autoit] [autoit][/autoit] [autoit]_GDIPlus_StartUp()
$hImage = _GDIPlus_ImageLoadFromFile(@TempDir & "\colorwheel.png")
$hImage1 = _GDIPlus_ImageLoadFromFile(@TempDir & "\kreispkt2.png")
$hGraphic = _GDIPlus_GraphicsCreateFromHWND($mainframe)
GUIRegisterMsg($WM_PAINT, "MY_WM_PAINT")
[/autoit] [autoit][/autoit] [autoit]GUICtrlCreateLabel("Ermittelte Farbe:", 540, 17, 80, 20)
GUICtrlSetFont(-1, 8, 400, 0, "Arial")
$color_view = GUICtrlCreateLabel("", 540, 34, 100, 46)
GUICtrlCreateLabel("HEX-Wert:", 540, 85, 60, 20)
GUICtrlSetFont(-1, 8, 400, 0, "Arial")
$ausgabe_farbe = GUICtrlCreateInput("", 540, 100, 60, 20)
GUICtrlSetBkColor($color_view, '0x' & "FFFFFF")
$slRed = GUICtrlCreateSlider(540, 200, 250, 20, 0)
GUICtrlSetLimit(-1, 255, 0)
GUICtrlSetBkColor(-1, 0xFF0000)
$slGreen = GUICtrlCreateSlider(540, 250, 250, 20, 0)
GUICtrlSetLimit(-1, 255, 0)
GUICtrlSetBkColor(-1, 0x00FF00)
$slBlue = GUICtrlCreateSlider(540, 300, 250, 20, 0)
GUICtrlSetLimit(-1, 255, 0)
GUICtrlSetBkColor(-1, 0x0000FF)
$InRed = GUICtrlCreateInput("", 570, 175, 40, 21, BitOR($ES_RIGHT,$ES_AUTOHSCROLL))
$InGreen = GUICtrlCreateInput("", 570, 225, 40, 21, BitOR($ES_RIGHT,$ES_AUTOHSCROLL))
$InBlue = GUICtrlCreateInput("", 570, 275, 40, 21, BitOR($ES_RIGHT,$ES_AUTOHSCROLL))
$lbRed = GUICtrlCreateLabel("Rot", 540, 180, 21, 12)
$lbGreen = GUICtrlCreateLabel("Grün", 540, 230, 27, 12)
$lbBlue = GUICtrlCreateLabel("Blau", 540, 280, 25, 12)
GUIsetstate(@SW_SHOW, $mainframe)
[/autoit] [autoit][/autoit] [autoit]While 1
Switch (GUIGetMsg())
Case $GUI_EVENT_CLOSE
_GDIPlus_GraphicsDispose($hGraphic)
_GDIPlus_ImageDispose($hImage)
_GDIPlus_ImageDispose($hImage1)
_GDIPlus_ShutDown()
Exit
Case $InRed
InRedChange()
Case $InGreen
InGreenChange()
Case $InBlue
InBlueChange()
Case $ausgabe_farbe
InHexChange()
Case $slRed
_Slider2Hex()
Case $slGreen
_Slider2Hex()
Case $slBlue
_Slider2Hex()
EndSwitch
If _IsPressed("01") Then
Sleep(75)
$mouseposi = MouseGetPos()
$farbe = Hex(PixelGetColor($mouseposi[0], $mouseposi[1]),6)
If $farbe = 'D4D0C8' Or $farbe = 'FFFFFF' Or $farbe = '000000' Or $farbe = 'FF0000' Or $farbe = '00FF00' Or $farbe = '0000FF' Or $farbe = '808080' Or $farbe = '404040' Or $farbe = '0A246A' Then
Else
GUICtrlSetData($ausgabe_farbe, "#" & $farbe)
GUICtrlSetBkColor($color_view, '0x' & $farbe)
_WinAPI_RedrawWindow($mainframe, 0, 0, $RDW_UPDATENOW)
_GDIPlus_GraphicsDrawImage($hGraphic, $hImage1, $mouseposi[0] -416, $mouseposi[1] -236)
_WinAPI_RedrawWindow($mainframe, 0, 0, $RDW_VALIDATE)
EndIf
EndIf
WEnd
Func MY_WM_PAINT($hWnd, $Msg, $wParam, $lParam)
_WinAPI_RedrawWindow($mainframe, 0, 0, $RDW_UPDATENOW)
_GDIPlus_GraphicsDrawImage($hGraphic, $hImage, 0, 0)
_WinAPI_RedrawWindow($mainframe, 0, 0, $RDW_VALIDATE)
Return $GUI_RUNDEFMSG
EndFunc
Func InBlueChange()
$tmp = GUICtrlRead($InBlue)
If $tmp < 0 Or $tmp > 255 Then
GUICtrlSetData($InBlue, GUICtrlRead($slBlue))
Return
EndIf
GUICtrlSetData($slBlue, $tmp)
_Slider2Hex()
EndFunc
Func InGreenChange()
$tmp = GUICtrlRead($InGreen)
If $tmp < 0 Or $tmp > 255 Then
GUICtrlSetData($InGreen, GUICtrlRead($slGreen))
Return
EndIf
GUICtrlSetData($slGreen, $tmp)
_Slider2Hex()
EndFunc
Func InRedChange()
$tmp = GUICtrlRead($InRed)
If $tmp < 0 Or $tmp > 255 Then
GUICtrlSetData($InRed, GUICtrlRead($slRed))
Return
EndIf
GUICtrlSetData($slRed, $tmp)
_Slider2Hex()
EndFunc
Func InHexChange()
$tmp = GUICtrlRead($farbe)
If Not StringRegExp($tmp, '(#[0-9A-Fa-f]{6}(?!.))') Then
_Slider2Hex()
Return
EndIf
_Hex2Slider()
EndFunc
Func _Slider2Hex()
GUICtrlSetData($InBlue, GUICtrlRead($slBlue))
GUICtrlSetData($InGreen, GUICtrlRead($slGreen))
GUICtrlSetData($InRed, GUICtrlRead($slRed))
$red = Hex(GUICtrlRead($slRed), 2)
$green = Hex(GUICtrlRead($slGreen), 2)
$blue = Hex(GUICtrlRead($slBlue), 2)
$hexColor1 = '#' & $red & $green & $blue
$hexColor2 = '0x' & $red & $green & $blue
GUICtrlSetData($ausgabe_farbe, $hexColor1)
GUICtrlSetBkColor($color_view, $hexColor2)
EndFunc
Func _Hex2Slider()
$red = Dec(StringMid(GUICtrlRead($farbe), 3, 2))
$green = Dec(StringMid(GUICtrlRead($farbe), 5, 2))
$blue = Dec(StringRight(GUICtrlRead($farbe), 2))
GUICtrlSetData($InRed, $red)
GUICtrlSetData($InGreen, $green)
GUICtrlSetData($InBlue, $blue)
GUICtrlSetData($slRed, $red)
GUICtrlSetData($slGreen, $green)
GUICtrlSetData($slBlue, $blue)
GUICtrlSetBkColor($color_view, GUICtrlRead($farbe))
EndFunc
Die übergabe von Slider auf HEX ins Inputfeld klappt... aber leider nicht umgedreht und ich versteh nicht, warum?