Jump to content

Trayicon and change the "icon"


lgvlgv
 Share

Recommended Posts

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
Link to comment
Share on other sites

  • Moderators

@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?

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
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

 

Link to comment
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 :/

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

×
×
  • Create New...