Jump to content

Send to Tray


Erik.
 Share

Recommended Posts

Hello,

I have a simple question and i hope it will be simple...

I have already used the Search button but did not found anything i want...

When you press the minimize button on the window of my script that my windows will go away and set it to tray when you click one time on the icon it will show to gui...

How to do that?

Or a button send to tray

I little problem, hard to find and fix

Link to comment
Share on other sites

#Include <GUIConstants.au3>
#Include <Constants.au3>


Opt("TrayMenuMode",1)
Opt("TrayAutoPause",0)

GUICreate("My Gui")
GUISetState()
While 1
    Sleep(10)
    $Msg=GUIGetMsg()
    $MsgT=TrayGetMsg()
    Select 
    Case $Msg=$GUI_EVENT_CLOSE
        Exit
    Case $Msg=$GUI_EVENT_MINIMIZE
        WinSetState("My Gui","",@SW_HIDE)
    Case $MsgT=$TRAY_EVENT_PRIMARYDOWN
        WinSetState("My Gui","",@SW_SHOW)
        WinActivate("My Gui")
    EndSelect       
WEnd

It could be shorter using GuiOnEventMode me thinks.

-edit-

Also, you could set the gui as toolbox (so there's no taskbar button) and hide the tray icon when it's visible and show it when you hide it.

Edited by Nahuel
Link to comment
Share on other sites

Yes, of course. Notice the "TrayAutoPause" mode.

It's strange.. remember that you have to use one primary click to show it again.

If you want to show it with a double click, use $TRAY_EVENT_PRIMARYDOUBLE instead of $TRAY_EVENT_PRIMARYDOWN

Try this:

#Include <GUIConstants.au3>
#Include <Constants.au3>
Opt("GuiOnEventMode",1)
Opt ("TrayIconHide",1)
Opt("TrayMenuMode",1)
Opt("TrayAutoPause",0)
Opt("TrayOnEventMode",1)

GUICreate("My Gui")
GUISetOnEvent($GUI_EVENT_CLOSE,"_exit")
GUISetOnEvent($GUI_EVENT_MINIMIZE,"hide")
TraySetOnEvent($TRAY_EVENT_PRIMARYDOWN,"show")
GUISetState()

While 1
    Sleep(10)   
WEnd

Func _exit()
    Exit
EndFunc

Func hide()
    Opt ("TrayIconHide",0)
    WinSetState("My Gui","",@SW_HIDE)
EndFunc
    
Func show()
    Opt ("TrayIconHide",1)
    WinSetState("My Gui","",@SW_SHOW)
    WinActivate("My Gui")
EndFunc
Edited by Nahuel
Link to comment
Share on other sites

Hi,

This is my script:

#cs ----------------------------------------------------------------------------

AutoIt Version: 3.2.4.9

Author: myName

Script Function:

Template AutoIt script.

#ce ----------------------------------------------------------------------------

#include <GUIConstants.au3>

#Include <GuiListView.au3>

#Include <File.au3>

#include <Date.au3>

#include <Array.au3>

#include <Date.au3>

#include <string.au3>

#Include <Constants.au3>

Opt("GuiOnEventMode",1)

Opt("TrayIconHide",1)

Opt("TrayMenuMode",1)

Opt("TrayAutoPause",0)

Opt("TrayOnEventMode",1)

$dir = @ScriptDir

$config = $dir & "\config.cfg"

If Not FileExists($config) Then

_FileCreate($config)

MsgBox(64,"No config file","There was no config file found it will be created")

EndIf

$Form2_1 = GUICreate("Auto internet", 285, 306, 316, 182)

$Button1 = GUICtrlCreateButton("Start Msn", 8, 72, 121, 33, 0)

$Button2 = GUICtrlCreateButton("Stop Msn", 8, 112, 121, 33, 0)

$Button4 = GUICtrlCreateButton("Start Firefox", 136, 72, 121, 33, 0)

$Button5 = GUICtrlCreateButton("Stop Firefox", 136, 112, 121, 33, 0)

$Tijd = GUICtrlCreateInput("", 8, 280, 89, 21, BitOR($ES_AUTOHSCROLL,$ES_READONLY))

$Label1 = GUICtrlCreateLabel("Activeren", 24, 32, 49, 17)

$Button3 = GUICtrlCreateButton("Opslaan", 128, 32, 129, 33, 0)

$msngestart = GUICtrlCreateInput("", 8, 248, 89, 21, BitOR($ES_AUTOHSCROLL,$ES_READONLY))

$internetgestart = GUICtrlCreateInput("", 8, 216, 89, 21, BitOR($ES_AUTOHSCROLL,$ES_READONLY))

$Checkbox1 = GUICtrlCreateCheckbox("", 80, 32, 17, 17)

GUISetOnEvent($GUI_EVENT_CLOSE,"_exit")

GUISetOnEvent($GUI_EVENT_MINIMIZE,"hide")

TraySetOnEvent($TRAY_EVENT_PRIMARYDOWN,"show")

GUISetState(@SW_SHOW)

While 1

GUICtrlSetData($Tijd,@HOUR & ":" & @MIN & ":" & @SEC)

$internet = ProcessExists("firefox.exe")

$msn = ProcessExists("msnmsgr.exe")

If ProcessExists($internet) Then

GUICtrlSetData($internetgestart,"Firefox Aan")

Else

GUICtrlSetData($internetgestart,"Firefox Uit")

EndIf

If ProcessExists($msn) Then

GUICtrlSetData($msngestart,"Msn Aan")

Else

GUICtrlSetData($msngestart,"Msn Uit")

EndIf

$configread = IniRead($config,"Activeren","1","")

$tijd2 = GUICtrlRead($Tijd)

If $configread = "1" Then

If $Tijd2 = "19:00:00" Then

If Not ProcessExists("firefox.exe") Then

Run("firefox.exe","C:\Program Files\Mozilla Firefox\")

EndIf

If Not ProcessExists("msnmsgr.exe") Then

Run("msnmsgr.exe","C:\Program Files\MSN Messenger\")

EndIf

Else

EndIf

Else

EndIf

If $tijd2 = "17:30:00" Then

Msgbox(64,"internet uit","Internet is uit")

Else

EndIf

$msg = GUIGetMsg()

Select

Case $msg = $Button3

$activeren = Guictrlread($Checkbox1)

If $activeren = 1 Then

IniWrite($config,"Activeren","1","1")

Else

IniWrite($config,"Activeren","1","0")

EndIf

Case $msg = $Button1

Msgbox(64,"internet uit","Internet is uit")

EndSelect

Sleep(100)

WEnd

Func _exit()

Exit

EndFunc

Func hide()

Opt ("TrayIconHide",0)

WinSetState("Auto internet","",@SW_HIDE)

EndFunc

Func show()

Opt ("TrayIconHide",1)

WinSetState("Auto internet","",@SW_SHOW)

WinActivate("Auto internet")

EndFunc

Exit

My problem now is the buttons do nothing how to fix it?

I little problem, hard to find and fix

Link to comment
Share on other sites

That's because of Opt("GuiOnEventMode"). If you see in the help file, you'll see that GuiGetMsg won't work if this option is enabled.

Here's a working script:

#include <GUIConstants.au3>
#Include <GuiListView.au3>
#Include <File.au3>
#include <Date.au3>
#include <Array.au3>
#include <Date.au3>
#include <string.au3>
#Include <Constants.au3>

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


$dir = @ScriptDir
$config = $dir & "\config.cfg"

If Not FileExists($config) Then
_FileCreate($config)
MsgBox(64,"No config file","There was no config file found it will be created")
EndIf



$Form2_1 = GUICreate("Auto internet", 285, 306, 316, 182)
$Button1 = GUICtrlCreateButton("Start Msn", 8, 72, 121, 33, 0)
GUICtrlSetOnEvent(-1,"button1")
$Button2 = GUICtrlCreateButton("Stop Msn", 8, 112, 121, 33, 0)
GUICtrlSetOnEvent(-1,"button2")
$Button3 = GUICtrlCreateButton("Opslaan", 128, 32, 129, 33, 0)
GUICtrlSetOnEvent(-1,"button3")
$Button4 = GUICtrlCreateButton("Start Firefox", 136, 72, 121, 33, 0)
GUICtrlSetOnEvent(-1,"button4")
$Button5 = GUICtrlCreateButton("Stop Firefox", 136, 112, 121, 33, 0)
GUICtrlSetOnEvent(-1,"button5")
$Tijd = GUICtrlCreateInput("", 8, 280, 89, 21, BitOR($ES_AUTOHSCROLL,$ES_READONLY))
$Label1 = GUICtrlCreateLabel("Activeren", 24, 32, 49, 17)

$msngestart = GUICtrlCreateInput("", 8, 248, 89, 21, BitOR($ES_AUTOHSCROLL,$ES_READONLY))
$internetgestart = GUICtrlCreateInput("", 8, 216, 89, 21, BitOR($ES_AUTOHSCROLL,$ES_READONLY))
$Checkbox1 = GUICtrlCreateCheckbox("", 80, 32, 17, 17)

GUISetOnEvent($GUI_EVENT_CLOSE,"_exit")
GUISetOnEvent($GUI_EVENT_MINIMIZE,"hide")
TraySetOnEvent($TRAY_EVENT_PRIMARYDOWN,"show")
GUISetState(@SW_SHOW)


While 1

GUICtrlSetData($Tijd,@HOUR & ":" & @MIN & ":" & @SEC)
$internet = ProcessExists("firefox.exe")
$msn = ProcessExists("msnmsgr.exe")
If ProcessExists($internet) Then
GUICtrlSetData($internetgestart,"Firefox Aan")
Else
GUICtrlSetData($internetgestart,"Firefox Uit")
EndIf

If ProcessExists($msn) Then
GUICtrlSetData($msngestart,"Msn Aan")
Else
GUICtrlSetData($msngestart,"Msn Uit")
EndIf

$configread = IniRead($config,"Activeren","1","")
$tijd2 = GUICtrlRead($Tijd)
If $configread = "1" Then
If $Tijd2 = "19:00:00" Then
If Not ProcessExists("firefox.exe") Then
Run("firefox.exe","C:\Program Files\Mozilla Firefox\")

EndIf

If Not ProcessExists("msnmsgr.exe") Then
Run("msnmsgr.exe","C:\Program Files\MSN Messenger\")
EndIf
Else
EndIf
Else
EndIf

If $tijd2 = "17:30:00" Then
Msgbox(64,"internet uit","Internet is uit") 
Else
EndIf
Sleep(100)
WEnd

Func button1()
    Msgbox(64,"internet uit","Internet is uit") 
EndFunc
Func button2()
    Msgbox(64,"","Button2") 
EndFunc
Func button3()
    $activeren = Guictrlread($Checkbox1)
    If $activeren = 1 Then
        IniWrite($config,"Activeren","1","1")
    Else 
        IniWrite($config,"Activeren","1","0")
    EndIf
EndFunc
Func button4()
    Msgbox(64,"","Button4") 
EndFunc
Func button5()
    Msgbox(64,"","Button5") 
EndFunc

Func _exit()
Exit
EndFunc

Func hide()
Opt ("TrayIconHide",0)
WinSetState("Auto internet","",@SW_HIDE)
EndFunc

Func show()
Opt ("TrayIconHide",1)
WinSetState("Auto internet","",@SW_SHOW)
WinActivate("Auto internet")
EndFunc



Exit

I like the OnEvent mode more than checking the message every loop.

Oh, and try to put your codes inside the code tags, it makes it so much easier to read.

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