Jump to content

My Gui to refesh data When it's not in focus (RESOLVED)


GNGNUT
 Share

Recommended Posts

Hi guys

what i am trying to do is have My Gui LIve update Out of focus, so i can have this on a 2nd monitor streaming live updates while i continue to work on other screen, 

i have been googling and looking at other threads about focus and stuff , but they do not seem to match what I'm after, 

to be clear - i am not wanting to put focus on the GUI for it to auto update values, 

 

if you have any positive feed back on the script while you read - i would be more then happy to accept - as im still building my Knowledge of this coding, 

and stream line is always better Garbage code writing, 

 

Kind regards 

Gngnut

 

#include <MemoryConstants.au3>
#include <MsgBoxConstants.au3>
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>

Global $currentTime,$currentTimeValue,$v,$Label_Time,$Form1
Global $Label_C2_1,$Label_C2_2,$Label_C2_3,$Label_C2_4,$Label_C2_5,$Label_C2_6,$Label_C2_7
Global $Label_C3_1,$Label_C3_2,$Label_C3_3,$Label_C3_4,$Label_C3_5,$Label_C3_6,$Label_C3_7

;~ Default Hight for boxs
    $Hight = 40
    $lenght = 180

;; As per nines comments moved out side of the While loop, 
    AdlibRegister(UpdateTime,250)
    AdlibRegister(updateValues,500)
    AdlibRegister(Warning,250)
    hotkeyset ("{ESC}",Terminate) ;; <<<  Used to Quit the programe

    $aMemStats = MemGetStats()
    MyGui()  ;; running the GUI

