AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Minimize to Tray by Clicking Close Button?
Goto page 1, 2  Next
 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
instantrunoff



Joined: 13 Jan 2008
Posts: 81

PostPosted: Sun Feb 24, 2008 11:39 pm    Post subject: Minimize to Tray by Clicking Close Button? Reply with quote

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
View user's profile Send private message Visit poster's website
willyfoo



Joined: 03 Jun 2007
Posts: 25

PostPosted: Mon Feb 25, 2008 2:49 am    Post subject: Reply with quote

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
View user's profile Send private message
engunneer



Joined: 30 Aug 2005
Posts: 6847
Location: Pacific Northwest, US

PostPosted: Mon Feb 25, 2008 7:13 pm    Post subject: Reply with quote

you may be able to adapt one of these to determine when the mouse is going to click close:

http://www.donationcoder.com/Software/Skrommel/index.html#NoClose
http://www.donationcoder.com/Software/Skrommel/index.html#CloseFence


This one is probably closest to what you want:
http://www.donationcoder.com/Software/Skrommel/index.html#GoneIn60s
_________________
Unless otherwise noted, all code is untested.
Common Answers: 1.(Loops, Viruses, etc.) 2. Search 3.RTFM
Back to top
View user's profile Send private message Visit poster's website
Lexikos



Joined: 17 Oct 2006
Posts: 2737
Location: Australia, Qld

PostPosted: Tue Feb 26, 2008 3:12 am    Post subject: Reply with quote

Use ~LButton in combination with WM_NCHITTEST.
Back to top
View user's profile Send private message
instantrunoff



Joined: 13 Jan 2008
Posts: 81

PostPosted: Tue Feb 26, 2008 3:55 am    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
Lexikos



Joined: 17 Oct 2006
Posts: 2737
Location: Australia, Qld

PostPosted: Tue Feb 26, 2008 4:11 am    Post subject: Reply with quote

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
View user's profile Send private message
instantrunoff



Joined: 13 Jan 2008
Posts: 81

PostPosted: Tue Feb 26, 2008 4:52 am    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
Lexikos



Joined: 17 Oct 2006
Posts: 2737
Location: Australia, Qld

PostPosted: Tue Feb 26, 2008 7:33 am    Post subject: Reply with quote

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
View user's profile Send private message
instantrunoff



Joined: 13 Jan 2008
Posts: 81

PostPosted: Tue Feb 26, 2008 7:43 am    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
instantrunoff



Joined: 13 Jan 2008
Posts: 81

PostPosted: Tue Feb 26, 2008 8:24 am    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
Lexikos



Joined: 17 Oct 2006
Posts: 2737
Location: Australia, Qld

PostPosted: Tue Feb 26, 2008 9:34 am    Post subject: Reply with quote

WinGetTitle does not set the Last Found Window, so you must specify ahk_id %hwnd% for WinHide.
Back to top
View user's profile Send private message
instantrunoff



Joined: 13 Jan 2008
Posts: 81

PostPosted: Tue Feb 26, 2008 5:18 pm    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
instantrunoff



Joined: 13 Jan 2008
Posts: 81

PostPosted: Tue Mar 25, 2008 12:39 am    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
Lexikos



Joined: 17 Oct 2006
Posts: 2737
Location: Australia, Qld

PostPosted: Tue Mar 25, 2008 1:12 am    Post subject: Reply with quote

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
View user's profile Send private message
instantrunoff



Joined: 13 Jan 2008
Posts: 81

PostPosted: Wed Mar 26, 2008 2:15 am    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group