Jump to content

Help minimizing to tray!


Recommended Posts

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:

#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 by jfitty
Link to comment
Share on other sites

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

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 by jfitty
Link to comment
Share on other sites

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

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...