 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
Solar Guest
|
Posted: Sat Sep 06, 2008 6:53 pm Post subject: Simple minimize to tray |
|
|
The easiest way to minimize your gui to the system tray?
| Code: |
OnMessage(0x112, "WM_SYSCOMMAND")
Return
WM_SYSCOMMAND(wParam)
{
If wParam = 61472
{
Gui, Destroy
If A_IconHidden = 0 ; NoTrayIcon
Menu, Tray, Icon
}
}
|
|
|
| Back to top |
|
 |
Solar Guest
|
Posted: Sat Sep 06, 2008 7:12 pm Post subject: |
|
|
| Gui, Cancel would probably be a better choice now that I think about it. |
|
| Back to top |
|
 |
Solar Guest
|
Posted: Sat Sep 06, 2008 7:24 pm Post subject: |
|
|
Ok, now the working code:
| Code: |
WM_SYSCOMMAND(wParam)
{
If wParam = 61472
{
Gui, Hide
If A_IconHidden = 1 ; NoTrayIcon
Menu, Tray, Icon
}
}
|
|
|
| Back to top |
|
 |
WhoAmIAgain Guest
|
Posted: Sun Nov 30, 2008 10:38 am Post subject: |
|
|
I use:
| Code: |
Menu, Tray, Add, Toggle Window, GuiToggle
Menu, Tray, Default, Toggle Window
;...
Gui, show, w600 h400,.
;...
Main_Window := WinExist("A")
GuiToggle:
IfWinExist, ahk_id %Main_Window%
Gui, Hide
else
Gui, Show
return |
The minimize button can minimize it to tray and a dbl click of the tray icon will restore it if it's hidden or restore it if it's not. |
|
| Back to top |
|
 |
DHMH
Joined: 17 Jul 2008 Posts: 225
|
Posted: Sun Nov 30, 2008 11:07 am Post subject: |
|
|
Wow!
good script!
Example: (with small gui )
| Code: | #Notrayicon
#SingleInstance, Force
Gui, show, w120 h20
OnMessage(0x112, "WM_SYSCOMMAND")
Return
guiclose:
exitapp
WM_SYSCOMMAND(wParam)
{
If wParam = 61472
{
Gui, Hide
If A_IconHidden = 1 ; NoTrayIcon
Menu, Tray, Icon
}
} |
Thx for the function!
Greets,
DHMH |
|
| Back to top |
|
 |
SKAN
Joined: 26 Dec 2005 Posts: 8688
|
Posted: Sun Nov 30, 2008 7:56 pm Post subject: |
|
|
Thanks..
| Code: | #NoTrayIcon ; MinimizeGUItoTray() by Skan -- created 18-Aug-2008
; www.autohotkey.com/forum/viewtopic.php?p=214612#214612
Menu("Tray","Nostandard"), Menu("Tray","Add","Restore","GuiShow"), Menu("Tray","Add")
Menu("Tray","Default","Restore"), Menu("Tray","Click",1), Menu("Tray","Standard")
Menu("Tray","Icon","User32.dll",4)
Gui +LastFound +Owner
Gui1 := WinExist()
OnMessage(0x112, "WM_SYSCOMMAND")
Gui, Show, w250 h100, Minimize/Restore to/from Tray - Demo
Return ; // end of auto-execute section //
WM_SYSCOMMAND(wParam)
{
If ( wParam = 61472 ) {
SetTimer, OnMinimizeButton, -1
Return 0
}
}
GuiClose:
ExitApp
Return
OnMinimizeButton:
MinimizeGuiToTray( R, Gui1 )
Menu("Tray","Icon")
Return
GuiShow:
DllCall("DrawAnimatedRects", UInt,Gui1, Int,3, UInt,&R+16, UInt,&R )
Menu("Tray","NoIcon")
Gui, Show
Return
MinimizeGuiToTray( ByRef R, hGui ) {
WinGetPos, X0,Y0,W0,H0, % "ahk_id " (Tray:=WinExist("ahk_class Shell_TrayWnd"))
ControlGetPos, X1,Y1,W1,H1, TrayNotifyWnd1,ahk_id %Tray%
SW:=A_ScreenWidth,SH:=A_ScreenHeight,X:=SW-W1,Y:=SH-H1,P:=((Y0>(SH/3))?("B"):(X0>(SW/3))
? ("R"):((X0<(SW/3))&&(H0<(SH/3)))?("T"):("L")),((P="L")?(X:=X1+W0):(P="T")?(Y:=Y1+H0):)
VarSetCapacity(R,32,0), DllCall( "GetWindowRect",UInt,hGui,UInt,&R)
NumPut(X,R,16), NumPut(Y,R,20), DllCall("RtlMoveMemory",UInt,&R+24,UInt,&R+16,UInt,8 )
DllCall("DrawAnimatedRects", UInt,hGui, Int,3, UInt,&R, UInt,&R+16 )
WinHide, ahk_id %hGui%
}
Menu( MenuName, Cmd, P3="", P4="", P5="" ) {
Menu, %MenuName%, %Cmd%, %P3%, %P4%, %P5%
Return errorLevel
} |
|
|
| Back to top |
|
 |
