Jump to content

minimise to system tray


ChrisL
 Share

Recommended Posts

minimise a gui to the system tray

Edit~: Updated to support newer versions of Autoit, thanks to Zedna too I've used some of your suggestions

#NoTrayIcon
#include <GuiConstants.au3>
#include <Constants.au3>

Opt("GUIEventOptions",1)
Opt("TrayOnEventMode",1)
Opt("TrayMenuMode",1)   

TraySetOnEvent($TRAY_EVENT_PRIMARYUP,"SpecialEvent")


$gui = GuiCreate("MyGUI", 392, 316,-1, -1 , BitOR($WS_OVERLAPPEDWINDOW, $WS_CLIPSIBLINGS))
GuiSetState()

While 1
    $msg = GuiGetMsg()
    
    Select
        Case $msg = $GUI_EVENT_MINIMIZE 
            GuiSetState(@SW_MINIMIZE)
            GuiSetState(@SW_HIDE)
            TraySetState(1) ; show
            
            If @OSVersion = "WIN_NT4" or @OSVersion = "WIN_ME" or @OSVersion = "WIN_98" or @OSVersion = "WIN_95" then
                TraySetToolTip ("My app - click here to restore")
            Else
                Traytip ("My App", "click here to restore", 5)
            EndIf
            

        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop
    EndSelect
WEnd

Func SpecialEvent()
    GuiSetState(@SW_RESTORE)
    GuiSetState(@SW_Show)
    TraySetState(2) ; hide
EndFunc
Edited by ChrisL
Link to comment
Share on other sites

Hi ChrisL,

nice idee i can use this in one of my scripts!

thanks

Arjan

Link to comment
Share on other sites

simple yet effective. Nice

My Programs:AInstall - Create a standalone installer for your programUnit Converter - Converts Length, Area, Volume, Weight, Temperature and Pressure to different unitsBinary Clock - Hours, minutes and seconds have 10 columns each to display timeAutoIt Editor - Code Editor with Syntax Highlighting.Laserix Editor & Player - Create, Edit and Play Laserix LevelsLyric Syncer - Create and use Synchronised Lyrics.Connect 4 - 2 Player Connect 4 Game (Local or Online!, Formatted Chat!!)MD5, SHA-1, SHA-256, Tiger and Whirlpool Hash Finder - Dictionary and Brute Force FindCool Text Client - Create Rendered ImageMy UDF's:GUI Enhance - Enhance your GUIs visually.IDEA File Encryption - Encrypt and decrypt files easily! File Rename - Rename files easilyRC4 Text Encryption - Encrypt text using the RC4 AlgorithmPrime Number - Check if a number is primeString Remove - remove lots of strings at onceProgress Bar - made easySound UDF - Play, Pause, Resume, Seek and Stop.
Link to comment
Share on other sites

  • 3 months later...

hi ChrisL,

thanks alot for the codes. but can i check with you something....what if i am using "Switch...Case...EndSwitch"? I tried to play around with the codes for half an hr. i cdn't figure it out.

pls help me. thanks.

mouse not found....scroll any mouse to continue.

Link to comment
Share on other sites

  • Moderators

hi ChrisL,

thanks alot for the codes. but can i check with you something....what if i am using "Switch...Case...EndSwitch"? I tried to play around with the codes for half an hr. i cdn't figure it out.

pls help me. thanks.

I'd like to see what you "tried" if you couldn't get it to work.
#include <GuiConstants.au3>
#include <Constants.au3>

Opt("TrayOnEventMode",1)
Opt("TrayMenuMode",1)   
Opt("TrayIconHide", 0)

TraySetOnEvent($TRAY_EVENT_PRIMARYUP,"SpecialEvent")
TraySetState()

GuiCreate("MyGUI", 392, 316,-1, -1 , BitOR($WS_OVERLAPPEDWINDOW, $WS_CLIPSIBLINGS))
GuiSetState()

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_MINIMIZE
            GuiSetState(@SW_HIDE)
            Opt("TrayIconHide", 0) 
            Traytip ("My App", "Click the Icon not the Tool Tip To Restore", 5)
        Case $GUI_EVENT_CLOSE
            ExitLoop
    EndSwitch
