Sign in to follow this  
Followers 0
MikeP

SetTrayIcon always success

3 posts in this topic

Hi, I'll try describing my problem as precisely as possible to make sure you understand. At the start of my script I'm using #NoTrayIcon then setting up my own with SetTrayIcon(".\ico\*****.ico") what I would like to do is hiding it with TraySetState(2) if a stupid user of my application is going to the ico directory to rename the .ico file.

So I tried this :

$trayIco = TraySetIcon(".\ico\******.ico")
MsgBox(0, "", $trayIco)
If $trayIco = 0 Then
    TraySetState(2)
Else
    TraySetState()
EndIf

The problem is, wether the script is compiled or not, If i'm changing the ico file name so that the script will fail, the Msgbox always popup with 1 .. which means TraySetIcon was successful...

Any ideas?

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Mayb this?

Global $check = False

$IconPath = "c:\Temp\autorun1.ico"

$trayIco = TraySetIcon($IconPath)

While 1
    If (FileExists($IconPath) = 0) And ($check = True) Then
        $check = False
        TraySetState(2)
    ElseIf (FileExists($IconPath) = 1) And ($check = False) Then
        $check = True
        TraySetState()
    EndIf
    Sleep(50)
WEnd
Edited by rasim

Share this post


Link to post
Share on other sites

Nice way-around.. there's a little mistake in the initialization $check must be True , this script is not the 100% perfect solution though. For a few milliseconds the icon of the .exe file still appear in the tray.

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