Jump to content
Sign in to follow this  

Either a Label or PixelGetColor is inconsistent

Recommended Posts

Windows XP SP3

Script creates a GUI Form with background Color A and a textless Label on it with background Color B. With me so far?

Script returns PixelGetColor info wherever the mouse clicks over the label. Here's the wierd part:

Although the label is all the same color (or so I thought), clicking in most places over the label returns the label's color, but in other places it returns the color of the form underneath it. This makes the PixelGetColor unuseable for me even for a simple one-color object.

(The issue is repeatable; you just need to find the areas which do this.)

What is the problem? Is the label 'porous', or is PixelGetColor not always looking at the top (visible) layer?

Is there an adjustment or workaround for this? I just need reliable color info returned over different labels.

Here is the code:

#include <GUIConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
AutoItSetOption("WinTitleMatchMode", 2)
AutoItSetOption("MouseCoordMode", 2)

Global $formBGColor = 0x669999
Global $boardBGOffColor = 0xBCDCFF

$formWidth = Int(@DesktopWidth * 0.8)
$formHeight = Int(@DesktopHeight * 0.8)
$formLeft = Int((@DesktopWidth - $formWidth) / 2)
$formTop = Int((@DesktopHeight - $formHeight) / 2)

$mainForm = GUICreate("TEST", $formWidth, $formHeight, $formLeft, $formTop)

$boardBGPanelWidth = 450
$boardBGPanelHeight = 600
$boardBGPanelLeft = 350
$boardBGPanelTop = 36
$boardBGPanel = GUICtrlCreateLabel("", $boardBGPanelLeft, $boardBGPanelTop, $boardBGPanelWidth, $boardBGPanelHeight)
GUICtrlSetBkColor($boardBGPanel, $boardBGOffColor)

While 1
    $msg = GUIGetMsg()
        Case $msg = $GUI_EVENT_CLOSE

        Case $msg = $GUI_EVENT_PRIMARYDOWN
            $mouse = MouseGetPos()
            $mouseColor = PixelGetColor($mouse[0], $mouse[1])
            If $mouse[0] > $boardBGPanelLeft And $mouse[0] < $boardBGPanelLeft + $boardBGPanelWidth Then
                If $mouse[1] > $boardBGPanelTop And $mouse[1] < $boardBGPanelTop + $boardBGPanelHeight Then
                    ConsoleWrite("Color = " & Hex($mouseColor, 6) & @CRLF)


Share this post

Link to post
Share on other sites

Take another look at

AutoItSetOption("MouseCoordMode", 2)

What coordmode does PixelGetColor() use?


Everything was responding so well, coordinate-wise, until this one issue, so I thought my settings were fine. But this is the first demand for pixel-related functions. My bad.

Works OK now with AutoItSetOption("PixelCoordMode", 2). Thanks.

Share this post

Link to post
Share on other sites

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
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...