 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
instantrunoff
Joined: 13 Jan 2008 Posts: 81
|
Posted: Sun Feb 24, 2008 11:39 pm Post subject: Minimize to Tray by Clicking Close Button? |
|
|
| Sorry I couldn't figure out the answer by searching, but I'm sure there must be a solution: Is there a way to minimize a specific window to the tray when its Close button is clicked (rather than or in addition to clicking the minimize button)? Thanks! |
|
| Back to top |
|
 |
willyfoo
Joined: 03 Jun 2007 Posts: 25
|
Posted: Mon Feb 25, 2008 2:49 am Post subject: |
|
|
Perhaps a way to get around it is to hide the original minimize, restore, close button and put your own set to control what happens. _________________ http://willyfoo.com
http://livestudios.sg |
|
| Back to top |
|
 |
engunneer
Joined: 30 Aug 2005 Posts: 6847 Location: Pacific Northwest, US
|
|
| Back to top |
|
 |
Lexikos
Joined: 17 Oct 2006 Posts: 2737 Location: Australia, Qld
|
Posted: Tue Feb 26, 2008 3:12 am Post subject: |
|
|
| Use ~LButton in combination with WM_NCHITTEST. |
|
| Back to top |
|
 |
instantrunoff
Joined: 13 Jan 2008 Posts: 81
|
Posted: Tue Feb 26, 2008 3:55 am Post subject: |
|
|
| lexiKos wrote: | | Use ~LButton in combination with WM_NCHITTEST. |
That's perfect, thanks! I didn't quite understand what to do at first, but I copied the code into my script and used the #IfWinActive directive as follows:
If IsOverCloseButton
LButton::WinHide A
BTW, the tilde (~LButton) would also close the window, because the left button click onto the close button was not intercepted. |
|
| Back to top |
|
 |
Lexikos
Joined: 17 Oct 2006 Posts: 2737 Location: Australia, Qld
|
Posted: Tue Feb 26, 2008 4:11 am Post subject: |
|
|
| instantrunoff wrote: | I didn't quite understand what to do at first, but I copied the code into my script and used the #IfWinActive directive as follows:
If IsOverCloseButton
LButton::WinHide A | I don't see how that could work. Hotkeys cannot be "conditionally executed" with If. LButton:: not a command - it is merely a label that is automatically associated with left-click when the script starts. Moreover, "If IsOverCloseButton" is not a function call; it checks whether the variable "IsOverCloseButton" is non-zero and non-empty.
| Quote: | | BTW, the tilde (~LButton) would also close the window, because the left button click onto the close button was not intercepted. | The window closes when you release the button, but not if you hide it first; at least on Vista. Unfortunately WM_NCHITTEST gives inaccurate results when Aero is enabled.
| Code: | #IfWinActive AutoHotkey Command Console .ahk
~LButton::
CoordMode, Mouse, Screen
MouseGetPos, x, y, hwnd
if IsOverCloseButton(x, y, hwnd)
{
WinHide
}
return
IsOverCloseButton(x, y, hWnd)
{
SendMessage, 0x84,, (x & 0xFFFF) | (y & 0xFFFF) << 16,, ahk_id %hWnd%
return (ErrorLevel == 20)
} | or | Code: | #IfWinActive AutoHotkey Command Console .ahk
LButton::
CoordMode, Mouse, Screen
MouseGetPos, x, y, hwnd
if IsOverCloseButton(x, y, hwnd)
{
WinHide
}
else
{
Send {LButton Down}
KeyWait, LButton
Send {LButton Up}
}
return
IsOverCloseButton(x, y, hWnd)
{
SendMessage, 0x84,, (x & 0xFFFF) | (y & 0xFFFF) << 16,, ahk_id %hWnd%
return (ErrorLevel == 20)
} |
|
|
| Back to top |
|
 |
