2016-02-02 49 views
0

我使用本地应用程序,当按ESCAPE时,当前窗口关闭。我想避免这种情况,所以我使用AutoHotKey创建了一个脚本,用于检测应用程序中窗口的名称,如果按ESCAPE,窗口不会关闭(除非按下X)。AutoHotKey:在窗口事件(关闭)上运行代码

#IfWinActive ahk_class name_of_app_class_here

Escape::return

现在我想申请时关闭该窗口的代码(按X),但我cuoldn't找到,在任何解决方案论坛或在帮助。 实施例:

#IfWinActive ahk_class name_of_app_class_here

OnWindowClose

`Do_something` 

希望是很好的解释。 谢谢!

回答

0

下面的代码应该做你想要达到的目标:

;tested on Notepad (Windows 7) 
;note: may not work correctly if aero mode is on 
;note: if you click a Notepad window that is *not* the active window, it will be closed 
;note: some programs don't return the standard NCHITTEST value for a close button, 
;a workaround is to compare the cursor position against the window coordinates 

#IfWinActive, ahk_class Notepad 
LButton:: 
WinGet, hWnd, ID, A 
WinGetClass, vWinClass, ahk_id %hWnd% 
if vWinClass not in Notepad 
Return 

CoordMode, Mouse, Screen 
MouseGetPos, vPosX, vPosY, hWnd2 

if (hWnd = hWnd2) 
{ 
SendMessage, 0x84, 0, vPosX|(vPosY<<16), , ahk_id %hWnd% ;WM_NCHITTEST 
vNCHITTEST := ErrorLevel ;(8 min, 9 max, 20 close) 

if (vNCHITTEST = 20) 
{ 
MsgBox can't close me! ;put your code here 
Return 
} 
} 

SendInput {LButton Down} 
KeyWait, LButton 
SendInput {LButton Up} 
Return 
#IfWinActive 

注: 张贴在下面的链接的代码,实现了一些相关的,醒目关闭按钮所有窗口,而不仅仅是一个程序,无论它们是活动的还是非活动的。

Is it possible to catch the close button and minimize the window instead? AutoHotKey