Sign in to follow this  
Followers 0
thelex

Weird GUI behavior

8 posts in this topic

i created a app to show coords + pixelcolor of the mouse as it moves around, but the thing is: it's flashy.

Its annyoing. whatever GUI coontrol i create to view them, it's flashing, and someetimes unreadable.

try it yourself:

<sub>#include <GUIConstants.au3>
 #include<WinAPI.au3>
 
 GUICreate ("Mouse", 200, 300)
 
 While 1
 $color = PixelGetColor( _WinAPI_GetMousePosX() , _WinAPI_GetMousePosY() )
 Sleep (10)
 GUICtrlCreateLabel ('x : ' & _WinAPI_GetMousePosX() & " y : " & _WinAPI_GetMousePosY(), 50,10 ,180 , 20)
 GUICtrlCreateLabel ('Color(RGB):' & $color ,  50, 90, 180 , 20)
 GUICtrlCreateButton ("For later use", 50, 40, 100, 20 )
;------pos---info---------------------left,top,with,height-------------------------------
 sleep(10) 
 GUISetState ()
     $msg = GUIGetMsg()
     
     If $msg = $GUI_EVENT_CLOSE Then exit
 WEnd</sub>

Posted Image

Share this post


Link to post
Share on other sites



@thelex...Instead of updating the data for the controls..you are creating new controls...

First create the controls and then in the while loop use Guictrlsetdata()...

Share this post


Link to post
Share on other sites

could you make a example?

im new to this..

Share this post


Link to post
Share on other sites

#include <GUIConstants.au3>
#include<WinAPI.au3>

GUICreate("Mouse", 200, 300) ; GUI Window
GUISetState() ; GUI State

$color = PixelGetColor( _WinAPI_GetMousePosX(), _WinAPI_GetMousePosY())

; GUI Controls [Start]
$LblPos = GUICtrlCreateLabel("", 50, 10, 180, 20)
GUICtrlCreateLabel('Color(RGB):' & $color, 50, 90, 180, 20)
GUICtrlCreateButton("For later use", 50, 40, 100, 20)
; GUI Controls  [End]

While 1
    Sleep(10)
    GUICtrlSetData($LblPos, 'x : ' & _WinAPI_GetMousePosX() & " y : " & _WinAPI_GetMousePosY()) ; Reset the data of the control to the current mouse pos
    $msg = GUIGetMsg()
    If $msg = $GUI_EVENT_CLOSE Then Exit
WEnd

Share this post


Link to post
Share on other sites

Awesome! thanks, but i don't get it to do the same with the color .. ><

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

I'll do it now. Also create a new script and try to make the same thing using Koda (Scite > Tools > Koda). It will help you understand how to sort things when you make a gui. (check this post back soon)

EDIT: You were trying this, weren't you?

#include <GUIConstants.au3>
#include<WinAPI.au3>

GUICreate("Mouse", 200, 300) ; GUI Window
GUISetState() ; GUI State

$color = PixelGetColor(_WinAPI_GetMousePosX(), _WinAPI_GetMousePosY())

; GUI Controls [Start]
$LblPos = GUICtrlCreateLabel("", 50, 10, 180, 20)
$LblClr = GUICtrlCreateLabel("", 50, 90, 180, 20)
GUICtrlCreateButton("For later use", 50, 40, 100, 20)
; GUI Controls  [End]

While 1
    Sleep(10)
    GUICtrlSetData($LblPos, "x : " & _WinAPI_GetMousePosX() & " y : " & _WinAPI_GetMousePosY()) ; Reset the data of the control to the current mouse pos
    GUICtrlSetData($LblClr, "Color(RGB):" & $color)
    $msg = GUIGetMsg()
    If $msg = $GUI_EVENT_CLOSE Then Exit
WEndoÝ÷ Ù8^­æ¬¢{aj×hzÉ÷öÜ(®H¬mçºÇ°éò¢ç±yË­zØ^±Êâ¦Ü!zx­ël¶a{Múrh®X§z+`zÛ-ç.®·§¶±zW(ÚÚÞ+-z¸­¶azg¦¢¼¢­Ü(®L¨º¯zÚ zÛaz±zW(Þ½êò¶)êÞjëh×6#include <GUIConstants.au3>
#include<WinAPI.au3>

GUICreate("Mouse", 200, 300) ; GUI Window
GUISetState() ; GUI State

; GUI Controls [Start]
$LblPos = GUICtrlCreateLabel("", 50, 10, 180, 20)
$LblClr = GUICtrlCreateLabel("", 50, 90, 180, 20)
GUICtrlCreateButton("For later use", 50, 40, 100, 20)
; GUI Controls  [End]

While 1
    Sleep(10)
    GUICtrlSetData($LblPos, "x : " & _WinAPI_GetMousePosX() & " y : " & _WinAPI_GetMousePosY()) ; Reset the data of the control to the current mouse pos
    GUICtrlSetData($LblClr, "Color(RGB):" & PixelGetColor(_WinAPI_GetMousePosX(), _WinAPI_GetMousePosY()))
    $msg = GUIGetMsg()
    If $msg = $GUI_EVENT_CLOSE Then Exit
WEnd
Edited by Aassdd

Share this post


Link to post
Share on other sites

Dude, you are awesome! Thanks a lot for the help! :)

Share this post


Link to post
Share on other sites

I've done updates like that before, and the problem is the flicker of the control when you are constantly updating it. To avoid that, I prefer to keep track of the old value, and only update the control if it changed. This is the same script with that implemented:

#include <GUIConstants.au3>
#include <StaticConstants.au3>

Global $avMouse[2] = [0, 0]
Global $avMouseOld = $avMouse
Global $iPixelColor = 0
Global $iPixelOld = 0

Global $hGUI = GUICreate("Mouse", 300, 200)
Global $Label_MousePos = GUICtrlCreateLabel('x: 0  y: 0', 10, 10, 280, 20, $SS_CENTER)
Global $Label_Color = GUICtrlCreateLabel('Color(RGB):  0', 10, 40, 280, 20, $SS_CENTER)
Global $Button = GUICtrlCreateButton("For later use", 100, 160, 100, 30)
GUISetState()

While 1
    ; Get current values
    $avMouse = MouseGetPos()
    $iPixelColor = PixelGetColor($avMouse[0], $avMouse[1])
    
    ; Update GUI if changed
    If ($avMouse[0] <> $avMouseOld[0]) Or ($avMouse[1] <> $avMouseOld[1]) Or ($iPixelColor <> $iPixelOld) Then
        $avMouseOld = $avMouse
        $iPixelOld = $iPixelColor
        ControlSetText($hGUI, "", $Label_MousePos, 'x: ' & $avMouse[0] & '  y: ' & $avMouse[1])
        ControlSetText($hGUI, "", $Label_Color, 'Color(RGB): 0x' & Hex($iPixelColor, 6) & ' = ' & $iPixelColor & ' (Dec)')
    EndIf
    
    $msg = GUIGetMsg()
    Switch $msg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button
            MsgBox(64, "Mouse", "For later use...")
    EndSwitch
WEnd

I think you'll find the GUI looks much more stable without the flickering controls.

:)


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

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  
Followers 0