Sign in to follow this  
Followers 0
ledigeine

Minimize to tray, no open window on start bar

15 posts in this topic

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.

Share this post


Link to post
Share on other sites



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


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

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?

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

ahh yes sorry, maybe i read something incorrectly in the helpfile then.

Share this post


Link to post
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.

1 person likes this

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

Share this post


Link to post
Share on other sites

I'll just agree with you there.. haha im still a noob.

Thank you again sir.

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

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


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

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.

Share this post


Link to post
Share on other sites

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


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

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.

Share this post


Link to post
Share on other sites

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

1 person likes this

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

Ok loaded that up and it seems good to me, I will have to try to use it on my script and see what issues i have. Thank you very much again. You guys are too good.

Share this post


Link to post
Share on other sites

ledigeine,

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

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

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

  • Similar Content

    • WoodGrain
      By WoodGrain
      Hi All,
      I'm using UseTraySetIcon("shell32.dll", xx) to set my tray icon to a specific icon while running, is there a way I can specify this icon when I compile my script into an exe so my exe icon is the same?
      Thanks!
    • 9252Survive
      By 9252Survive
      Hello Guys, 
      Is there a way to have Auto it Exe messages/line number when you hover over the tray icon just at it shows when you run Au3.?
      For an example, if I the script has paused due to WinWait or Sleep I could hover over the icon and it shows the line where it's at. Is there a way to achieve the same with the compiled exe? 
      Many thanks for the help! 
       
    • jpujut
      By jpujut
      I have a script that gets a list of visible windows and makes a tray item of each in the tray menu. I'd also want it to update every time I want to access that menu again, in case new windows have appeared or some would have been closed. I'm using TrayOnEventMode option and trying to get the update going with TraySetOnEvent($TRAY_EVENT_PRIMARYDOWN...) as in the snippet below. However, the list doesn't update until after the tray menu has been closed again. I think I could work around this by having the script update the list constantly in the background, but that feels like it'd take up unnecessary amount of resources since the script might be used rarely by the user anyway. I tried using TraySetOnEvent($TRAY_EVENT_MOUSEOVER...), and that kind of does it, but it actually still calls my function many times (since the mouse cursor moves quite a bit on the icon) before the tray menu is opened. I could put another menuitem to call the update function, but I'd much rather have just the minimal amount of user actions. Similarly I could have tray menu open with a double click (with TraySetClick()) and have the first click just call the update function, but can anyone tell me if there's a way to call the update once and then have the menu open without these gimmicks?
       
      Opt("TrayOnEventMode", 1) TraySetOnEvent($TRAY_EVENT_PRIMARYDOWN, "UpdateWindowsList")  
    • Kyou
      By Kyou
      I have a working code here. 
      #include <GUIConstants.au3> #include <Constants.au3> Opt("GUIOnEventMode",1) $title = "WINDOW" $text="" $fullTest = WinExistsExact($title, $text) $PASSWORD = "PASS" $retryCount = 0 $stop = 1 ;<<<<<<<<<<<<<<<<<<<<<<<<< While 1 if $retryCount > 0 then Exit $input = InputBox("Password Protected", "Enter the password to continue", "", "*") If @error Or $input <> $PASSWORD Then MsgBox(4096,"Error", "Incorrect Password") $retryCount = $retryCount + 1 Else ;MsgBox(4096,"Success", "Password Accepted") ExitLoop EndIf Wend If $fullTest = 1 Then ;MsgBox(0, "WINDOW", "Press Ok to continue") GUICreate("WINDOW", 241, 78) ;$label = GUICtrlCreateInput ("test", 10, 10, 50, 20) GuiSetOnEvent($GUI_EVENT_CLOSE,"Quit") $button = GUICtrlCreateButton ("Start", 18, 31, 100, 25) $button1 = GUICtrlCreateButton ("Hide", 128, 31, 91, 25) ; <----- THIS IS THE BUTTON GuiCtrlSetOnEvent($button,"DoScript") GUISetState (@SW_SHOW) GUIRegisterMsg($WM_COMMAND, "_WM_COMMAND") ;<<<<<<<<<<<<<<<<<<<<< Else MsgBox(0, "WINDOW", "You need to run WINDOW client first.") EndIf While 1 Sleep(10) Wend Func _WM_COMMAND($hWnd, $Msg, $wParam, $lParam) If BitAND($wParam, 0x0000FFFF) = $button Then $stop = not $stop If $stop = 0 Then GUICtrlSetData($button, "Stop") If $stop = 1 Then GUICtrlSetData($button, "Start") EndIf Return $GUI_RUNDEFMSG EndFunc Func WinExistsExact($title, $text) AutoItSetOption( "WinTitleMatchMode", $OPT_MATCHEXACT ) $res = WinExists($title, $text) AutoItSetOption( "WinTitleMatchMode", $OPT_MATCHSTART ) Return $res EndFunc Func DoScript() While 1 For $i = 1 to 300 Sleep (10) If $stop = 1 Then Return ; GuiCtrlSetData($label, $i) Next ControlSend ( $title, "", 0, "{F12}") $a = Random(300, 900, 1) For $i = 1 to $a Sleep (10) If $stop = 1 Then Return Next ControlSend ( $title, "", 0, "{Del}") $a = Random(100, 500, 1) For $i = 1 to $a Sleep (10) If $stop = 1 Then Return Next WEnd EndFunc Func Quit() Exit EndFunc What I wanted to do is to make the 'Hide' button minimized the entire window when clicked and while it is on tray, there will be a menu if a user right clicked on it. Exactly what the code below should do.
      #NoTrayIcon #include <guiconstantsex.au3> #include <constants.au3> Opt("TrayOnEventMode", 1) Opt("TrayMenuMode", 3) ; Create tray menu items and set the events $About = TrayCreateItem("About") TrayItemSetOnEvent($About, "_About") TrayCreateItem("") ; Create a separator line. $Exit = TrayCreateItem("Exit") TrayItemSetOnEvent($Exit, "_Exit") ; Set the action if you left click on the tray icon TraySetOnEvent($TRAY_EVENT_PRIMARYUP, "SpecialEvent") ; Show the menu if the icon is right clicked TraySetClick(8) Global $MainGui = GUICreate("TestGUI", 392, 316, -1, -1) GUISetState() ;Test() While 1 Switch GUIGetMsg() Case $GUI_EVENT_MINIMIZE ; Hide the GUI GUISetState(@SW_HIDE) ; Show the icon TraySetState(1) Case $GUI_EVENT_CLOSE ExitLoop EndSwitch WEnd Func SpecialEvent() ; Show the GUI GUISetState(@SW_SHOW) GUISetState(@SW_RESTORE) ; Hide the icon TraySetState(2) EndFunc ;==>SpecialEvent Func _About() MsgBox(0,0,"Test") EndFunc Func _Exit() Exit EndFunc My problem is I cannot integrate this code to the one I have. Can anyone help me with this? I would be very much thankful as I am just starting to learn.