WEnd

Func SpecialEvent()
    GuiSetState(@SW_Show)
    Opt("TrayIconHide", 1)
EndFunc
Edit:

:) (Forgot to paste my code)

Edited by SmOke_N

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

thanks SmOke_N,

well one of the scripts i got from the forum was using "Switch...Case...EndSwitch" method. And the other portion of the script i made was with "Select...Case...EndSelect" method. I didn't knew how to combine both of them. I even tried having 2 "whiles". obviously tat didn't work.

mouse not found....scroll any mouse to continue.

Link to comment
Share on other sites

this was the code taken off the forum

While 1
    Sleep(0)
    $recv = TCPRecv($sock, 2048)
    If not $recv Then ContinueLoop
    $recv = StringSplit($recv, Chr(1))
    For $i = 1 to $recv[0]
        $temp = StringSplit($recv[$i], Chr(2))
        Switch $temp[1]
            Case "rejected"
                mError("Too many users in chat room.", 1)
            Case "accepted"
            ; nothing
            Case "adduser"
                _AddUser($temp[2])
            Case "deluser"
                _DelUser($temp[2])
            Case "exit"
                mError("Server has closed.", 1)
            Case Else
                If $recv[$i] Then GUICtrlSetData($edit, $recv[$i] & @CRLF, 1)
        EndSwitch
    Next
    _ReduceMemory()
WEnd

my code was

While 1
   $msg = GUIGetMsg()
   Select
       Case $msg = $GUI_EVENT_CLOSE
         MsgBox(0, "", "Dialog was closed") 
         Exit
      Case $msg = $GUI_EVENT_MINIMIZE
         MsgBox(0,"", "Dialog minimized",2)
      Case $msg = $GUI_EVENT_MAXIMIZE
         MsgBox(0,"", "Dialog restored",2)
   
      Case $msg = $button_1
         MsgBox(0, "Default button clicked", "Radio " & $radioval1 )
         
      Case $msg >= $radio_1 AND $msg <= $radio_3
         $radioval1 = $msg - $radio_1

   EndSelect
WEnd

so tats where i got blurred.

mouse not found....scroll any mouse to continue.

Link to comment
Share on other sites

minimise a gui to the system tray

Thanks for very nice and simple code :)

I made little changes:

1) #NoTrayIcon - to avoid initial flash of tray

2) hide tray after start of application

3) use TraySetState(2) ; hide and TraySetState(1) ; show

instead of Opt("TrayIconHide", 0/1)

4) use TraySetToolTip instead of TrayTip --> to work also on WIN98

#NoTrayIcon
#include <GuiConstants.au3>
#include <Constants.au3>

Opt("TrayOnEventMode",1)
Opt("TrayMenuMode",1)   

TraySetOnEvent($TRAY_EVENT_PRIMARYUP,"SpecialEvent")
;TraySetState(2) ; hide --> not needed

GuiCreate("MyGUI", 392, 316,-1, -1 , BitOR($WS_OVERLAPPEDWINDOW, $WS_CLIPSIBLINGS))
GuiSetState()

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
            ExitLoop
    EndSelect
WEnd

Func SpecialEvent()
    GuiSetState(@SW_Show)
    TraySetState(2) ; hide
EndFunc
Edited by Zedna
Link to comment
Share on other sites

  • 1 year later...
  • 1 year later...

This script is not working for me.

C:\Users\NameDeleted\Desktop\tray.au3 (12) : ==> Variable used without being declared.:

$gui = GuiCreate("MyGUI", 392, 316,-1, -1 , BitOR($WS_OVERLAPPEDWINDOW, $WS_CLIPSIBLINGS))

$gui = GuiCreate("MyGUI", 392, 316,-1, -1 , BitOR(^ ERROR

What are these supposed to be set to?

Link to comment
Share on other sites

  • Moderators

BinaryCortex,

It is a very old script and the includes have changed a lot since it was written. Put these in place of the includes currently used: :mellow:

#include <GuiConstantsEx.au3>
#include <Constants.au3>
#include <WindowsConstants.au3>

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

  • 2 years later...

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