Sign in to follow this  
Followers 0
Nearro

Update GUI without gaining focus?

6 posts in this topic

Here's the basic idea and what I'm currently doing to get it working:

I've got a program that runs in one portion of the screen. What I am doing is monitoring certain sections of that screen for color changes. I have created a rather simple GUI window that sits beside it to show basic information I'm gathering, mainly to debug the further development of the script.

What I currently have it do is every couple seconds, it checks the main screen, switches to the GUI window, updates a list view if anything has changed, then switches back to the main window. While it's working, it's extremely slow and can sometimes miss a change if it doesn't catch it quick. It is, in my opinion, a very inefficient way to debug, since I'd like to be able to see when the script is catching changes a little quicker.

So, now for the question(s).

(1) Is it possible to update a GUI window without having the window regain focus, essentially update in the background?

(2) Is there a better idea to use instead of a ListBox/Gui window for printing variables onscreen? (Answering that might solve #1 as well)

If needed, I can post the script I currently have, though it is very ugly and a bit hard to follow.

Share this post


Link to post
Share on other sites



Depending on how the gui is set up, it might be possible to.

You'll have to post your script more than likely to get help in getting it working.


SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Share this post


Link to post
Share on other sites

Here's the code I have for reviewing. I tried to clean it up a little to make it a bit more understandable.

The UpdateGUI Function is the one that is the main concern. It switches to the GUI window, updates the listview, then switches back. That's where I'm wondering if it's possible to bypass the switching windows and have it update in the background, say when one of the variables changes.

#include <GuiConstants.au3>

Sleep(3000)
WinActivate("Main Window")
Sleep(2000)
Global $Paused
HotKeySet("{PAUSE}", "TogglePause")
HotKeySet("{ESC}", "Terminate")
Global $con1,$con2,$condition1,$condition2
$ForceRun = 1
$PassNum = 0
$nextaction = "Initialize"
; GUI
GuiCreate("Info Window",200, 110, 1050, 500)
GuiSetState()
WinActivate("Main Window")

While $ForceRun = 1
$condition2 = "No"
$iscondition1 = "No"
$nextaction = "Step 1"
UpdateGui()
_GetItem()
$PassNum = $PassNum + 1
if $condition1 = 1 Then
    $iscondition1 = "Yes"
    $nextaction = "Step 2"
    UpdateGui()
    _CheckColor()
    _DoAction()
    $nextaction = "Step 3"
    UpdateGui()

EndIf

WEnd

While GuiGetMsg() <> $GUI_EVENT_CLOSE
WEnd



Func UpdateGui()
    WinActivate("Info Window")
    $treeTwo = GuiCtrlCreateTreeView(0, 0, 190, 100, $TVS_CHECKBOXES)
    GuiCtrlCreateTreeViewItem("Con1: "&$con1, $treeTwo)
    GuiCtrlCreateTreeViewItem("Con2: "&$con2, $treeTwo)
    GuiCtrlCreateTreeViewItem("Cond1: "&$iscondition1, $treeTwo)
    GuiCtrlCreateTreeViewItem("Cond2: "&$condition2, $treeTwo)
    GuiCtrlCreateTreeViewItem("Pass #: "&$PassNum, $treeTwo)
    GuiCtrlCreateTreeViewItem("Next Action: "&$nextaction, $treeTwo)
    WinActivate("Main Window")
EndFunc


Func _DoAction()
    send("Action")
EndFunc

Func _CheckColor()
    $comb = PixelGetColor(875,607)
    While $comb = 14026752
        $nextaction = "Check Loop"
        $condition2 = "Yes"
        UpdateGui()
        sleep(1000)
        $comb = PixelGetColor(875,607)
    WEnd
EndFunc


Func _GetItem()
    Send("{TAB}")
    sleep(1000)
    $con1a = 1
    $con2a = 1
    $condition1 = 1
    $con1 = PixelSearch(928,766,948,766,0xF50000)
    If Not @error Then
        $con1a = 0
        $condition1 = 0
    EndIf
    $con2 = PixelSearch(928,766,948,766,0xD27FFC)
    If Not @error Then
        $con2a = 0
        $condition1 = 0
    EndIf
EndFunc

Func TogglePause()
    $Paused = NOT $Paused
    While $Paused
        sleep(100)
        ToolTip('Script is "Paused"',0,0)
    WEnd
    ToolTip("")
EndFunc

Func Terminate()
    Exit 0
EndFunc

Share this post


Link to post
Share on other sites

have your try removing the winactivate part?


i think

Share this post


Link to post
Share on other sites

I've tried it without switching back to the GUI using WinActivate and the GUI doesn't update. What it needs is for the Main Window to retain the focus and the script to update the GUI in the background.

Share this post


Link to post
Share on other sites

I don't know what to try to achieved

I add a simulation of you "main window" and creation of the "info window" on top to see that udpate are done remove the winactivate in updateGUI()

Perhaps it what you want to do.

#include <GuiConstants.au3>
run("notepad")
WinWait("Untitled")
WinSetTitle("Untitled","","Main Window")
WinActivate("Main Window")

Global $Paused
HotKeySet("{PAUSE}", "TogglePause")
HotKeySet("{ESC}", "Terminate")
Global $con1,$con2,$condition1,$condition2
$ForceRun = 1
$PassNum = 0
$nextaction = "Initialize"
; GUI
GuiCreate("Info Window",200, 110, 750, 400,-1,$WS_EX_TOPMOST )
GuiSetState()
WinActivate("Main Window")

While $ForceRun = 1
$condition2 = "No"
$iscondition1 = "No"
$nextaction = "Step 1"
UpdateGui()
_GetItem()
$PassNum = $PassNum + 1
if $condition1 = 1 Then
    $iscondition1 = "Yes"
    $nextaction = "Step 2"
    UpdateGui()
    _CheckColor()
    _DoAction()
    $nextaction = "Step 3"
    UpdateGui()

EndIf

WEnd

While GuiGetMsg() <> $GUI_EVENT_CLOSE
WEnd



Func UpdateGui()
;   WinActivate("Info Window")
    $treeTwo = GuiCtrlCreateTreeView(0, 0, 190, 100, $TVS_CHECKBOXES)
    GuiCtrlCreateTreeViewItem("Con1: "&$con1, $treeTwo)
    GuiCtrlCreateTreeViewItem("Con2: "&$con2, $treeTwo)
    GuiCtrlCreateTreeViewItem("Cond1: "&$iscondition1, $treeTwo)
    GuiCtrlCreateTreeViewItem("Cond2: "&$condition2, $treeTwo)
    GuiCtrlCreateTreeViewItem("Pass #: "&$PassNum, $treeTwo)
    GuiCtrlCreateTreeViewItem("Next Action: "&$nextaction, $treeTwo)
;   WinActivate("Main Window")
EndFunc


Func _DoAction()
    send("Action")
EndFunc

Func _CheckColor()
    $comb = PixelGetColor(875,607)
    While $comb = 14026752
        $nextaction = "Check Loop"
        $condition2 = "Yes"
        UpdateGui()
        sleep(1000)
        $comb = PixelGetColor(875,607)
    WEnd
EndFunc


Func _GetItem()
    Send("{TAB}")
    sleep(1000)
    $con1a = 1
    $con2a = 1
    $condition1 = 1
    $con1 = PixelSearch(928,766,948,766,0xF50000)
    If Not @error Then
        $con1a = 0
        $condition1 = 0
    EndIf
    $con2 = PixelSearch(928,766,948,766,0xD27FFC)
    If Not @error Then
        $con2a = 0
        $condition1 = 0
    EndIf
EndFunc

Func TogglePause()
    $Paused = NOT $Paused
    While $Paused
        sleep(100)
        ToolTip('Script is "Paused"',0,0)
    WEnd
    ToolTip("")
EndFunc

Func Terminate()
    Exit 0
EndFunc

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