Sign in to follow this  
Followers 0
potitpanda

Help with TrayIcon Menu

4 posts in this topic

Hi

I have created a tray Icon Menu with 2 items:

Close which close the program

Connect Which connect to a shared folder using Net Use

So when it's connected

I Want the line Connect to Change as "Disconnect" without add a Line in my tray menu and when I Click on Disconnect, go to Function Disconnect()

How to do this ?

#include <Constants.au3>

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

TraySetClick(16)   ; Only secondary mouse button will show the tray menu.

$infoitem = TrayCreateItem("Connecter...")
TrayItemSetOnEvent(-1,"Connecter")

TrayCreateItem("")

$exititem = TrayCreateItem("Fermer")
TrayItemSetOnEvent(-1,"ExitScript")

TraySetState()

While 1
    Sleep(10)  ; Idle loop
WEnd

; Functions
Func Connecter()
  run("net use \\172.26.0.163\Moliere /user:AD-0133490Y\moliere moliere","",@SW_HIDE)
MsgBox(0,"Connecté", "Vous etes connecté à Molière")
EndFunc

Func ExitScript()
    Exit
EndFunc

Func Deconnecter()
     Run("net use /delete \\172.26.0.163\Moliere","",@SW_HIDE)
     MsgBox(0,"Déconnecté", "Vous etes Déconnecté de Molière")
Exit    
EndFunc

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Hi

I have created a tray Icon Menu with 2 items:

Close which close the program

Connect Which connect to a shared folder using Net Use

So when it's connected

I Want the line Connect to Change as "Disconnect" without add a Line in my tray menu and when I Click on Disconnect, go to Function Disconnect()

How to do this ?

CODE
#include <Constants.au3>

Opt("TrayOnEventMode",1)

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

TraySetClick(16) ; Only secondary mouse button will show the tray menu.

$infoitem = TrayCreateItem("Connecter...")

TrayItemSetOnEvent(-1,"Connecter")

TrayCreateItem("")

$exititem = TrayCreateItem("Fermer")

TrayItemSetOnEvent(-1,"ExitScript")

TraySetState()

While 1

Sleep(10) ; Idle loop

WEnd

; Functions

Func Connecter()

run("net use \\172.26.0.163\Moliere /user:AD-0133490Y\moliere moliere","",@SW_HIDE)

MsgBox(0,"Connecté", "Vous etes connecté à Molière")

EndFunc

Func ExitScript()

Exit

EndFunc

Func Deconnecter()

Run("net use /delete \\172.26.0.163\Moliere","",@SW_HIDE)

MsgBox(0,"Déconnecté", "Vous etes Déconnecté de Molière")

Exit

EndFunc

Give this a try (untested, but the basic concept is there):

CODE

#include <Constants.au3>

Opt("TrayOnEventMode", 1)

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

TraySetClick(16) ; Only secondary mouse button will show the tray menu.

$connectionitem = TrayCreateItem("Connecter...")

TrayItemSetOnEvent(-1, "Connecter")

$iConnected = 0

TrayCreateItem("")

$exititem = TrayCreateItem("Fermer")

TrayItemSetOnEvent(-1, "ExitScript")

TraySetState()

While 1

Sleep(10) ; Idle loop

WEnd

; Functions

Func Connecter()

If $iConnected Then

Run("net use /delete \\172.26.0.163\Moliere", "", @SW_HIDE)

TrayItemSetText($connectionitem,"Débranchez...")

MsgBox(0, "Déconnecté", "Vous etes Déconnecté de Molière")

Else

Run("net use \\172.26.0.163\Moliere /user:AD-0133490Y\moliere moliere", "", @SW_HIDE)

TrayItemSetText($connectionitem,"Connect")

MsgBox(0, "Connecté", "Vous etes connecté à Molière")

EndIf

$iConnected = Not $iConnected

EndFunc

Func ExitScript()

Exit

EndFunc

***Edit*** Spacing Edited by Monamo

- MoChr(77)& Chr(97)& Chr(100)& Chr(101)& Chr(32)& Chr(121)& Chr(97)& Chr(32)& Chr(108)& Chr(111)& Chr(111)& Chr(107)-------I've told you 100,000 times not to exaggerate!-------Don't make me hit you with my cigarette hand...-------My scripts:Random Episode Selector, Keyboard MouseMover, CopyPath v2.1, SmartRename for XP,Window Tracer[sup]New![/sup]

Share this post


Link to post
Share on other sites

Another way to do it.

#include <Constants.au3>

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

TraySetClick(16)   ; Only secondary mouse button will show the tray menu.

$infoitem = TrayCreateItem("Connecter...")
TrayItemSetOnEvent(-1,"Connecter")

TrayCreateItem("")

$exititem = TrayCreateItem("Fermer")
TrayItemSetOnEvent(-1,"ExitScript")

TraySetState()

While 1
    Sleep(10)  ; Idle loop
WEnd

; Functions
Func Connecter()
    run("net use \\172.26.0.163\Moliere /user:AD-0133490Y\moliere moliere","",@SW_HIDE)
    TrayItemSetText($infoitem, 'Disconnect')
    TrayItemSetOnEvent($infoitem, "DeConnecter")
    MsgBox(0,"Connecté", "Vous etes connecté à Molière")
EndFunc

Func ExitScript()
    Exit
EndFunc

Func Deconnecter()
     Run("net use /delete \\172.26.0.163\Moliere","",@SW_HIDE)
     MsgBox(0,"Déconnecté", "Vous etes Déconnecté de Molière")
    Exit    
EndFunc

Share this post


Link to post
Share on other sites

Second Method Works Fine

Thanks

PS : I Will test the first method Later

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