Sign in to follow this  
Followers 0
lgvlgv

Trayicon and change the "icon"

4 posts in this topic

#1 ·  Posted (edited)

I have a problem with changeing the trayicon while program is running, is it possible?

my script seems to be running for a while then it becomes unresponcive

 

I have a script thats sets the tray icon to a "red icon" when i lose ping connection, then when ping resumes it sets it back to green icon.

But for some reason the script gets unresponsive and nothing happens, there are no errors just have to kill the trayicon the hardway.

Some times it can run for hours before it starts to "hang" again.

$nTrayIcon1 = _TrayIconCreate("Datornamn: " & @ComputerName & @CRLF & "IPAdress: " & @IPAddress1 & " ," & @IPAddress2, @ScriptFullPath, -1)
 

Local $iPing = Ping($LatencyUrl, $LatencyMS)
                    If @error Then
                        If @error = 1 Then
                            _DebugOut("---------- (_Ping Start)-----------")
                            _TrayIconSetIcon($nTrayIcon1, @ScriptFullPath, -5)
                            _TrayIconSetToolTip($nTrayIcon1, "Datornamn: " & @ComputerName & @CRLF & "IPAdress: " & @IPAddress1 & " ," & @IPAddress2 & @CRLF & "Gateway: " & _GetGatewayIP() & @CRLF & " Internet error: " & @error & ", Host is offline.")
                            ;       _TrayTip($nTrayIcon1, "Lost Connection", "Error: " & @error & " Host is offline.", $nTimeOut = 3, $nInfoFlags = 0)
                            _DebugOut("*PING: " & @error & ", Host is offline")
                            _DebugOut("---------- (_Ping End)-----------" & @CRLF)
                        ElseIf @error = 2 Then
                            _DebugOut("---------- (_Ping Start)-----------")
                            _TrayIconSetIcon($nTrayIcon1, @ScriptFullPath, -5)
                            _TrayIconSetToolTip($nTrayIcon1, "Datornamn: " & @ComputerName & @CRLF & "IPAdress: " & @IPAddress1 & " ," & @IPAddress2 & @CRLF & "Gateway: " & _GetGatewayIP() & @CRLF & " Internet error: " & @error & ", Host is unreachable.")
                            ;       _TrayTip($nTrayIcon1, "Lost Connection", "Error: " & @error & "Host is unreachable.", $nTimeOut = 3, $nInfoFlags = 0)
                            _DebugOut("*PING: " & @error & ", Host is unreachable")
                            _DebugOut("---------- (_Ping End)-----------" & @CRLF)
                        ElseIf @error = 3 Then
                            _DebugOut("---------- (_Ping Start)-----------")
                            _TrayIconSetIcon($nTrayIcon1, @ScriptFullPath, -5)
                            _TrayIconSetToolTip($nTrayIcon1, "Datornamn: " & @ComputerName & @CRLF & "IPAdress: " & @IPAddress1 & " ," & @IPAddress2 & @CRLF & "Gateway: " & _GetGatewayIP() & @CRLF & " Internet error: " & @error & ", Bad destination")
                            ;       _TrayTip($nTrayIcon1, "Lost Connection", "Error: " & @error & " Bad destination.", $nTimeOut = 3, $nInfoFlags = 0)
                            _DebugOut("*PING: " & @error & ", Bad destination")
                            _DebugOut("---------- (_Ping End)-----------" & @CRLF)
                        ElseIf @error = 4 Then
                            _DebugOut("---------- (_Ping Start)-----------")
                            _TrayIconSetIcon($nTrayIcon1, @ScriptFullPath, -5)
                            _TrayIconSetToolTip($nTrayIcon1, "Datornamn: " & @ComputerName & @CRLF & "IPAdress: " & @IPAddress1 & " ," & @IPAddress2 & @CRLF & "Gateway: " & _GetGatewayIP() & @CRLF & " Internet error: " & @error & ", Other errors")
                            ;       _TrayTip($nTrayIcon1, "Lost Connection", "Error: " & @error & " Other errors.", $nTimeOut = 3, $nInfoFlags = 0)
                            _DebugOut("*PING: " & @error & ", Other errors")
                            _DebugOut("---------- (_Ping End)-----------" & @CRLF)
                        EndIf
                    Else
                        _DebugOut("*PING: The roundtrip-time took: " & $iPing & "ms.")
                        _TrayIconSetIcon($nTrayIcon1, @ScriptFullPath, -1)
                        _TrayIconSetToolTip($nTrayIcon1, "Datornamn: " & @ComputerName & @CRLF & "IPAdress: " & @IPAddress1 & " ," & @IPAddress2 & @CRLF & "Gateway: " & _GetGatewayIP() & @CRLF & " Internet: " & $iPing & " Ms.")
                        ;                       _TrayTip($nTrayIcon1, "Internet Access", "Internet: " & $iPing & " Ms.", 3, 0)
                        _DebugOut("---------- (_Ping End)-----------" & @CRLF)
                    EndIf

 

Edited by lgvlgv

Share this post


Link to post
Share on other sites

@lgvlgv if the script is hung at a certain point, then of course it isn't going to be able to change the icon. Have you tried adding the TrayIconDebug option to the top of your script, to find out precisely where it is hanging?


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites

Dident know about "TrayIconDebug :)" thx.
 

im useing " ModernMenu UDF by Holger Kotsch"

