Jump to content

Enable / Disable Tray Menu


Recommended Posts

Hi to all, i want to have an option in my application that allow to enable or disable the tray menu when i minimize the programm...

Here is my code to show what i want to do :)

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

$hGUI = GUICreate("Form1", 259, 76, 284, 388)
$Button1 = GUICtrlCreateButton("", 8, 8, 75, 25)
$Button2 = GUICtrlCreateButton("Try Func", 88, 32, 75, 25)
$Button3 = GUICtrlCreateButton("Try Func 2", 168, 8, 75, 25)
GUISetState(@SW_SHOW)

If IniRead (@ScriptDir & "\Setup.ini","Main","Tray","") = "" Then
    IniWrite (@ScriptDir & "\Setup.ini","Main","Tray","False")
ElseIf IniRead (@ScriptDir & "\Setup.ini","Main","Tray","") = "False" Then
    GUICtrlSetData ($Button1, "Enable Tray")
ElseIf IniRead (@ScriptDir & "\Setup.ini","Main","Tray","") = "True" Then
    GUICtrlSetData ($Button1, "Disable Tray")

EndIf

Opt("TrayAutoPause", 0)
Opt("TrayMenuMode", 11)


While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $GUI_EVENT_MINIMIZE
            If IniRead (@ScriptDir & "\Setup.ini","Main","Tray","") = "True" Then
                ;Create and show the tray menu
            Else
                ;Hyde Tray Menu
                EndIf
        Case $Button1
            If IniRead (@ScriptDir & "\Setup.ini","Main","Tray","") = "False" Then
                IniWrite (@ScriptDir & "\Setup.ini","Main","Tray","True")
                GUICtrlSetData ($Button1, "Disable Tray")
            ElseIf IniRead (@ScriptDir & "\Setup.ini","Main","Tray","") = "True" Then
                IniWrite (@ScriptDir & "\Setup.ini","Main","Tray","False")
                GUICtrlSetData ($Button1, "Enable Tray")
            EndIf
        Case $Button2
            ConsoleWrite ("It's only an example" & @CRLF)
        Case $Button3
            ConsoleWrite ("It's only an example" & @CRLF)
    EndSwitch
WEnd

How i can do that?...if the tray menu option is on enable i want to create a tray menu...else i dont want the tray menu :)

Hi!

Edited by StungStang
Link to comment
Share on other sites

  • Moderators

StungStang,

Use TraySetClick(0) to disable your tray menu when a $GUI_EVENT_MINIMIZE event occurs - and then reset it to whatever you require when you see a $GUI_EVENT_RESTORE event. :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

@Melba23

I want create a tray menu if a $GUI_EVENT_MINIMIZE event occurs and the flag "main" is set to True...as i can see on help file TraySetClick(0) Sets the clickmode of the tray icon...

Hi :)

EDIT:

I've fixed my problem with the function TraySetState ..., but i've another problem...i want activate (give the focus) on the main gui when i press "Return To GUI"...i try with WinActivate but don't work...this is my code:

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

$hGUI = GUICreate("Form1", 259, 76, 284, 388)
$Button1 = GUICtrlCreateButton("", 8, 8, 75, 25)
$Button2 = GUICtrlCreateButton("Try Func", 88, 32, 75, 25)
$Button3 = GUICtrlCreateButton("Try Func 2", 168, 8, 75, 25)
GUISetState(@SW_SHOW)

If IniRead (@ScriptDir & "\Setup.ini","Main","Tray","") = "" Then
    IniWrite (@ScriptDir & "\Setup.ini","Main","Tray","False")
ElseIf IniRead (@ScriptDir & "\Setup.ini","Main","Tray","") = "False" Then
    GUICtrlSetData ($Button1, "Enable Tray")
ElseIf IniRead (@ScriptDir & "\Setup.ini","Main","Tray","") = "True" Then
    GUICtrlSetData ($Button1, "Disable Tray")

EndIf

Opt("TrayAutoPause", 0)
Opt("TrayMenuMode", 11)

;#####################################################################
$TrayeExit = TrayCreateItem("Exit")
$TrayReturn = TrayCreateItem("Return To GUI")
$Traymessage = TrayCreateItem("Example")
TraySetState (2)
;#####################################################################


While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $GUI_EVENT_MINIMIZE
            If IniRead (@ScriptDir & "\Setup.ini","Main","Tray","") = "True" Then
               TraySetState ()
               GUISetState(@SW_HIDE)
            Else
               TraySetState (2)
                EndIf
        Case $Button1
            If IniRead (@ScriptDir & "\Setup.ini","Main","Tray","") = "False" Then
                IniWrite (@ScriptDir & "\Setup.ini","Main","Tray","True")
                GUICtrlSetData ($Button1, "Disable Tray")
            ElseIf IniRead (@ScriptDir & "\Setup.ini","Main","Tray","") = "True" Then
                IniWrite (@ScriptDir & "\Setup.ini","Main","Tray","False")
                GUICtrlSetData ($Button1, "Enable Tray")
            EndIf
        Case $Button2
            ConsoleWrite ("It's only an example" & @CRLF)
        Case $Button3
            ConsoleWrite ("It's only an example" & @CRLF)
    EndSwitch
    Switch TrayGetMsg ()
        Case $TrayeExit
            Exit
        Case $TrayReturn
            GUISetState(@SW_SHOW)
            WinActivate ($hGUI) ;It don't work it dont give the focus on main gui
        Case $Traymessage
            ConsoleWrite ("It's only an example" & @CRLF)
    EndSwitch
WEnd
Edited by StungStang
Link to comment
Share on other sites

  • Moderators

StungStang,

I want create a tray menu if a $GUI_EVENT_MINIMIZE event occurs and the flag "main" is set to True

Do not create the menu each time - just create the menu when you create the GUI and by using TraySetClick only allow it to be actioned when the main GUI is minimized and your flag is set. :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

  • Moderators

StungStang,

That is because you need to RESTORE the GUI from its minimized state: :)

Case $TrayReturn
    GUISetState(@SW_SHOW)
    GUISetState(@SW_RESTORE)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...