Big Digger
Joined: 07 Feb 2009 Posts: 43
|
Posted: Sat Jun 06, 2009 5:49 pm Post subject: |
|
|
| Code: | Menu, Tray, Add, Show, GuiShow
Menu, Tray, Default, Show
Menu, Tray, Click, 1
Gui, Add, Text, , Minimize Gui to tray…
Gui, Show
Return
GuiShow:
Gui, Show
Return
GuiSize:
If A_EventInfo = 1
Gui, Show, Hide
Return
GuiClose:
ExitApp |
|
|
| Back to top |
|
 |
Solar
Joined: 03 May 2009 Posts: 345 Location: OH, USA
|
Posted: Sat Jun 06, 2009 6:57 pm Post subject: |
|
|
Big Digger, that won't work because the window can be restored by means other than the tray. For example, double click the window on the taskbar and see what happens. As resize and restore are both sent as the same A_EventInfo, unless you mind the extra Gui, Show commands, don't use that method.
SKAN pointed out that a timer should be used. Here's an updated example that works well:
| Code: | #NoTrayIcon
Menu, Tray, Click, 1
Menu, Tray, Add, Restore, Restore
Menu, Tray, Default, Restore
OnMessage(0x112, "WM_SYSCOMMAND")
Gui, Show, w200 h100, Minimize to Tray
Return
WM_SYSCOMMAND(wParam)
{
If (wParam = 61472) ; minimize
SetTimer, Minimize, -1
Else If (wParam = 61728) ; restore
SetTimer, Restore, -1
}
Minimize:
Critical
Gui, Hide
Menu, Tray, Icon
Return
Restore:
Critical
Menu, Tray, NoIcon
Gui, Show
Return
GuiEscape:
GuiClose:
ExitApp |
Edit: Added Critical to both labels so that they cannot be interrupted by each other causing the tray icon to display improperly. |
|
| Back to top |
|
 |
hughman
Joined: 11 Feb 2007 Posts: 166
|
Posted: Sat Jul 18, 2009 4:36 am Post subject: |
|
|
| It's truely simple and effective, thanks, Solar, good job. |
|
| Back to top |
|
 |
