Sign in to follow this  
Followers 0

GUI refresh

7 posts in this topic

Posted

This forum has been great for me in creating a tool I'm working on, but I've reached a sticking point that hopefully one of you guys out there can help with. I'm trying to create an on-screen-display that collects information from a program running in the background, and display it in large bold font, full screen. This information needs to update regularly (every 30 seconds or so).

I seem to have cracked gathering the information and displaying it in the format I want, but it does not update correctly. Every loop a new GUI is created and overlaps the last one, rather than refreshing or replacing it. When this happens I cannot close the GUI without ending the process. I'm new to this, so not sure whether a GUI is even the right way to display what I want - any help?

#include <GUIConstants.au3>

While 1
    
;~ Checks if the source program is running and activates
If WinExists("External Data Source") = 0 Then
    MsgBox(0, "", "External Data Source is not running")
    Exit
EndIf
WinActivate("External Data Source", "")

; Prompts an export of data
ControlSend("External Data Source", "","", "{ALT}")
ControlSend("External Data Source", "","", "{RIGHT}")
ControlSend("External Data Source", "","", "{DOWN 3}")
ControlSend("External Data Source", "","", "{ENTER}")

;~ Finds each bit of info on the clipboard, and pulls out the stats I need
$Clip = ClipGet()
$STAT1pos = StringInStr($Clip, "    ",0, 13,)
$STAT2pos = StringInStr($Clip, "    ",0, 14,)
$STAT3pos = StringInStr($Clip, "    ",0, 15,)
$STAT4pos = StringInStr($Clip, "    ",0, 16,)
$STAT5pos = StringInStr($Clip, "    ",0, 17,)
$STAT1 = StringMid($Clip, $STAT1pos+1, $STAT2pos-$STAT1pos-1)
$STAT2 = StringMid($Clip, $STAT2pos+1, $STAT3pos-$STAT2pos-1)
$STAT3 = StringMid($Clip, $STAT3pos+1, $STAT4pos-$STAT3pos-1)
$STAT4 = StringMid($Clip, $STAT4pos+1, $STAT5pos-$STAT4pos-1)

;~ Some definitions for the GUI
$GUIWidth = @DesktopWidth
$GUIHeight = @DesktopHeight
$GUIColour = 0x8b8b83
$GUIFont="Arial"
$GUIFontSize= $GUIHeight / 35

;~ Displays the results ~ Create a GUI
GUICreate("Full Screen Display",$GUIWidth,$GUIHeight,-1,-1,$WS_POPUPWINDOW,$WS_EX_TOPMOST)
GUISetBkColor ($GUIColour)
GUISetFont ($GUIFontSize, 400, $GUIFont)

;~ Create the Close button, and activate GUI
Opt("GUICoordMode",1)
$CloseButton = GUICtrlCreateButton ("Close", $GUIWidth-40, $GUIHeight-20, 40, 20,)
GUICtrlSetFont ($CloseButton, 8, 400, $GUIFont)
GUICtrlSetBkColor ($CloseButton, $GUIColour)
GUISetState ()

;~ Insert text into the GUI
$ColumnWidth = $GUIWidth / 6
$RowHeight = $GUIHeight / 10
GUICtrlCreateLabel ("1st stat to display", $ColumnWidth * 1 , $RowHeight * 1)
GUICtrlCreateLabel ("2nd stat to display", $ColumnWidth * 1 , $RowHeight * 2)
GUICtrlCreateLabel ("3rd stat to display", $ColumnWidth * 1 , $RowHeight * 3)
GUICtrlCreateLabel ("4th stat to display", $ColumnWidth * 1 , $RowHeight * 4)

GUICtrlCreateLabel ($STAT1, $ColumnWidth * 3 , $RowHeight * 1)
GUICtrlCreateLabel ($STAT2, $ColumnWidth * 3 , $RowHeight * 2)
GUICtrlCreateLabel ($STAT3, $ColumnWidth * 3 , $RowHeight * 3)
GUICtrlCreateLabel ($STAT4, $ColumnWidth * 3 , $RowHeight * 4)

Sleep(5000)
WEnd

Share this post


Link to post
Share on other sites



Posted

I corrected only GUI related stuff not your external logic.

Note that WinActivate() inside loop is incorrect - comment this line and in ControlSend() specify ClassNameNN parameter.

#include <GUIConstants.au3>

Opt("GUICoordMode",1)

;~ Some definitions for the GUI
$GUIWidth = @DesktopWidth
$GUIHeight = @DesktopHeight
$GUIColour = 0x8b8b83
$GUIFont="Arial"
$GUIFontSize= $GUIHeight / 35

$ColumnWidth = $GUIWidth / 6
$RowHeight = $GUIHeight / 10

;~ Displays the results ~ Create a GUI
GUICreate("Full Screen Display",$GUIWidth,$GUIHeight,-1,-1,$WS_POPUPWINDOW,$WS_EX_TOPMOST)
GUISetBkColor ($GUIColour)
GUISetFont ($GUIFontSize, 400, $GUIFont)

