Sign in to follow this  
Followers 0
stuka

...

7 posts in this topic

#1 ·  Posted (edited)

.

Edited by stuka

Share this post


Link to post
Share on other sites



sry, I made a mistake about command ;p

the right command was: TrayItemSetState($Notepad_focus, $GUI_DISABLE)

here's an example:

#include <Constants.au3>
#include <GUIConstants.au3>
#NoTrayIcon

Opt("TrayOnEventMode",1)
Opt("TrayMenuMode",1)
Opt("WinTitleMatchMode", 2)

$Notepad_focus = TrayCreateItem("Focus Notepad")
TrayItemSetOnEvent(-1,"FocusNotepad")
TrayCreateItem("")
$exit = TrayCreateItem("Exit")
TrayItemSetOnEvent(-1,"ExitEvent")

TraySetState()
AdlibEnable("adlib1", 10)

func adlib1()
If Not ProcessExists("Notepad.exe") Then
    TrayItemSetState($Notepad_focus, $GUI_DISABLE)
    Else
    TrayItemSetState($Notepad_focus, $GUI_ENABLE)
EndIf   
EndFunc

While 1
    Sleep(10)  ; Idle loop
WEnd
Exit

Func ExitEvent()
    Exit
EndFunc

Func FocusNotepad ()
    WinActivate("Notepad", "")
EndFunc

Share this post


Link to post
Share on other sites

That example contradicts itself, when you right click the tray icon Notepad loses focus and the option never gets "greyed out". :)

Share this post


Link to post
Share on other sites

Try this:

#include <Constants.au3>
#include <GUIConstants.au3>
#NoTrayIcon

TraySetClick (16)
Opt("TrayMenuMode",1)

$a = "Title"

; about label
$name = TrayCreateItem ("About")

; help label
$help = TrayCreateItem ("Help!")

; hotkeys label
$hotkeys = TrayCreateItem ("Keyboard Hotkeys")

; divider
TrayCreateItem ("")

; start label
$StartItem = TrayCreateItem ("Start")

; stop label
$StopItem = TrayCreateItem ("Stop")

; pause label
$PauseItem = TrayCreateItem ("Pause/Unpause")

; divider
TrayCreateItem ("")

; remove startup entry label
$addrun = TrayCreateItem ("Add Billy To System Startup")

; remove startup entry label
$remrun = TrayCreateItem ("Remove Billy From System Startup")

; divider
TrayCreateItem ("")

; exit label
$exit = TrayCreateItem ("Exit")

; show tray icon
TraySetState ()

; tool start tray tip
TrayTip ($a, "Right click to start...", 1, 1)
; -------------------- tray menu label end -------------------

; ----------------- tray menu function start -----------------

AdlibEnable("adlib1", 10)

func adlib1()
    If Not ProcessExists("Billy.exe") Then
        TrayItemSetState($StopItem, $GUI_DISABLE)
    Else
        TrayItemSetState($StopItem, $GUI_ENABLE)
    EndIf
EndFunc


; begin loop
While 1

    $msg = TrayGetMsg ()
    Select
        Case $msg = 0
            ContinueLoop
           
           ; ----- info label-----

           ; info msg box
        Case $msg = $name
            MsgBox (64, "Autorun Eater 1.0", "yadayada.")
           
           ; ----- help label-----

           ; help option
        Case $msg = $help
            If FileExists ("C:\Program Files\Mozilla Firefox\firefox.exe") Then
                Run (@ComSpec & ' /c start firefox.exe "C:\Program Files\Autorun Eater Temp\help.html" ', "", @SW_HIDE)
            Else
                ShellExecute ("iexplore.exe", "C:\Program Files\Autorun Eater Temp\help.html")
            EndIf
           
           ; ----- hotkey label-----
           
           ; hotkeys traytip
        Case $msg = $hotkeys
            TrayTip ("Keyboard Hotkeys", "Pause = pause tool", 1 , 1)
           
           ; ----- start label-----

           ; start Billy option
        Case $msg = $StartItem
           
           ;start Billy sound
            If Not ProcessExists("Billy.exe") Then
            SoundPlay ("C:\Program Files\Autorun Eater Temp\goat.wav", 1)
            EndIf
           
           ; start Billy
            If Not ProcessExists("Billy.exe") Then
            ShellExecute ("C:\Program Files\Autorun Eater Temp\Billy.exe")
            EndIf
       
           ; scan started traytip
            If ProcessExists("Billy.exe") Then
            TrayTip ("Tool Status", "Scan Started", 1 , 1)
            Else
            TrayTip ("Tool Status", "Cannot Start Duplicate Processes!", 1 , 1)
            EndIf
           
           ; ----- stop label-----
           
           ; stop Billy option
        Case $msg = $StopItem
           
           ; stop Billy sound
            If ProcessExists("Billy.exe") Then
            SoundPlay ("C:\Program Files\Autorun Eater Temp\goat.wav", 1)
            EndIf
           
           ; scan stopped traytip
            If ProcessExists("Billy.exe") Then
            TrayTip ("Tool Status", "Scan Stopped", 1 , 1)
            EndIf
           
           ; stop Billy
            ProcessClose ("Billy.exe")
           
            If Not ProcessExists("Billy.exe") Then
            TrayTip ("Tool Status", "No Process To Stop", 1 , 1)
            EndIf
        Case $msg = $exit
            ExitLoop
EndSelect
WEnd
Exit

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