Jump to content
Sign in to follow this  
Roman

Hide one menu item from default tray menu?

Recommended Posts

Hi

I just want to delete the "Script paused" item from the default tray-icon menu because the other item "Exit" is the only one i need.

How can i do that?

The help file mentions the "TrayItemDelete" command, but wants a "controlID" of that menu item, but which value is that?

I feel like an absolut beginner... :whistle:

Thanks for every help.

Roman

Share this post


Link to post
Share on other sites

Modified from the TrayCreateItem in the help file

#Include <Constants.au3>

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


$exititem       = TrayCreateItem("Exit")

TraySetState()

While 1
    $msg = TrayGetMsg()
    Select
        Case $msg = 0
            ContinueLoop
                Case $msg = $exititem
            ExitLoop
    EndSelect
WEnd

Exit

Edit - Removed unrequired line

Edited by BigDod


Time you enjoyed wasting is not wasted time ......T.S. Elliot
Suspense is worse than disappointment................Robert Burns
God help the man who won't help himself, because no-one else will...........My Grandmother

Share this post


Link to post
Share on other sites

I saw this help information too, but i wonder if that self created "Exit" has the same behaviour like the "Exit" from the default menu item.

Reason:

For example, my script starts an external exe file with "RunWait" und waits for termination and the return code of that executable.

This lasts maybe 10 minutes. If i click "Exit" from the default tray menu item during this RunWait, the script immediately ends, doesn't matter the external program has terminated or not!

But if i use your example, the scripts ends the earliest when the external executable terminated because i can handle the input of that tray menu item only in the next lines of code after the RunWait command, or not?

Or is it possible to have something like a second thread, i mean AutoIt waits with RunWait for termination of an external program und handles the input of that tray menu item at the same time? :whistle:

Roman.

Share this post


Link to post
Share on other sites

You could do that... Have 2 scripts... A loader/killer and the main script... The loader/killer have the tray icon and the main has none :whistle:


Start here if you are new Valuater's AutoIT 1-2-3Looking for an UDF - Look hereDo you need to do it twice - Autoit

Share this post


Link to post
Share on other sites

You could do that... Have 2 scripts... A loader/killer and the main script... The loader/killer have the tray icon and the main has none :P

I have done that already in other scripts, thanks. A possible way - but not very "neat" i think.

But the conclusion is, that i can not hide or disable a menu item (in my case the item "Script paused") from the default tray menu?

What a pity. :whistle:

Regards,

Roman

Share this post


Link to post
Share on other sites

Just a little imagination is all:

Global $bToggleTrayPause

MsgBox(64, 'Info', 'Pause active')
_ToggleTrayPause()
MsgBox(64, 'Info', 'Pause Not Active')
_ToggleTrayPause()
MsgBox(64, 'Info', 'Pause Active again')

Func _ToggleTrayPause()
    $bToggleTrayPause = Not $bToggleTrayPause
    If $bToggleTrayPause Then
        Opt('TrayMenuMode', 1)
    Else
        Opt('TrayMenuMode', 0)
    EndIf
    Return
EndFunc
Obviously MsgBox() would be replaced by RunWait() and you would _TogglePause() before RunWait().

Edit:

And _TogglePause() after RunWait() to reactivate it.

Edited by SmOke_N

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Share this post


Link to post
Share on other sites

Hm... but in your example, i will "lose" all menu items temporarely - i will lose the whole tray icon menu.

Remember, i need the "Exit" item quite urgent during RunWait().

Or am i wrong with analyzing your code? :whistle:

Greetings.

Edited by roman

Share this post


Link to post
Share on other sites

Hm... but in your example, i will "lose" all menu items temporarely - i will lose the whole tray icon menu.

Remember, i need the "Exit" item quite urgent during RunWait().

Or am i wrong with analyzing your code? :whistle:

Greetings.

I don't see you being able to do what you want with RunWait() and still be able to register Exit without registering a DLL call... and I'm not quite sure about that one myself... I believe PaulIA has some Tray tools in his AU3Lib.au3, you can find it in the Example forum.

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Share this post


Link to post
Share on other sites

Want a really nasty work around? :whistle:

Global $bToggleTrayPause
MsgBox(64, 'Info', 'Pause active')
_ToggleTrayPause()
MsgBox(64, 'Info', 'Pause Not Active')
_ToggleTrayPause()
MsgBox(64, 'Info', 'Pause Active again')

Func _ToggleTrayPause()
    $bToggleTrayPause = Not $bToggleTrayPause
    If $bToggleTrayPause Then
        _RunTrayWriteFile(@TempDir & '\TrayMess.txt')
    Else
        Send("!{F9}")
        Opt('TrayIconHide', 0)
    EndIf
    Return
EndFunc

Func _RunTrayWriteFile($hFile)
    FileClose(FileOpen($hFile, 2))
    Local $sString =    "If $cmdline[0] = 0 Then Exit" & @CRLF & _
            "HotKeySet('!{F9}', '_ExitHK')" & @CRLF & _
            "Opt('TrayMenuMode', 1)" & @CRLF & _
            "Opt('TrayOnEventMode', 1)" & @CRLF & _
            "TrayCreateItem('  Exit  ')" & @CRLF & _
            "TrayItemSetOnEvent(-1, '_ExitNow')" & @CRLF & _
            "While 1" & @CRLF & _
            "Sleep(100000)" & @CRLF & _
            "WEnd" & @CRLF & _
            "Func _ExitNow()" & @CRLF & _
            "ProcessClose($cmdline[1])" & @CRLF & _
            "Exit" & @CRLF & _
            "EndFunc" & @CRLF & _
            "Func _ExitHK()" & @CRLF & _
            "Exit" & @CRLF & _
            "EndFunc"
    FileWrite($hFile, $sString)
    Local $iPID = Run('"' & @AutoItExe & '" /AutoIt3ExecuteScript "' & $hFile & '" ' & @AutoItPID, '', @SW_HIDE)
    Opt('TrayIconHide', 1)
    ProcessWait($iPID)
    FileDelete($hFile)
    Return 1
EndFunc

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

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  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...