Jump to content
Sign in to follow this  
Valhalla1

simple loop question

Recommended Posts

Valhalla1

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

Share this post


Link to post
Share on other sites
meekaah

post your script so we can help :)

Share this post


Link to post
Share on other sites
Valhalla1

#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 :)

Share this post


Link to post
Share on other sites
Valhalla1

any ideas anyone ? thanks

Share this post


Link to post
Share on other sites
Generator

You can do it this way, use one of the system UDF and test if you are able to interact with the trayicon, if it doesn' exist it will return error which indicates it's not shown up yet. I haven't try System Tray UDF so i could only help on ideas.

Share this post


Link to post
Share on other sites
Valhalla1

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

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  

×