Jump to content
Sign in to follow this  

simple loop question

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

Share this post

Link to post
Share on other sites

#include "SysTray_UDF.au3"


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
     $pos = _SysTrayIconPos($index)
    If $pos = -1 Then Exit; ** A real error this time;)

MouseMove($pos[0], $pos[1])


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

thanks much :)

Share this post

Link to post
Share on other sites

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

I've come up with an easy workaround :


     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  

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...