#Region ### START Koda GUI section ### Form=
func MyGui()
        $ServerName=@ComputerName
        ;  ### Change to your location of image
        $Image = "C:\Users\gngnut\OneDrive\Pictures\Computer.jpg"

        ; Creating the form With the Labels
        $Form1 = GUICreate("My System Status", 800, 750, 225, 173,BitOR($WS_SYSMENU,$WS_MAXIMIZEBOX,$WS_MINIMIZEBOX));$WS_POPUP))
        $Pic1 = GUICtrlCreatePic($Image, 0, 0, 800, 750)

        ;;; ####  Column 1
        $Label_C1_1 = GUICtrlCreateLabel("Total load currently on RAM:", 71, 192, 180, $Hight, BitOR($SS_CENTER,""))
        GUICtrlSetBkColor(-1, 0xFEF200)
        GUICtrlSetFont(-1, 12, 400, 0, "Lucida Console")

        $Label_C1_2 = GUICtrlCreateLabel("Total physical RAM:", 71, 248, 180, $Hight, BitOR($SS_CENTER,""))
        GUICtrlSetBkColor(-1, 0xFEF200)
        GUICtrlSetFont(-1, 12, 400, 0, "Lucida Console")

        $Label_C1_3 = GUICtrlCreateLabel("Available physical RAM:", 71, 304, 180, $Hight, BitOR($SS_CENTER,""))
        GUICtrlSetBkColor(-1, 0xFEF200)
        GUICtrlSetFont(-1, 12, 400, 0, "Lucida Console")

        $Label_C1_4 = GUICtrlCreateLabel("Total Page Size:", 71, 360, 180, $Hight, BitOR($SS_CENTER,""))
        GUICtrlSetBkColor(-1, 0xFEF200)
        GUICtrlSetFont(-1, 12, 400, 0, "Lucida Console")

        $Label_C1_5 = GUICtrlCreateLabel("Available Page Size:", 71, 416, 180, $Hight, BitOR($SS_CENTER,""))
        GUICtrlSetBkColor(-1, 0xFEF200)
        GUICtrlSetFont(-1, 12, 400, 0, "Lucida Console")

        $Label_C1_6 = GUICtrlCreateLabel("Total virtual Size:", 71, 472, 180, $Hight, BitOR($SS_CENTER,""))
        GUICtrlSetBkColor(-1, 0xFEF200)
        GUICtrlSetFont(-1, 12, 400, 0, "Lucida Console")

        $Label_C1_7 = GUICtrlCreateLabel("Available virtual RAM:", 71, 528, 180, $Hight, BitOR($SS_CENTER,""))
        GUICtrlSetBkColor(-1, 0xFEF200)
        GUICtrlSetFont(-1, 12, 400, 0, "Lucida Console")

        ;;; ####  Column 2

        $Label_C2_1 = GUICtrlCreateLabel($aMemStats[$MEM_LOAD] & " %", 311, 192, 180, $Hight, BitOR($SS_CENTER,$WS_BORDER,$SS_CENTERIMAGE))
        $colour=0xFEF200
        GUICtrlSetFont(-1, 12, 400, 0, "Lucida Console")

        $Label_C2_2 = GUICtrlCreateLabel($aMemStats[$MEM_TOTALPHYSRAM] & ' Kb' , 311, 248, 180, $Hight, BitOR($SS_CENTER,$WS_BORDER,$SS_CENTERIMAGE))
        GUICtrlSetBkColor(-1, 0xFEF200)
        GUICtrlSetFont(-1, 12, 400, 0, "Lucida Console")

        $Label_C2_3 = GUICtrlCreateLabel($aMemStats[$MEM_AVAILPHYSRAM] & ' Kb', 311, 304, 180, $Hight, BitOR($SS_CENTER,$WS_BORDER,$SS_CENTERIMAGE))
        GUICtrlSetBkColor(-1, 0xFEF200)
        GUICtrlSetFont(-1, 12, 400, 0, "Lucida Console")

        $Label_C2_4 = GUICtrlCreateLabel($aMemStats[$MEM_TOTALPAGEFILE] & ' Kb', 311, 360, 180, $Hight, BitOR($SS_CENTER,$WS_BORDER,$SS_CENTERIMAGE))
        GUICtrlSetBkColor(-1, 0xFEF200)
        GUICtrlSetFont(-1, 12, 400, 0, "Lucida Console")

        $Label_C2_5 = GUICtrlCreateLabel($aMemStats[$MEM_AVAILPAGEFILE] & ' Kb', 311, 416, 180, $Hight, BitOR($SS_CENTER,$WS_BORDER,$SS_CENTERIMAGE))
        GUICtrlSetBkColor(-1, 0xFEF200)
        GUICtrlSetFont(-1, 12, 400, 0, "Lucida Console")

        $Label_C2_6 = GUICtrlCreateLabel($aMemStats[$MEM_TOTALVIRTUAL] & ' Kb' , 311, 472, 180, $Hight, BitOR($SS_CENTER,$WS_BORDER,$SS_CENTERIMAGE))
        GUICtrlSetBkColor(-1, 0xFEF200)
        GUICtrlSetFont(-1, 12, 400, 0, "Lucida Console")

        $Label_C2_7 = GUICtrlCreateLabel($aMemStats[$MEM_AVAILVIRTUAL] & ' Kb', 311, 528, 180, $Hight, BitOR($SS_CENTER,$WS_BORDER,$SS_CENTERIMAGE))
        GUICtrlSetBkColor(-1, 0xFEF200)
        GUICtrlSetFont(-1, 12, 400, 0, "Lucida Console")

        ;;; ####  Column 3

        $Label_C3_2 = GUICtrlCreateLabel(Round($aMemStats[$MEM_TOTALPHYSRAM]/1024/1024, 2) & ' Gb', 551, 248, 180, $Hight, BitOR($SS_CENTER,$WS_BORDER,$SS_CENTERIMAGE))
        GUICtrlSetBkColor(-1, 0xFEF200)
        GUICtrlSetFont(-1, 12, 400, 0, "Lucida Console")

        $Label_C3_3 = GUICtrlCreateLabel(Round($aMemStats[$MEM_AVAILPHYSRAM]/1024/1024, 2) & ' Gb', 551, 304, 180, $Hight, BitOR($SS_CENTER,$WS_BORDER,$SS_CENTERIMAGE))
        GUICtrlSetBkColor(-1, 0xFEF200)
        GUICtrlSetFont(-1, 12, 400, 0, "Lucida Console")

        $Label_C3_4 = GUICtrlCreateLabel(Round($aMemStats[$MEM_TOTALPAGEFILE]/1024/1024, 2) & ' Gb', 551, 360, 180, $Hight, BitOR($SS_CENTER,$WS_BORDER,$SS_CENTERIMAGE))
        GUICtrlSetBkColor(-1, 0xFEF200)
        GUICtrlSetFont(-1, 12, 400, 0, "Lucida Console")

        $Label_C3_5 = GUICtrlCreateLabel(Round($aMemStats[$MEM_AVAILPAGEFILE]/1024/1024, 2) & ' Gb', 551, 416, 180, $Hight, BitOR($SS_CENTER,$WS_BORDER,$SS_CENTERIMAGE))
        GUICtrlSetBkColor(-1, 0xFEF200)
        GUICtrlSetFont(-1, 12, 400, 0, "Lucida Console")

        $Label_C3_6 = GUICtrlCreateLabel(Round($aMemStats[$MEM_TOTALVIRTUAL]/1024/1024, 2) & ' Gb', 551, 472, 180, $Hight, BitOR($SS_CENTER,$WS_BORDER,$SS_CENTERIMAGE))
        GUICtrlSetBkColor(-1, 0xFEF200)
        GUICtrlSetFont(-1, 12, 400, 0, "Lucida Console")

        $Label_C3_7 = GUICtrlCreateLabel(Round($aMemStats[$MEM_AVAILVIRTUAL]/1024/1024, 2) & ' Gb', 551, 528, 180, $Hight, BitOR($SS_CENTER,$WS_BORDER,$SS_CENTERIMAGE))
        GUICtrlSetBkColor(-1, 0xFEF200)
        GUICtrlSetFont(-1, 12, 400, 0, "Lucida Console")

        $Label_Server = GUICtrlCreateLabel($ServerName, 551, 600, 180, $Hight, BitOR($SS_CENTER,$WS_BORDER,$SS_CENTERIMAGE))
        GUICtrlSetBkColor(-1, 0xFEF200)
        GUICtrlSetFont(-1, 12, 400, 0, "Lucida Console")

        $Label_Time = GUICtrlCreateLabel($currentTime , 71, 600, 180, $Hight, bitOR($SS_CENTER,$WS_BORDER,$SS_CENTERIMAGE))
        GUICtrlSetBkColor(-1, 0xFEF200)
        GUICtrlSetFont(-1, 12, 400, 0, "Lucida Console")

        GUISetState(@SW_SHOWNORMAL)
        #EndRegion ### END Koda GUI section ###
