Jump to content

Flickering GUI


Recommended Posts

I've searched and tried to find a solution to this problem but nothing seems to be working. It fixed it flickering on my computer but on the computer it is supposed to run on the top text still flickers like crazy.

Any pointers would be helpful. Thanks.

Its a full screen app that displays a countdown in seconds to a certain date.

#include <UnixTime.au3>

If WinExists("Countdown") Then WinKill("Countdown")
AutoItWinSetTitle("Countdown")

; Target date and time
$Second = 0
$Minute = 0
$Hour = 0
$Day = 1
$Month = 1
$Year = 2070

; Get the width and height of the screen
If Not IsDeclared("SM_VIRTUALWIDTH") Then Global Const $SM_VIRTUALWIDTH = 78
If Not IsDeclared("SM_VIRTUALHEIGHT") Then Global Const $SM_VIRTUALHEIGHT = 79
$VirtualDesktopWidth = DLLCall("user32.dll", "int", "GetSystemMetrics", "int", $SM_VIRTUALWIDTH)
$VirtualDesktopWidth = $VirtualDesktopWidth[0]
$VirtualDesktopHeight = DLLCall("user32.dll", "int", "GetSystemMetrics", "int", $SM_VIRTUALHEIGHT)
$VirtualDesktopHeight = $VirtualDesktopHeight[0]

; Create full size window
$MainGUI = GUICreate("SWE08Countdown", $VirtualDesktopWidth, $VirtualDesktopHeight, 0, 0, 0x80000000, 136);$WS_POPUP, $WS_EX_TOPMOST + $WS_EX_TOOLWINDOW
GUISetCursor(16, 1); Move mouse off screen
GUISetBkColor(0x000000); Set background colour to black

; Set the Exit hotkey
$Exit = False
HotKeySet("{ESC}", "SetExitFlag")

; Create first label
$Label1 = GUICtrlCreateLabel("Some text", 0, ($VirtualDesktopHeight / 2) - 100, $VirtualDesktopWidth, 50, 1)
GUICtrlSetFont(-1, 30, 400, 0, "Arial"); 30pt Arial font
GUICtrlSetColor(-1, 0xFFFFFF); White colour

; Create label
$Label = GUICtrlCreateLabel("", 0, ($VirtualDesktopHeight / 2) - 40, $VirtualDesktopWidth, 80, 1)
GUICtrlSetFont(-1, 50, 400, 0, "Arial"); 50pt Arial font
GUICtrlSetColor(-1, 0xFFFFFF); White colour

; Get current and target date/time
$CurrentTime = _TimeMakeStamp(@SEC, @MIN, @HOUR, @MDAY, @MON, @YEAR - 35, 0)
$TargetTime = _TimeMakeStamp($Second, $Minute, $Hour, $Day, $Month, $Year - 35 , 0)
$Offset = 0

;Show main window
GUISetState(@SW_SHOW, $MainGUI)

; Keep updating text until exit key is pressed
Do
    If ++$Offset >= 3600 Then
        $Offset = 0
        $CurrentTime = _TimeMakeStamp(@SEC, @MIN, @HOUR, @MDAY, @MON, @YEAR - 35, 0)
    Else
        $CurrentTime += 1
    EndIf
    
    GUISetState (@SW_LOCK, $MainGUI)
    UpdateDisplay()
    GUISetState (@SW_UNLOCK, $MainGUI)
    
    Sleep(1000)
Until $Exit

; Sets exit flag when ESC is pressed
Func SetExitFlag()
    $Exit = true
EndFunc

Func UpdateDisplay()
    GUICtrlSetData($Label, $TargetTime - $CurrentTime)
EndFunc
Link to comment
Share on other sites

One thing I have found to help with flickering is to add the $WS_CLIPCHILDREN style to the main GUI. This prevents the child windows from being redrawn when the main GUI gets a call to redraw. In my case, it has eliminated flickering due to updates of other controls.

Good luck.

Bob

You can't see a rainbow without first experiencing the rain.

Link to comment
Share on other sites

One thing I have found to help with flickering is to add the $WS_CLIPCHILDREN style to the main GUI. This prevents the child windows from being redrawn when the main GUI gets a call to redraw. In my case, it has eliminated flickering due to updates of other controls.

Good luck.

Bob

There is just the one window, there arent any child windows.

Get rid of those @SW_LOCK/@SW_UNLOCK, update only if $NewText <> $OldText, use ControlSetText instead of GUICtrlSetData.

I'll try without the @SW_LOCK and @SW_UNLOCK. I have tried using ControlSetText, and the "NewText" will always be different to the "OldText".
Link to comment
Share on other sites

There is just the one window, there arent any child windows.

The label controls are considered children. My experience has been with one main GUI with Picture controls flickering. Adding the $WS_CLIPCHILDREN style stopped the flickering.

Bob

You can't see a rainbow without first experiencing the rain.

Link to comment
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
 Share

  • Recently Browsing   0 members

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