Jump to content

simple loop question


Valhalla1
 Share

Recommended Posts

can someone help me with my script ?

I am launching an app from a script, this app puts an icon in the systray. I'm able to use the systray UDF to interact with the icon just fine, the problem I have is there is a variable amount of time before the icon is loaded which throws off the timing

I've put in a sleep() wait before the script tries to interact with the icon but the timing is a blind guess and depends how fast the pc is.. the lag waiting for the sleep to end bugs me on fast computers but it needs to be there on slow pc's or everything messes up

so I want a Do..While loop I assume, with Sleep(1000) inside the loop.

I need a function that will check if my systray icon has loaded yet, return a 1 or 0 to keep me in the loop or kick me out of the loop once its loaded and proceed

thanks for any tips

Link to comment
Share on other sites

#include "SysTray_UDF.au3"
#NoTrayIcon

Run("C:\XXX.exe","",@SW_HIDE)
ProcessWait("XXX.exe")


Sleep(30000) ;  <----  this i want to replace


$oldMatchMode = Opt("WinTitleMatchMode", 4)
$oldChildMode = Opt("WinSearchChildren", 1)
$class = "classname=Shell_TrayWnd"
$hControl = ControlGetHandle($class, "", "Button2")
$posTray = WinGetPos(_FindTrayToolbarWindow())
MouseMove($posTray[0], $posTray[1])
$index = _SysTrayIconIndex("XXX.exe")
If $index <> -1 Then
$pos = _SysTrayIconPos($index)

If $pos = -1 Then
     If $hControl <> "" And ControlCommand($class, "", $hControl, "IsVisible","") Then
    ControlClick($class, "", $hControl)
    Sleep(250); Small delay to allow the icons to be drawn
    EndIf
     $pos = _SysTrayIconPos($index)
    If $pos = -1 Then Exit; ** A real error this time;)
EndIf

MouseMove($pos[0], $pos[1])
Sleep(500)
MouseClick("right")
Send("{UP}")
Sleep(50)
Send("{ENTER}")
Sleep(250)
Send("{ENTER}")
ProcessClose("XXX.exe")
ProcessWaitClose("XXX.exe")
Sleep(100)

EndIf

Opt("WinTitleMatchMode", $oldMatchMode)
Opt("WinSearchChildren", $oldChildMode)
Exit

thanks much :)

Link to comment
Share on other sites

I've come up with an easy workaround :

$systraycount=_SysTrayIconCount()
 $systraycount2=$systraycount+1

 
 Do
     sleep(1000) 
      $systraycount=_SysTrayIconCount()
     Until $systraycount=$systraycount2

this counts the tray icons then I'll launch my app and wait until the traycount increases by 1 to start interacting with it

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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...