Jump to content

Recommended Posts

Posted

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

Posted

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!

Posted (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 by erifash
Posted

Nice Example erifash ;)

$color = _PixelGetColorMouse()

$HexColor = "0x" & Hex($color, 6)

GUICtrlSetData($Input_2, $HexColor)

To get the hex colour use _PixelGetColorMouse(1) :P

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...