he has a function in hes file " _TrayIconSetState($NotificationID, $NewState)"

maybe i need to update the state for every change, it seems to be runing better now?

hasent hung the app for 1 hour now :)

 

;**********************************************************************
; _TrayIconSetState($NotificationID, $NewState)
;**********************************************************************
Func _TrayIconSetState($nID = -1, $nState = 1)
    If $nState = 0 Then Return 1 ; No change

    If $nID = -1 Then $nID = $TRAYLASTID
    If $TRAYMSGWND = 0 Or $nID <= 0 Then Return 0

    Local $i, $nResult = 0, $bFound = FALSE

    For $i = 1 To $TRAYNOTIFYIDS[0][0]
        If $nID = $TRAYNOTIFYIDS[$i][0] Then
            $bFound = TRUE
            ExitLoop
        EndIf
    Next

    If Not $bFound Then Return 0

    Local $stNID = DllStructCreate($sNOTIFYICONDATAW)

    If BitAnd($nState, 1) Then
        DllStructSetData($stNID, 1, DllStructGetSize($stNID))
        DllStructSetData($stNID, 2, $TRAYMSGWND)
        DllStructSetData($stNID, 3, $nID)
        DllStructSetData($stNID, 4, BitOr($NIF_ICON, $NIF_MESSAGE))
        DllStructSetData($stNID, 5, $TRAYTIPMSG)
        DllStructSetData($stNID, 6, $TRAYNOTIFYIDS[$nID][1])

        $nResult = Shell_NotifyIcon($NIM_ADD, DllStructGetPtr($stNID))
        If $nResult Then _TrayIconSetToolTip($nID, $TRAYNOTIFYIDS[$nID][4])
    ElseIf BitAnd($nState, 2) Then
        DllStructSetData($stNID, 1, DllStructGetSize($stNID))
        DllStructSetData($stNID, 2, $TRAYMSGWND)
        DllStructSetData($stNID, 3, $nID)

        $nResult = Shell_NotifyIcon($NIM_DELETE, DllStructGetPtr($stNID))
    EndIf

    If BitAnd($nState, 4) Then
        If Not $TRAYNOTIFYIDS[$nID][7] Then
            If $hBlankIcon = 0 Then _CreateBlankIcon()
            If $hBlankIcon <> 0 Then
                SetTimer($TRAYMSGWND, $FLASHTIMERID, $FLASHTIMEOUT, 0)
                $TRAYNOTIFYIDS[$nID][7] = TRUE
            EndIf
        EndIf
    ElseIf BitAnd($nState, 8) Then
        KillTimer($TRAYMSGWND, $FLASHTIMERID)

        DllStructSetData($stNID, 1, DllStructGetSize($stNID))
        DllStructSetData($stNID, 2, $TRAYMSGWND)
        DllStructSetData($stNID, 3, $nID)
        DllStructSetData($stNID, 4, $NIF_ICON)
        DllStructSetData($stNID, 6, $TRAYNOTIFYIDS[$nID][1])

        $nResult = Shell_NotifyIcon($NIM_MODIFY, DllStructGetPtr($stNID))

        $TRAYNOTIFYIDS[$nID][7] = FALSE
        $TRAYNOTIFYIDS[$nID][8] = FALSE
    EndIf

    Return $nResult
EndFunc

 

Share this post


Link to post
Share on other sites
20 hours ago, JLogan3o13 said:

@lgvlgv if the script is hung at a certain point, then of course it isn't going to be able to change the icon. Have you tried adding the TrayIconDebug option to the top of your script, to find out precisely where it is hanging?

Still hungs, does  "_TrayIconSetToolTip" work for anyone else?
It works for a while then program goes to 20 % cpu and dont respond?

 

Sence this is an udf in use the TrayIconDebug  option dosent work :/

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

  • Similar Content

    • Simpel
      By Simpel
      Hi,
      I'm wondering why my code snippet isn't working. I copied most of it from a script where it work's. Here is the code:
      #include <Constants.au3> Opt("TrayAutoPause", 0) ; no pause while click Opt("TrayMenuMode", 1) ; no exit and pause Opt("TrayOnEventMode", 1); While 1 Sleep(100) WEnd Exit #Region ### START Tray section Global $hIni = TrayCreateItem("open INI") TrayItemSetOnEvent (-1, "_INI") TrayCreateItem("") Global $hExit = TrayCreateItem("Exit") TrayItemSetOnEvent (-1, "_Quit") TraySetState(1) TraySetClick(16); INI and Exit with secondary click TraySetOnEvent( $TRAY_EVENT_PRIMARYDOUBLE, "_OpenPath" ); _OpenPath with primary double click #EndRegion ### END Tray section Func _OpenPath() $sPfad = @ScriptDir ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $sPfad = ' & $sPfad & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console $iDelimiterPfad = StringInStr($sPfad, "\", 0, -1) ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $iDelimiterPfad = ' & $iDelimiterPfad & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console $sPfadHoeher = StringLeft($sPfad, $iDelimiterPfad) ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $sPfadHoeher = ' & $sPfadHoeher & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console ShellExecute($sPfadHoeher) EndFunc Func _INI() ConsoleWrite("_INI" & @CRLF) Sleep(10) EndFunc Func _Quit() Exit EndFunc I can see the trayicon but there is nothing happening neither primary double click nor secondary click. What's wrong?
      Regards, Conrad