2016-01-05 36 views
0

我试图创建代码,每次打开记事本时都会显示foo窗口。问题是,如果关闭foo一次,它将不会再显示(当我下次打开记事本时)。目前我使用下面的代码:每次打开记事本窗口时显示GUI

SetTitleMatchMode, 2 
WinWaitActive, Notepad 
Gui, Add, Button, w200 h25 gTest1 , button 1 
Gui, Add, Button, w200 h25 gTest2 , button 2 
Gui, Show,, foo 
Return 

Test1: 
Run test1.ahk 
Return 

Test2: 
Run test2.ahk 
Return 

回答

1
#Persistent 

Gui, Add, Button, w200 h25 gTest1 , button 1 
Gui, Add, Button, w200 h25 gTest2 , button 2 

SetTimer, Show_Gui, 300 
return 

Show_Gui: 
IfWinNotExist, ahk_class Notepad 
{ 
    Gui, cancel 
    return 
} 
; Otherwise: 
SetTimer, Show_Gui, off 
Gui, Show,, foo 
WinWaitClose, ahk_class Notepad 
SetTimer, Show_Gui, on 
Return 

Test1: 
; do sth 
return 

Test2: 
; do sth 
return 

https://autohotkey.com/docs/commands/SetTimer.htm#Examples

+0

谢谢,这工作。 Upvoted并标记为答案。 –

相关问题