;~ Create the Close button, and activate GUI
$CloseButton = GUICtrlCreateButton ("Close", $GUIWidth-40, $GUIHeight-20, 40, 20)
GUICtrlSetFont ($CloseButton, 8, 400, $GUIFont)
GUICtrlSetBkColor ($CloseButton, $GUIColour)

GUICtrlCreateLabel ("1st stat to display", $ColumnWidth * 1 , $RowHeight * 1)
GUICtrlCreateLabel ("2nd stat to display", $ColumnWidth * 1 , $RowHeight * 2)
GUICtrlCreateLabel ("3rd stat to display", $ColumnWidth * 1 , $RowHeight * 3)
GUICtrlCreateLabel ("4th stat to display", $ColumnWidth * 1 , $RowHeight * 4)

$label1 = GUICtrlCreateLabel ('', $ColumnWidth * 3 , $RowHeight * 1)
$label2 = GUICtrlCreateLabel ('', $ColumnWidth * 3 , $RowHeight * 2)
$label3 = GUICtrlCreateLabel ('', $ColumnWidth * 3 , $RowHeight * 3)
$label4 = GUICtrlCreateLabel ('', $ColumnWidth * 3 , $RowHeight * 4)

GUISetState ()

While 1
    $msg = GUIGetMsg()
    If $msg = $GUI_EVENT_CLOSE Or $msg = $CloseButton Then ExitLoop
    
    ;~ Checks if the source program is running and activates
    If WinExists("External Data Source") = 0 Then
        MsgBox(0, "", "External Data Source is not running")
        Exit
    EndIf
    WinActivate("External Data Source", "")

    ; Prompts an export of data
    ControlSend("External Data Source", "","", "{ALT}")
    ControlSend("External Data Source", "","", "{RIGHT}")
    ControlSend("External Data Source", "","", "{DOWN 3}")
    ControlSend("External Data Source", "","", "{ENTER}")

    ;~ Finds each bit of info on the clipboard, and pulls out the stats I need
    $Clip = ClipGet()
    $STAT1pos = StringInStr($Clip, "    ",0, 13)
    $STAT2pos = StringInStr($Clip, "    ",0, 14)
    $STAT3pos = StringInStr($Clip, "    ",0, 15)
    $STAT4pos = StringInStr($Clip, "    ",0, 16)
    $STAT5pos = StringInStr($Clip, "    ",0, 17)
    $STAT1 = StringMid($Clip, $STAT1pos+1, $STAT2pos-$STAT1pos-1)
    $STAT2 = StringMid($Clip, $STAT2pos+1, $STAT3pos-$STAT2pos-1)
    $STAT3 = StringMid($Clip, $STAT3pos+1, $STAT4pos-$STAT3pos-1)
    $STAT4 = StringMid($Clip, $STAT4pos+1, $STAT5pos-$STAT4pos-1)

    GUICtrlSetData ($label1, $STAT1)
    GUICtrlSetData ($label2, $STAT1)
    GUICtrlSetData ($label3, $STAT1)
    GUICtrlSetData ($label4, $STAT1)
WEnd

Share this post


Link to post
Share on other sites

Posted (edited)

Hi,

From a brief look at your script , it looks like your creating your gui and labels over and over again.

This is due to you have your Gui and Labels inside the main While 1 loop.

So While 1 you are recreating the Gui and Labels over and over and over and over and over and over........ again and again and again and again.... until While doesn't equal 1.

Maybe try creating your Gui and Labels before the While 1 loop then in the While 1 loop use GuiCtrlSetData() to set the info in the already created labels instead of recreating the labels over and over again.

Good luck and Cheers

Edit: I was to slow as usual , Zenda has the answer

Edited by smashly

Share this post


Link to post
Share on other sites

Posted

Edit: I was to slow as usual , Zenda has the answer

I'm Zedna and not Zenda :) !!!

You are not the first with this my nickname "improvement" here.

I know in english it sound like a crap but in Czech it's OK :P and it's based on my real name so change will not happen.

Share this post


Link to post
Share on other sites

Posted

Thanks Zedna, Zenda and smashley :) You've helped me out of a jam. I knew one of the forum gurus would point me in the right direction.

Share this post


Link to post
Share on other sites

Posted

Sorry about that Zedna :">

How rude of me , after seeing your helpful post for the past year and I still got your name wrong , shame on me. :)

Will make sure I get it correct next time :P

All the best

Cheers.

Share this post


Link to post
Share on other sites

Posted

Sorry about that Zedna :">

How rude of me , after seeing your helpful post for the past year and I still got your name wrong , shame on me. :)

Will make sure I get it correct next time :)

All the best

Cheers.

OK. I trust your promise :P

Cheers.

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

  • Recently Browsing   0 members

    No registered users viewing this page.