Jump to content

TrayGetMsg seems to hang script...


Recommended Posts

I wrote a script, which checks a database every x seconds, and pops up a message if new records are added to that database. I then added a tray menu to allow for quick access to some related web pages. I then noticed that the script stopped working correctly. The script below behaves similarly, the splash screen should appear for 2 seconds every 10 seconds that the script is run. However, the script seems to hang on the TrayGetMsg call. Interestingly, if you run the mouse cursor over the tray icon, the splash screen appears, and then goes away, as it should.

Any ideas, or help would be appreciated.

;
;===============================================================================
;
#Include <Constants.au3>
#NoTrayIcon

Opt("TrayMenuMode",1)   ; Default tray menu items (Script Paused/Exit) will not be shown.

$settingsitem   = TrayCreateMenu("Settings")
$displayitem    = TrayCreateItem("Display", $settingsitem)
$printeritem    = TrayCreateItem("Printer", $settingsitem)
TrayCreateItem("")
$aboutitem      = TrayCreateItem("About")
TrayCreateItem("")
$exititem       = TrayCreateItem("Exit")

TraySetState()
$timer = TimerInit()
While 1
    $msg = TrayGetMsg()
    Select
        Case $msg = 0
            ContinueLoop
        Case $msg = $aboutitem
            Msgbox(64,"about:","AutoIt3-Tray-sample")
        Case $msg = $exititem
            ExitLoop
    EndSelect
    $timerdiff = TimerDiff($timer)
    If $timerdiff > 10000 Then
        SplashTextOn("Splash","More than 10 seconds have passed")
        Sleep(2000)
        $timer = TimerInit()
        SplashOff()
    EndIf
WEnd

Exit
Link to comment
Share on other sites

Case $msg = 0
            ContinueLoop

Return Value

Returns an event.

The "event" returned is the control ID of the control sending the message, or it is a special event (like the mouse clicking on the tray icon). Or if there is no message, the event is 0.

Somewhat hard to get past that Continueloop unless some non 0 event happens as you are blocking 0 getting through the loop.

:)

Link to comment
Share on other sites

Somewhat hard to get past that Continueloop unless some non 0 event happens as you are blocking 0 getting through the loop.

:)

You're absolutely right... have to be more carful about copy/pasting from the help file :D

Thanks!!

Link to comment
Share on other sites

By the way, you can put the timerdiff check into a Case:

$timerdiff = TimerDiff($timer)

While 1
    $msg = TrayGetMsg()
    Select
        Case $msg = 0
            ContinueLoop
        Case $msg = $aboutitem
            Msgbox(64,"about:","AutoIt3-Tray-sample")
        Case $msg = $exititem
            ExitLoop
        Case $timerdiff > 10000 
            SplashTextOn("Splash","More than 10 seconds have passed")
            Sleep(2000)
            $timer = TimerInit()
            SplashOff()
    EndSelect
WEnd

:)

Edited by Teldin
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...