Sign in to follow this  
Followers 0
StungStang

Enable / Disable Tray Menu

7 posts in this topic

#1 ·  Posted (edited)

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

Share this post


Link to post
Share on other sites



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


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

@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

Share this post


Link to post
Share on other sites

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


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites

yes...se the post above your :)

Hi!

Share this post


Link to post
Share on other sites

StungStang,

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

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

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites

Thanks a lot, problem fixed :)

Hi,

StungStang

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