Delusion
Joined: 16 Jul 2008 Posts: 210 Location: Greece/Rhodos
|
Posted: Sun Sep 20, 2009 6:38 pm Post subject: |
|
|
| SKAN wrote: | Thanks..
| Code: | #NoTrayIcon ; MinimizeGUItoTray() by Skan -- created 18-Aug-2008
; www.autohotkey.com/forum/viewtopic.php?p=214612#214612
Menu("Tray","Nostandard"), Menu("Tray","Add","Restore","GuiShow"), Menu("Tray","Add")
Menu("Tray","Default","Restore"), Menu("Tray","Click",1), Menu("Tray","Standard")
Menu("Tray","Icon","User32.dll",4)
Gui +LastFound +Owner
Gui1 := WinExist()
OnMessage(0x112, "WM_SYSCOMMAND")
Gui, Show, w250 h100, Minimize/Restore to/from Tray - Demo
Return ; // end of auto-execute section //
WM_SYSCOMMAND(wParam)
{
If ( wParam = 61472 ) {
SetTimer, OnMinimizeButton, -1
Return 0
}
}
GuiClose:
ExitApp
Return
OnMinimizeButton:
MinimizeGuiToTray( R, Gui1 )
Menu("Tray","Icon")
Return
GuiShow:
DllCall("DrawAnimatedRects", UInt,Gui1, Int,3, UInt,&R+16, UInt,&R )
Menu("Tray","NoIcon")
Gui, Show
Return
MinimizeGuiToTray( ByRef R, hGui ) {
WinGetPos, X0,Y0,W0,H0, % "ahk_id " (Tray:=WinExist("ahk_class Shell_TrayWnd"))
ControlGetPos, X1,Y1,W1,H1, TrayNotifyWnd1,ahk_id %Tray%
SW:=A_ScreenWidth,SH:=A_ScreenHeight,X:=SW-W1,Y:=SH-H1,P:=((Y0>(SH/3))?("B"):(X0>(SW/3))
? ("R"):((X0<(SW/3))&&(H0<(SH/3)))?("T"):("L")),((P="L")?(X:=X1+W0):(P="T")?(Y:=Y1+H0):)
VarSetCapacity(R,32,0), DllCall( "GetWindowRect",UInt,hGui,UInt,&R)
NumPut(X,R,16), NumPut(Y,R,20), DllCall("RtlMoveMemory",UInt,&R+24,UInt,&R+16,UInt,8 )
DllCall("DrawAnimatedRects", UInt,hGui, Int,3, UInt,&R, UInt,&R+16 )
WinHide, ahk_id %hGui%
}
Menu( MenuName, Cmd, P3="", P4="", P5="" ) {
Menu, %MenuName%, %Cmd%, %P3%, %P4%, %P5%
Return errorLevel
} |
|
thats great
but that animation doesnt seem to work on vista (i got vista ultimate x64 sp2) .is there any way to make it work?
thanks in advance  _________________ Popcorn Movie Db
Simple Apnea Trainer |
|
| Back to top |
|
 |
antihack
Joined: 03 Nov 2009 Posts: 10
|
Posted: Sun Nov 08, 2009 1:59 pm Post subject: |
|
|
| WhoAmIAgain wrote: | I use:
| Code: |
Menu, Tray, Add, Toggle Window, GuiToggle
Menu, Tray, Default, Toggle Window
;...
Gui, show, w600 h400,.
;...
Main_Window := WinExist("A")
GuiToggle:
IfWinExist, ahk_id %Main_Window%
Gui, Hide
else
Gui, Show
return |
The minimize button can minimize it to tray and a dbl click of the tray icon will restore it if it's hidden or restore it if it's not. |
Hello!
This script works, but only if you double click the tray icon.
How to make application go to tray by clicking that minimize button in top right corner of GUI. _________________ Follow your dreams! |
|
| Back to top |
|
 |
guest3456 Guest
|
Posted: Sun Mar 28, 2010 5:41 am Post subject: |
|
|
| can someone explain why a Timer is used? |
|
| Back to top |
|
 |
SKAN
Joined: 26 Dec 2005 Posts: 8688
|
Posted: Sun Mar 28, 2010 1:26 pm Post subject: |
|
|
| guest3456 wrote: | | can someone explain why a Timer is used? |
| Code: | WM_SYSCOMMAND(wParam)
{
If ( wParam = 61472 ) {
SetTimer, OnMinimizeButton, -1
Return 0
}
} |
OnMessage functions need to return a true or false within the shortest possible time.
GoSub would halt the function from returning a value until the subroutine itself returns.
SetTimer, SubRoutine, -1 does not halt the OnMessage function from returning, and at the same time the subroutine gets triggered within 1 millisecond making the code "all safe". |
|
| Back to top |
|
 |
TheGood
Joined: 30 Jul 2007 Posts: 580
|
Posted: Sun Mar 28, 2010 3:45 pm Post subject: |
|
|
| SKAN wrote: | OnMessage functions need to return a true or false within the shortest possible time.
GoSub would halt the function from returning a value until the subroutine itself returns.
SetTimer, SubRoutine, -1 does not halt the OnMessage function from returning, and at the same time the subroutine gets triggered within 1 millisecond making the code "all safe". |
Just to clarify, that's only necessary if the message is less than 0x312 (like WM_SYSCOMMAND here). If the message is greater than that, you could use Critical to buffer the messages and not having to worry about returning a value ASAP. |
|
| Back to top |
|
 |
guest3456 Guest
|
Posted: Sun Mar 28, 2010 5:00 pm Post subject: |
|
|
thanks guys, i was just curious. i don't really understand it, and the docs confuse me as well.  |
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|