Sign in to follow this  
Followers 0
FinalVersion

Stop Flickering And Fix Hide

3 posts in this topic

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <SendMessage.au3>
#include <Date.au3>


Global Const $SC_DRAGMOVE = 0xF012
Local $iHours, $iMins, $iSecs


$frmMain = GUICreate("System :: Uptime", 290, 58, 192, 124, BitOR($WS_POPUP,$WS_BORDER), $WS_EX_TOPMOST)
GUISetBkColor(0x000000)
$lblDays = GUICtrlCreateLabel("00", 8, 8, 40, 41)
GUICtrlSetFont(-1, 24, 400, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0x00FF00)
$lblHours = GUICtrlCreateLabel("00", 64, 8, 40, 41)
GUICtrlSetFont(-1, 24, 400, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0x00FF00)
$lblMinutes = GUICtrlCreateLabel("00", 120, 8, 40, 41)
GUICtrlSetFont(-1, 24, 400, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0x00FF00)
$lblSeconds = GUICtrlCreateLabel("00", 176, 8, 40, 41)
GUICtrlSetFont(-1, 24, 400, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0x00FF00)
$lblSep1 = GUICtrlCreateLabel(":", 48, 8, 13, 41)
GUICtrlSetFont(-1, 24, 400, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0x00FF00)
$lblSep2 = GUICtrlCreateLabel(":", 104, 8, 13, 41)
GUICtrlSetFont(-1, 24, 400, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0x00FF00)
$lblSep3 = GUICtrlCreateLabel(":", 160, 8, 13, 41)
GUICtrlSetFont(-1, 24, 400, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0x00FF00)
$btnHide = GUICtrlCreateButton("Hide", 224, 10, 51, 33, BitOR($BS_FLAT,$WS_GROUP))
GUISetState(@SW_SHOW)


While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_PRIMARYDOWN
    _SendMessage($frmMain, $WM_SYSCOMMAND, $SC_DRAGMOVE, 0)
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch

    $GTC = DllCall("kernel32.dll", "long", "GetTickCount")
    $TSB = $GTC[0]

    _TicksToTime($TSB, $iHours, $iMins, $iSecs)
    $iDays = Int($iHours / 24)
    $iHours = $iHours - ($iDays * 24)

    GUICtrlSetData($lblDays, $iDays)
    GUICtrlSetData($lblHours, $iHours)
    GUICtrlSetData($lblMinutes, $iMins)
    GUICtrlSetData($lblSeconds, $iSecs)
WEnd

It only flickers for a couple of seconds when I start it, but it's annoying. And now I've broken the Hide function, I'm thinking when you hit the hide button, it stops updating the labels and hides, but when you unhide it, it continues updating.

Share this post


Link to post
Share on other sites



FinalVersion,

1. To stop the flickering, only update the labels when needed - you need variables to track the current values and then wait for changes, as shown below. I also added some formatting to give 2-digit values at all times. :mellow:

2. You were not looking for the "Hide" button in your GUIGetMsg loop - hardly surprising that it was not working! :( By the way, the Case $GUI_EVENT_CLOSE is unnecessary as you have no way of sending the message from a $WS_POPUP window - there is no [X].

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <SendMessage.au3>
#include <Date.au3>

Global Const $SC_DRAGMOVE = 0xF012
Local $iHours, $iMins, $iSecs

$frmMain = GUICreate("System :: Uptime", 290, 58, 192, 124, BitOR($WS_POPUP,$WS_BORDER), $WS_EX_TOPMOST)
GUISetBkColor(0x000000)
$lblDays = GUICtrlCreateLabel("00", 8, 8, 40, 41)
GUICtrlSetFont(-1, 24, 400, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0x00FF00)
$lblHours = GUICtrlCreateLabel("00", 64, 8, 40, 41)
GUICtrlSetFont(-1, 24, 400, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0x00FF00)
$lblMinutes = GUICtrlCreateLabel("00", 120, 8, 40, 41)
GUICtrlSetFont(-1, 24, 400, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0x00FF00)
$lblSeconds = GUICtrlCreateLabel("00", 176, 8, 40, 41)
GUICtrlSetFont(-1, 24, 400, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0x00FF00)
$lblSep1 = GUICtrlCreateLabel(":", 48, 8, 13, 41)
GUICtrlSetFont(-1, 24, 400, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0x00FF00)
$lblSep2 = GUICtrlCreateLabel(":", 104, 8, 13, 41)
GUICtrlSetFont(-1, 24, 400, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0x00FF00)
$lblSep3 = GUICtrlCreateLabel(":", 160, 8, 13, 41)
GUICtrlSetFont(-1, 24, 400, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0x00FF00)
$btnHide = GUICtrlCreateButton("Hide", 224, 10, 51, 33, $BS_FLAT)
GUISetState(@SW_SHOW)

$iCurrSecs = 0
$iCurrMins = 0
$iCurrHrs = 0
$iCurrDays = 0

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_PRIMARYDOWN
            _SendMessage($frmMain, $WM_SYSCOMMAND, $SC_DRAGMOVE, 0)
        Case $GUI_EVENT_CLOSE
            Exit
        Case $btnHide
            GUISetState(@SW_HIDE)
    EndSwitch

    $GTC = DllCall("kernel32.dll", "long", "GetTickCount")
    $TSB = $GTC[0]

    _TicksToTime($TSB, $iHours, $iMins, $iSecs)
    $iDays = Int($iHours / 24)
    $iHours = $iHours - ($iDays * 24)

    If $iSecs <> $iCurrSecs Then
        If $iDays <> $iCurrDays Then
            GUICtrlSetData($lblDays, StringFormat("%02i", $iDays))
            $iCurrDays = $iDays
        EndIf
        If $iCurrHrs <> $iHours Then
            GUICtrlSetData($lblHours, StringFormat("%02i", $iHours))
            $iCurrHrs = $iHours
        EndIf
        If $iCurrMins <> $iMins Then
            GUICtrlSetData($lblMinutes, StringFormat("%02i", $iMins))
            $iCurrMins = $iMins
        EndIf
        GUICtrlSetData($lblSeconds, StringFormat("%02i", $iSecs))
        $iCurrSecs = $iSecs
    EndIf
WEnd

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

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