instantrunoff
Joined: 13 Jan 2008 Posts: 81
|
Posted: Tue Feb 26, 2008 4:52 am Post subject: |
|
|
Thanks, I got it working.. I had a problem in that my escape character was | because I use ` as a shortcut to close the active window. I changed the escape character to @, so the | in your code would work, and it does! Thanks again!
Last edited by instantrunoff on Tue Feb 26, 2008 7:34 am; edited 1 time in total |
|
| Back to top |
|
 |
Lexikos
Joined: 17 Oct 2006 Posts: 2737 Location: Australia, Qld
|
Posted: Tue Feb 26, 2008 7:33 am Post subject: |
|
|
| Try it on a different window. The code works fine for me on Vista, and I see no reason for it to not work on other versions of Windows. |
|
| Back to top |
|
 |
instantrunoff
Joined: 13 Jan 2008 Posts: 81
|
Posted: Tue Feb 26, 2008 7:43 am Post subject: |
|
|
| It works very nicely now, but is there a way for the LButton to have this behavior if the mouse cursor is over a specific window's close button and that window is inactive? |
|
| Back to top |
|
 |
instantrunoff
Joined: 13 Jan 2008 Posts: 81
|
Posted: Tue Feb 26, 2008 8:24 am Post subject: |
|
|
I feel like I'm pretty close with this, but it's not working:
| Code: | #IfWinActive Google Calendar
`::WinHide A
#IfWinActive
~LButton::
CoordMode, Mouse, Screen
MouseGetPos, x, y, hwnd
WinGetTitle, title, ahk_id %hWnd%
IfInString, title, Google Calendar
{
If IsOverCloseButton(x, y, hwnd)
{
WinHide
}
}
return
IsOverCloseButton(x, y, hWnd)
{
SendMessage, 0x84,, (x & 0xFFFF) | (y & 0xFFFF) << 16,, ahk_id %hWnd%
return (ErrorLevel == 20)
} |
What am I missing? Thanks as always, really. |
|
| Back to top |
|
 |
Lexikos
Joined: 17 Oct 2006 Posts: 2737 Location: Australia, Qld
|
Posted: Tue Feb 26, 2008 9:34 am Post subject: |
|
|
| WinGetTitle does not set the Last Found Window, so you must specify ahk_id %hwnd% for WinHide. |
|
| Back to top |
|
 |
instantrunoff
Joined: 13 Jan 2008 Posts: 81
|
Posted: Tue Feb 26, 2008 5:18 pm Post subject: |
|
|
Thanks again! It took some tweaking to make the left mouse button work correctly everywhere but over the close button of the Google Calendar window, but this seems to work:
| Code: | LButton::
CoordMode, Mouse, Screen
MouseGetPos, x, y, hwnd
WinGetTitle, title, ahk_id %hWnd%
IfInString, title, Google Calendar
{
If IsOverCloseButton(x, y, hwnd)
{
WinHide ahk_id %hWnd%
}
else
{
Send {LButton Down}
KeyWait, LButton
Send {LButton Up}
}
}
else
{
Send {LButton Down}
KeyWait, LButton
Send {LButton Up}
}
return
IsOverCloseButton(x, y, hWnd)
{
SendMessage, 0x84,, (x & 0xFFFF) | (y & 0xFFFF) << 16,, ahk_id %hWnd%
return (ErrorLevel == 20)
} |
|
|
| Back to top |
|
 |
instantrunoff
Joined: 13 Jan 2008 Posts: 81
|
Posted: Tue Mar 25, 2008 12:39 am Post subject: |
|
|
| Lexikos wrote: | | Unfortunately WM_NCHITTEST gives inaccurate results when Aero is enabled. |
I now have Vista, Aero, and problems getting this to work still. Is there a workaround for the inaccuracy of WM_NCHITTEST with Aero? |
|
| Back to top |
|
 |
Lexikos
Joined: 17 Oct 2006 Posts: 2737 Location: Australia, Qld
|
Posted: Tue Mar 25, 2008 1:12 am Post subject: |
|
|
| I suppose you could check the mouse position against hard-coded co-ordinates and/or use ImageSearch to compare (part of) the button to an image of the button highlighted. |
|
| Back to top |
|
 |
instantrunoff
Joined: 13 Jan 2008 Posts: 81
|
Posted: Wed Mar 26, 2008 2:15 am Post subject: |
|
|
I had problems with both WM_NCHITTEST inaccuracy under Aero and with weird mouse issues. I used MsgBox %ErrorLevel% to find out what replies WM_NCHITTEST gives for my Aero close button, and I got (in addition to 20, which is the documented close button code) 9, 12, and 14. I rewrote this part of my script with some success so that on this particular window, it is hidden instead of closed when the close button is clicked.
| Code: | LButton:: ; Hide Google Calendar instead of close when close button is clicked
CoordMode, Mouse, Screen
MouseGetPos, x, y, hwnd
WinGetTitle, title, ahk_id %hWnd%
IfInString, title, Google Calendar - Mozilla Firefox
{
SendMessage, 0x84,, (x & 0xFFFF) | (y & 0xFFFF) << 16,, ahk_id %hWnd%
If ErrorLevel in 9,12,14,20 ; 20 is for Close box but Vista/Aero bug in WM_NCHITTEST
WinHide ahk_id %hWnd%
else
Click down
}
else
Click down
return
LButton Up::Click Up |
|
|
| 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
|