jfitty Posted July 7, 2009 Share Posted July 7, 2009 (edited) Hey guys, Ive found some code around the forum to allow me to minimize my program to the tray. This works great, until you press a button to run a function. Here is the code: expandcollapse popup#include <GUIConstantsEx.au3> #include <ProgressConstants.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #NoTrayIcon #Include <Constants.au3> Func Test() sleep(40000) EndFunc Opt("TrayOnEventMode",1) Opt("TrayMenuMode",1) TraySetOnEvent($TRAY_EVENT_PRIMARYUP,"SpecialEvent") ;TraySetState(2); hide --> not needed #Region ### START Koda GUI section ### Form=e:\usb backup\backup - good\other\koda form designer\forms\main.kxf $Form1 = GUICreate("Form1", 395, 191, 192, 124) $Group1 = GUICtrlCreateGroup("", 8, 8, 377, 57) $Icon1 = GUICtrlCreateIcon("E:\backup.ico", 0, 16, 24, 32, 32, BitOR($SS_NOTIFY,$WS_GROUP)) $heading = GUICtrlCreateLabel("Label1", 128, 24, 64, 27) GUICtrlSetFont(-1, 12, 800, 0, "Arial Black") GUICtrlCreateGroup("", -99, -99, 1, 1) $Progress1 = GUICtrlCreateProgress(8, 80, 377, 25) $Group2 = GUICtrlCreateGroup("", -8, 112, 377, 65) $Label6 = GUICtrlCreateLabel("0", 8, 224, 11, 19) GUICtrlSetFont(-1, 8, 800, 0, "Arial Black") GUICtrlCreateGroup("", -99, -99, 1, 1) $label1 = GUICtrlCreateLabel("0", 168, 128, 10, 18) GUICtrlSetFont(-1, 8, 800, 0, "Arial") $label2 = GUICtrlCreateLabel("Text", 16, 128, 139, 19) GUICtrlSetFont(-1, 8, 800, 0, "Arial Black") $label3 = GUICtrlCreateLabel("Text", 16, 152, 104, 19) GUICtrlSetFont(-1, 8, 800, 0, "Arial Black") $button = GUICtrlCreateButton("Label5", 128, 152, 40, 18) GUICtrlSetFont(-1, 8, 800, 0, "Arial") GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### GUISetState(@SW_SHOW) While 1 $msg = GuiGetMsg() Select Case $msg = $GUI_EVENT_MINIMIZE GuiSetState(@SW_HIDE) TraySetState(1); show TraySetToolTip ("My app - click here to restore") Case $msg = $GUI_EVENT_CLOSE Exit Case $msg = $button Test() EndSelect WEnd Func SpecialEvent() GuiSetState(@SW_Show) TraySetState(2); hide EndFunc When I first run the program, I can minimize it to the task bar and maximize it fine, but after pressing the button and running the function "Test" it wont work. This probably sounds like a n00b question, but can anyone help? Thanks Edited July 7, 2009 by jfitty Link to comment Share on other sites More sharing options...
Robjong Posted July 7, 2009 Share Posted July 7, 2009 Hey, It's because the sleep(40000) tells AutoIt to do nothing for 40000ms (40 seconds) so the code to minimize to tray is not executed, but after the sleep time has passed it will be. Just try it with Sleep(4000), press the button once then click the minimize button and wait a few seconds to see what happens. If you need the sleep time use the Timer* functions instead. Link to comment Share on other sites More sharing options...
jfitty Posted July 7, 2009 Author Share Posted July 7, 2009 (edited) Thanks for the reply, I dont actually want the program to sleep, it was just an example of something for the program to do. I have a longer function that is actually called when the button is pressed. But I want it so i can minimize at any time during that function Edited July 7, 2009 by jfitty Link to comment Share on other sites More sharing options...
Yashied Posted July 7, 2009 Share Posted July 7, 2009 You can use Opt("GUIOnEventMode", 1). My UDFs: iKey | FTP Uploader | Battery Checker | Boot Manager | Font Viewer | UDF Keyword Manager | Run Dialog Replacement | USBProtect | 3D Axis | Calculator | Sleep | iSwitcher | TM | NetHelper | File Types Manager | Control Viewer | SynFolders | DLL Helper Animated Tray Icons UDF Library | Hotkeys UDF Library | Hotkeys Input Control UDF Library | Caret Shape UDF Library | Context Help UDF Library | Most Recently Used List UDF Library | Icons UDF Library | FTP UDF Library | Script Communications UDF Library | Color Chooser UDF Library | Color Picker Control UDF Library | IPHelper (Vista/7) UDF Library | WinAPI Extended UDF Library | WinAPIVhd UDF Library | Icon Chooser UDF Library | Copy UDF Library | Restart UDF Library | Event Log UDF Library | NotifyBox UDF Library | Pop-up Windows UDF Library | TVExplorer UDF Library | GuiHotKey UDF Library | GuiSysLink UDF Library | Package UDF Library | Skin UDF Library | AITray UDF Library | RDC UDF Library Appropriate path | Button text color | Gaussian random numbers | Header's styles (Vista/7) | ICON resource enumeration | Menu & INI | Tabbed string size | Tab's skin | Pop-up circular menu | Progress Bar without animation (Vista/7) | Registry export | Registry path jumping | Unique hardware ID | Windows alignment More... Link to comment Share on other sites More sharing options...
jfitty Posted July 7, 2009 Author Share Posted July 7, 2009 Where abouts would I put it? Link to comment Share on other sites More sharing options...
jfitty Posted July 7, 2009 Author Share Posted July 7, 2009 Let me clarify a bit more. The function I want to run is a backup program I've put together (Which ive called Test in the code) and I want the ability to minimize and restore it while this function is running. It works fine before I run the function, but not while it is running Thanks again Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now