Sign in to follow this  
Followers 0
kpu

Setting app to wait until Window is active

6 posts in this topic

I'm working a a program that uses the tray menu to log program information. My question is how do I make my script not take up processor time and still work correclty. Here's my basic code:

Program waits until window is active ($Window) and crates a traymenu item for tracking. I'm sure some of you will think this is weird, wrong, ... etc.

#include <Array.au3>
#include <Date.au3>
#Include <Constants.au3>
#Include <File.au3>

$Window = "Untitled "
opt("TrayMenuMode", 1)  ; Default tray menu items (Script Paused/Exit) will not be shown.
TrayCreateItem("")
$exititem = TrayCreateItem("Exit")
TraySetState()

While 1
    If WinExists($Window) Then
        MsgBox(32,"Window","Window is Active at " & _DateTimeFormat( _NowCalc(), 2))
        TrayCreateItem("Window was active at "  & _DateTimeFormat( _NowCalc(), 2));just for info
    Else
               ;?? Sleep(1000)
    EndIf
    
    $msg = TrayGetMsg()
    Select
        Case $msg = 0
            ContinueLoop
        Case $msg = $exititem
            ExitLoop
    EndSelect
WEnd
    Exit
Exit

Any help would greatly be appreciated.

Share this post


Link to post
Share on other sites



#include <Array.au3>
#include <Date.au3>
#Include <Constants.au3>
#Include <File.au3>

$Window = "Untitled "
Opt("TrayMenuMode", 1) ; Default tray menu items (Script Paused/Exit) will not be shown.
TrayCreateItem("")
$exititem = TrayCreateItem("Exit")
TraySetState()
$set_item = 0
While 1
   If WinExists($Window) And Not $set_item Then
      $trayItem = TrayCreateItem("Window was active at " & _DateTimeFormat( _NowCalc(), 2));just for info
      $set_item = 1
   ElseIf Not WinExists($Window) And $set_item Then
      $set_item = 0
      TrayItemDelete($trayItem)
   EndIf
   
   $msg = TrayGetMsg()
   Select
      Case $msg = 0
         ContinueLoop
      Case $msg = $exititem
         ExitLoop
   EndSelect
WEnd
Exit


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

#3 ·  Posted (edited)

it doesnt use that much on mine... but maybe this idea could help???

#include <Date.au3>
#Include <Constants.au3>
#Include <File.au3>

$Window = "Untitled "
opt("TrayMenuMode", 1); Default tray menu items (Script Paused/Exit) will not be shown.
TrayCreateItem("")
$exititem = TrayCreateItem("Exit")
TraySetState()

AdlibEnable("Win_Exist"); you can set the time to wait

While 1
    $msg = TrayGetMsg()
    Select
        Case $msg = 0
            ContinueLoop
        Case $msg = $exititem
            ExitLoop
    EndSelect
WEnd
    Exit
Exit

Func Win_Exist()
     If WinExists($Window) Then
        MsgBox(32,"Window","Window is Active at " & _DateTimeFormat( _NowCalc(), 2))
        TrayCreateItem("Window was active at "  & _DateTimeFormat( _NowCalc(), 2));just for info
    EndIf
EndFunc

8)

PS

Gary got here first with a good idea, however i dont think he went for cpu useage

( he would know more on that than i would )

Edited by Valuater

NEWHeader1.png

Share this post


Link to post
Share on other sites

Gafrost,

Thanks for your fast response, but at idle it still is using the processor. Is it just my PC? Did you try and run it?

Thanks,

Share this post


Link to post
Share on other sites

Thanks! That seems to do the trick. I guess I didn't see that command in the help. Then again, it been awhile since I've read through the latestet beta commands. Guess I need to do that more often!

it doesnt use that much on mine... but maybe this idea could help???

#include <Date.au3>
#Include <Constants.au3>
#Include <File.au3>

$Window = "Untitled "
opt("TrayMenuMode", 1); Default tray menu items (Script Paused/Exit) will not be shown.
TrayCreateItem("")
$exititem = TrayCreateItem("Exit")
TraySetState()

AdlibEnable("Win_Exist"); you can set the time to wait

While 1
    $msg = TrayGetMsg()
    Select
        Case $msg = 0
            ContinueLoop
        Case $msg = $exititem
            ExitLoop
    EndSelect
WEnd
    Exit
Exit

Func Win_Exist()
     If WinExists($Window) Then
        MsgBox(32,"Window","Window is Active at " & _DateTimeFormat( _NowCalc(), 2))
        TrayCreateItem("Window was active at "  & _DateTimeFormat( _NowCalc(), 2));just for info
    EndIf
EndFunc

8)

PS

Gary got here first with a good idea, however i dont think he went for cpu useage

( he would know more on that than i would )

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

it does use a little, between 5 and 11 percent

try the below, was between 0 and 2 percent

#include <Array.au3>
#include <Date.au3>
#Include <Constants.au3>
#Include <File.au3>

$Window = "Untitled "
Opt("TrayMenuMode", 1); Default tray menu items (Script Paused/Exit) will not be shown.
TrayCreateItem("")
$exititem = TrayCreateItem("Exit")
TraySetState()
$set_item = 0
While 1
   
   $msg = TrayGetMsg()
   Select
      Case $msg = 0
         ContinueLoop
      Case $msg = $exititem
         ExitLoop
        Case Else
            If WinExists($Window) And Not $set_item Then
                $trayItem = TrayCreateItem("Window was active at " & _DateTimeFormat( _NowCalc(), 2));just for info
                $set_item = 1
            ElseIf Not WinExists($Window) And $set_item Then
                $set_item = 0
                TrayItemDelete($trayItem)
            EndIf
   EndSelect
WEnd
Exit
Edited by gafrost

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

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