Matrix112 Posted September 28, 2005 Share Posted September 28, 2005 Hi, this UDF is simple, but maybe useful. PGCMouse.au3 ;====================================================================================== ; ; Function Name: _PixelGetColorMouse() ; Description: Returns Color in dec or hex from mouse position. ; Parameter(s): $iHex - Optional. If set to 1 hex will be returned. ; Requirement(s): Include PGCMouse.au3 ; Return Value(s): Colour of the pixel at mouse position in dec or hex. ; Author(s): Christoph Krogmann <ch.krogmann@gmx.de> ; ;====================================================================================== ; Func _PixelGetColorMouse($iHex = 0) Local $iPos Local $iColor $iPos = MouseGetPos() $iColor = PixelGetColor($iPos[0] ,$iPos[1]) If $iHex = 0 Then Return $iColor ElseIf $iHex = 1 Then Return "0x" & Hex($iColor, 6) EndIf EndFunc;==>_PixelGetColorMouse Example.au3 #include <GuiConstants.au3> #include <PGCMouse.au3> If Not IsDeclared('WS_CLIPSIBLINGS') Then Global $WS_CLIPSIBLINGS = 0x04000000 GuiCreate("Example", 418, 119,(@DesktopWidth-418)/2, (@DesktopHeight-119)/2 , $WS_OVERLAPPEDWINDOW + $WS_VISIBLE + $WS_CLIPSIBLINGS) $Label_1 = GuiCtrlCreateLabel("Colour under mouse: ", 20, 40, 100, 20) $Input_2 = GuiCtrlCreateInput("", 140, 40, 100, 20) GuiSetState() While 1 $msg = GuiGetMsg() Select Case $msg = $GUI_EVENT_CLOSE ExitLoop Case Else ;;; EndSelect $color = _PixelGetColorMouse() GUICtrlSetData($Input_2, $color) Sleep(20) WEnd Exit PGCMouse.au3 Example.au3 Link to comment Share on other sites More sharing options...
MuffettsMan Posted September 29, 2005 Share Posted September 29, 2005 Ok trying to add to above (in my primative noobness) I wanted to not only see the hex value but the color itself... having it display the hex was simple enough.. $color = _PixelGetColorMouse() $HexColor = "0x" & Hex($color, 6) GUICtrlSetData($Input_2, $HexColor) However I am having difficulty getting it to display a 'view' of the color itself. It seems when you set GUICtrlSetColor or GUICtrlSetBkColor its static when the label is created? my only workaround was to create a new lable inside the while statement... though that flickers like crazy as its being rebuilt within the while statement could increase the sleep to compensate however that can't be the best option.... Anyone have any better ideas than: GuiSetState() While 1 $msg = GuiGetMsg() $Color_Bar = GUICtrlCreateLabel (" COLOR SELECTED ", -1, 0) ; next line Select Case $msg = $GUI_EVENT_CLOSE ExitLoop Case Else ;;; EndSelect $color = _PixelGetColorMouse() $HexColor = "0x" & Hex($color, 6) GUICtrlSetData($Input_2, $HexColor) GUICtrlSetBkColor($Color_Bar,$HexColor) Sleep(20) WEnd Don't let that status fool you, I am no advanced memeber! Link to comment Share on other sites More sharing options...
erifash Posted September 29, 2005 Share Posted September 29, 2005 (edited) Try... #include <GuiConstants.au3> #include <PGCMouse.au3> If Not IsDeclared('WS_CLIPSIBLINGS') Then Global $WS_CLIPSIBLINGS = 0x04000000 Dim $last = -1, $color GuiCreate("Example", 400, 120, -1, -1, $WS_OVERLAPPEDWINDOW + $WS_VISIBLE + $WS_CLIPSIBLINGS) $Label_1 = GuiCtrlCreateLabel("Colour under mouse: ", 20, 40, 100, 20) $dispcolor = GUICtrlCreateLabel("", 140, 40, 50, 20) $Input_2 = GuiCtrlCreateInput("", 20, 80, 200, 20) GuiSetState() While 1 $msg = GuiGetMsg() Select Case $msg = $GUI_EVENT_CLOSE ExitLoop Case $color <> $last GUICtrlSetBkColor($dispcolor, $color) Case Else ;;; EndSelect $last = $color $color = _PixelGetColorMouse() GUICtrlSetData($Input_2, $color) Sleep(20) WEnd Exit Not tested but i'm pretty sure it will work... hehe I got to help someone! Edited September 29, 2005 by erifash My UDFs:_FilePrint() | _ProcessGetName() | _Degree() and _Radian()My Scripts:Drive Lock - Computer Lock Using a Flash DriveAU3Chat - Simple Multiuser TCP ChatroomStringChunk - Split a String Into Equal PartsAutoProxy - Custom Webserver Link to comment Share on other sites More sharing options...
MuffettsMan Posted September 29, 2005 Share Posted September 29, 2005 AWESOME!!! now just to get rid of the headache after watching my version flicker so badly ty ty Don't let that status fool you, I am no advanced memeber! Link to comment Share on other sites More sharing options...
erifash Posted September 29, 2005 Share Posted September 29, 2005 Thanks, but all you had to do was check to see if the color was different then update it if it was. I'm glad I could help. My UDFs:_FilePrint() | _ProcessGetName() | _Degree() and _Radian()My Scripts:Drive Lock - Computer Lock Using a Flash DriveAU3Chat - Simple Multiuser TCP ChatroomStringChunk - Split a String Into Equal PartsAutoProxy - Custom Webserver Link to comment Share on other sites More sharing options...
Matrix112 Posted September 29, 2005 Author Share Posted September 29, 2005 Nice Example erifash $color = _PixelGetColorMouse()$HexColor = "0x" & Hex($color, 6)GUICtrlSetData($Input_2, $HexColor)To get the hex colour use _PixelGetColorMouse(1) Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now