Jump to content



Photo

minimise to system tray


  • Please log in to reply
13 replies to this topic

#1 ChrisL

ChrisL

    Mass Spanner!

  • Active Members
  • PipPipPipPipPipPip
  • 1,746 posts

Posted 23 May 2006 - 04:19 PM

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

AutoIt         
#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, 17 July 2007 - 09:47 PM.






#2 Pakku

Pakku

    Prodigy

  • Active Members
  • PipPipPip
  • 183 posts

Posted 23 May 2006 - 04:30 PM

Hi ChrisL,

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

thanks

Arjan
How can someone use Windows without using AutoIt?That one would properly don't know how to handle a computer!My scripts:Send files over internetKind of RSS reader3Draw ProUDF: convert a character string to a binary one and backCalculate PiCommand line downloader (Youtube/Google video)Set the transparency of a window just by hitting a key!Secure your pcOther things:http://www.autoitscript.com/fileman/users/arjan%20staring/My profilePM me

#3 RazerM

RazerM

    cowinkeedenky - coincidence?

  • Active Members
  • PipPipPipPipPipPip
  • 1,246 posts

Posted 23 May 2006 - 05:01 PM

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.

#4 iceberg

iceberg

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 301 posts

Posted 22 September 2006 - 08:38 AM

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.

#5 SmOke_N

SmOke_N

    It's not what you know ... It's what you can prove!

  • Moderators
  • 15,729 posts

Posted 22 September 2006 - 09:15 AM

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.
AutoIt         
#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, 22 September 2006 - 09:16 AM.

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.


#6 iceberg

iceberg

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 301 posts

Posted 22 September 2006 - 12:51 PM

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.

#7 iceberg

iceberg

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 301 posts

Posted 22 September 2006 - 12:55 PM

this was the code taken off the forum

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

#8 Zedna

Zedna

    AutoIt rulez!

  • MVPs
  • 8,315 posts

Posted 22 September 2006 - 09:09 PM

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

AutoIt         
#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, 22 September 2006 - 09:19 PM.


#9 iceberg

iceberg

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 301 posts

Posted 23 September 2006 - 11:44 AM

thanks Zedna!
mouse not found....scroll any mouse to continue.

#10 jftuga

jftuga

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 315 posts

Posted 23 September 2006 - 02:13 PM

Nice script, I like it!

-John

#11 slayerz

slayerz

    Prodigy

  • Active Members
  • PipPipPip
  • 160 posts

Posted 16 May 2008 - 03:26 AM

Nice and simple script, thanks for sharing :)
AUTOIT I'm lovin' it!

#12 BinaryCortex

BinaryCortex

    Seeker

  • New Members
  • 2 posts

Posted 22 February 2010 - 02:48 PM

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?

#13 Melba23

Melba23

    Yes, me!

  • Moderators
  • 15,330 posts

Posted 22 February 2010 - 03:00 PM

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
StringSize - Automatically size controls to fit text - ExtMsgBox - A user customisable replacement for MsgBox

Toast - Small GUIs which pop out of the Systray - Marquee - Scrolling tickertape GUIs

Scrollbars - Automatically sized scrollbars with a single command - GUIFrame - Subdivide GUIs into many adjustable frames

GUIExtender - Extend and retract multiple sections within a GUI - NoFocusLines - Remove the dotted focus lines from buttons, sliders, radios and checkboxes

ChooseFileFolder - Single and multiple selections from specified path tree structure - - Notify - Small notifications on the edge of the display

RecFileListToArray - An alternative to _FileListToArray with user-defined include/exclude masks, maximum recursion level, sorting and displayed path options

GUIListViewEx - Insert, delete, move, drag and sort ListView items


#14 grimmlock

grimmlock

    Prodigy

  • Active Members
  • PipPipPip
  • 171 posts

Posted 05 December 2012 - 08:32 PM

Yes that works Thank you!!!
ThanksGrimm




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users