Jump to content

Minimize to tray, no open window on start bar


ledigeine
 Share

Recommended Posts

Searched and found one thread but it wasn't very helpful.

I was wondering how to do this, I have a UI and I would like it when you hit minimize it will go to the tray. Not the start bar.

Then the tray will have options to just run from there, or restoring to the UI the saw before.

I am sure its a common thing, just cant figure it out so far.

Link to comment
Share on other sites

  • Moderators

ledigeine,

This should give you the idea: ;)

#include <GUIConstantsEx.au3>

Opt("TrayOnEventMode", 1) ; Use event trapping for tray menu
Opt("TrayMenuMode", 3) ; Default tray menu items will not be shown.

$hTray_Show_Item = TrayCreateItem("Hide")
TrayItemSetOnEvent(-1, "To_Tray")
TrayCreateItem("")
TrayCreateItem("Exit")
TrayItemSetOnEvent(-1, "On_Exit")

; Use the Autoit window as a parent to prevent appearing on the taskbar 
$hGUI = GUICreate("Test", 200, 200, 200, 200, Default, Default, WinGetHandle(AutoItWinGetTitle()))
GUISetState()

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $GUI_EVENT_MINIMIZE
            To_Tray()
    EndSwitch
WEnd

Func To_Tray()

    If TrayItemGetText($hTray_Show_Item) = "Hide" Then
        GUISetState(@SW_HIDE, $hGUI)
        TrayItemSetText($hTray_Show_Item, "Show")
    Else
        GUISetState(@SW_SHOW, $hGUI)
        GUISetState(@SW_RESTORE, $hGUI)
        TrayItemSetText($hTray_Show_Item, "Hide")
    EndIf

EndFunc

Func On_Exit()
    Exit
EndFunc

All clear? :)

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

Now I thought i read that if you do the event trapping type thing then it will mess up other aspects like getmsg or something like that.

So would i want this whole thing in another file so my main UI while will not break because the trapping is turned on?

Link to comment
Share on other sites

As you can see by his script, he's using TRAY event mode, and GUIGetMsg in the same script without an issue.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

You can't use GUI event mode and GUIgetmsg in the same script at the same time, but you can use TRAY event mode and GUIgetmsg together. And vice versa, you can use GUI EventMode and Traygetmsg at the same time, just not traygetmsg and tray event mode together.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

Sorry to revive this, I can make a new thread if needed. Just trying ot keep things orderly.

what format would i be using things in my while loop. I already have one for the main UI so if a button is pushed it will do x.

I pretty much will have the same 'buttons' in the tray, do i just do a new switch monitoring a var set to traygetmsg and have cases with in that?

While 1

$msg = guigetmsg(1)

$Tmsg = traygetmsg()

switch $msg[1]

blahblah

endswitch

switch $Tmsg

blahblahtraystuff

endswitch

wend

Link to comment
Share on other sites

  • Moderators

ledigeine,

Yes, the two are entirely separate - so you will need 2 Switch structures. :)

Personally I tend to use TrayOnEvent mode for the tray and MessageLoop for any GUIs - I find it gives a better response for the tray items which tend to be major events that need fast action. ;)

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

Hmm so right now i have two messageloops right, one for the main ui and one for the tray. But the trayonevent one, would that be more like vb.net where its looking for events?

I think i'll try what i have now just to see if i can get it working, just because im not very familiar with the other way you mentioned.

Thank you again.

Link to comment
Share on other sites

  • Moderators

ledigeine,

No, you only ever need one loop. This script demonstrates how to use TrayOnEvent and GUI MessageLoop - does it help clear the air? :huh:

#include <GUIConstantsEx.au3>

Opt("TrayOnEventMode", 1) ; Use event trapping for tray menu
Opt("TrayMenuMode", 3) ; Default tray menu items will not be shown.

$hTray_Show_Item = TrayCreateItem("Hide")
TrayItemSetOnEvent(-1, "To_Tray")
TrayCreateItem("")
TrayCreateItem("Exit")
TrayItemSetOnEvent(-1, "On_Exit")

; Use the Autoit window as a parent to prevent appearing on the taskbar
$hGUI = GUICreate("Test", 200, 200)

$cButton = GUICtrlCreateButton("Test", 10, 10, 80, 30)

GUISetState()

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $GUI_EVENT_MINIMIZE
            To_Tray()
        Case $cButton
            MsgBox(0, "Hi", "Testing!")
    EndSwitch
WEnd

Func To_Tray()

    If TrayItemGetText($hTray_Show_Item) = "Hide" Then
        GUISetState(@SW_HIDE, $hGUI)
        TrayItemSetText($hTray_Show_Item, "Show")
    Else
        GUISetState(@SW_SHOW, $hGUI)
        GUISetState(@SW_RESTORE, $hGUI)
        TrayItemSetText($hTray_Show_Item, "Hide")
    EndIf

EndFunc

Func On_Exit()
    Exit
EndFunc

Please ask if you have any questions. :)

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

Hmm see from the tray i already have the hide and show working what I am having trouble with is calling a function(s) that a button press on the UI would normally call.

So say the Test button you have on the UI, could you put the msgbox in a function. Then add a tray item that will call that function for the msgbox. After seeing that I think I will be able to figure it out.

What i thought i knew is turning out to not work, I hit the tray button that the switch is monitoring in the while and nothing happens.

Link to comment
Share on other sites

  • Moderators

ledigeine,

Does this explain better? :huh:

#include <GUIConstantsEx.au3>

Opt("TrayOnEventMode", 1) ; Use event trapping for tray menu
Opt("TrayMenuMode", 3) ; Default tray menu items will not be shown.

Global $fButton = False

TrayCreateItem("Test")
TrayItemSetOnEvent(-1, "_Test_Func")
TrayCreateItem("")
TrayCreateItem("")
$hTray_Show_Item = TrayCreateItem("Hide")
TrayItemSetOnEvent(-1, "To_Tray")
TrayCreateItem("")
TrayCreateItem("Exit")
TrayItemSetOnEvent(-1, "On_Exit")

$hGUI = GUICreate("Test", 200, 200)

$cButton = GUICtrlCreateButton("Test", 10, 10, 80, 30)

GUISetState()

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $GUI_EVENT_MINIMIZE
            To_Tray()
        Case $cButton
            $fButton = True ; The button is calling the function
            _Test_Func()
            $fButton = False ; Clear the flag
    EndSwitch
WEnd

Func _Test_Func()

    If $fButton Then
        MsgBox(0, "Hi", "Testing!" & @CRLF & @CRLF & "Called from Button")
    Else
        MsgBox(0, "Hi", "Testing!" & @CRLF & @CRLF & "Called from Tray")
    EndIf

EndFunc

Func To_Tray()

    If TrayItemGetText($hTray_Show_Item) = "Hide" Then
        GUISetState(@SW_HIDE, $hGUI)
        TrayItemSetText($hTray_Show_Item, "Show")
    Else
        GUISetState(@SW_SHOW, $hGUI)
        GUISetState(@SW_RESTORE, $hGUI)
        TrayItemSetText($hTray_Show_Item, "Hide")
    EndIf

EndFunc

Func On_Exit()
    Exit
EndFunc

Because we cannot use parameters with OnEvent functions (one reason why I tend only to use this mode for the tray) we need the $fButton flag to determine whether the function was fired from the tray or the button. If you do not care about which control triggered the function then you can of course delete all references to it. ;)

Any clearer? Ask again if not. :)

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

ledigeine,

You know where we are if you do have issues - but I suggest you open a new thread in that case. ;)

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

×
×
  • Create New...