EndFunc

While 1
    Sleep(1000)  ; sets a delay of 1 sec per 1000
WEnd

;; close down the Application
func Terminate()
    exit
EndFunc

;;  Updating Time
func UpdateTime()
    $currentTime = @HOUR&":"& @MIN &":"& @SEC
    ControlSetText($Form1,"",$Label_Time, $currentTime)
EndFunc

;; currently changing the CPU % lable
Func Warning()
        if $aMemStats[$MEM_LOAD] <=40 Then ; Green
            GUICtrlSetbkColor($Label_C2_1,0x2BFC0B)
        ElseIf $aMemStats[$MEM_LOAD] >40 and $aMemStats[$MEM_LOAD] <= 80 Then
            GUICtrlSetbkColor($Label_C2_1,0xFDBE01)
        Elseif $aMemStats[$MEM_LOAD] > 80 Then
             GUICtrlSetBkColor($Label_C2_1, 0xEE0C0C)
        EndIf
EndFunc

;;  Updating The Lable values of column 2 Only if the values change
func updateValues()
    $aMemStats = MemGetStats()
    if  GUICtrlRead($Label_C2_1) <> $aMemStats[$MEM_LOAD] Then
        ControlSetText($Form1,"",$Label_C2_1,$aMemStats[$MEM_LOAD])
    endif
    If GUICtrlRead($Label_C2_2) <> $aMemStats[$MEM_TOTALPHYSRAM] & ' Kb' then
        ControlSetText($Form1,"",$Label_C2_2,$aMemStats[$MEM_TOTALPHYSRAM] & ' Kb')
    endif
    If GUICtrlRead($Label_C2_3) <> $aMemStats[$MEM_AVAILPHYSRAM]  & ' Kb' then
        ControlSetText($Form1,"",$Label_C2_3,$aMemStats[$MEM_AVAILPHYSRAM]  & ' Kb')
    endif
    If GUICtrlRead($Label_C2_4) <> $aMemStats[$MEM_TOTALPAGEFILE] & ' Kb' then
        ControlSetText($Form1,"",$Label_C2_4,$aMemStats[$MEM_TOTALPAGEFILE] & ' Kb')
    endif
    If GUICtrlRead($Label_C2_5) <> $aMemStats[$MEM_AVAILPAGEFILE] & ' Kb' then
        ControlSetText($Form1,"",$Label_C2_5,$aMemStats[$MEM_AVAILPAGEFILE] & ' Kb')
    endif
    If GUICtrlRead($Label_C2_6) <> $aMemStats[$MEM_TOTALVIRTUAL]  & ' Kb' then
        ControlSetText($Form1,"",$Label_C2_6,$aMemStats[$MEM_TOTALVIRTUAL]  & ' Kb')
    endif
    If GUICtrlRead($Label_C2_7) <> $aMemStats[$MEM_AVAILVIRTUAL]  & ' Kb' then
        ControlSetText($Form1,"",$Label_C2_7,$aMemStats[$MEM_AVAILVIRTUAL]  & ' Kb')
    endif
EndFunc

 

Edited by GNGNUT
Updated the Script content based on comments from others for better coding practice,
Link to comment
Share on other sites

Your while Loop is not good at all.  It registers adlib functions and hotkeyset repeatedly which is useless.  Just put those statements once at the beginning of the script.  It is also a bad practice to put code between functions, it makes it hard to read and hard to debug.  Put all your main code together at the beginning of the script before all functions.

At first glance, beside the above comments, your code looks right, even if I didn't test it.  You do not seem to say that you have a particular problem...

Link to comment
Share on other sites

HI Nine Ty for the comments, 

The problem i have and looking for a solution to is   Getting it to update - when its not in focus  as I'm working on other things on my pc, 

so if i'm writing emails, coding ect I would still like to see the GUI to update Per sec with out me having to click on it to update, 

Currently if i take focus The time will stop - and only change once i refocus the Gui again,

 

Link to comment
Share on other sites

I see.  Declare your $Form1 as Global, and replace all controlSetText first parameter with $Form1, instead of "".  Should work...

If that doesn't work put top most extended style to your GUI.

Edited by Nine
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

×
×
  • Create New...