关闭 GUI 但在 AHK 中继续脚本

Close GUI but continue script in AHK

我正在尝试关闭图形用户界面但保留脚本 运行ning。这是因为如果用户选择通过点击 esc 或简单地单击右上角的 'X' 来退出 GUI,我想执行其他操作。我不明白如何离开脚本 运行ning 但关闭 gui。单击 esc 或 X 时,GUI 关闭似乎没有执行任何操作。我已经浏览了 GUI 文档,但无法弄清楚。他们总是运行退出应用程序,但我还没准备好退出应用程序,我需要做其他事情。

Gui, Add, Text, ,To cancel, press ESCAPE or close this window.

Gui, Show, w320 h80, Downloads

GuiClose:
GuiEscape:
; Continue on to do other things here!!!!
WinActivate ahk_exe notepad++.exe
; do things...
exitapp

他们在文档中假设通过单击 x,您希望脚本关闭。
所以他们以 ExitApp 为例。

如果你不想那么做,当然没有必要。
我想你想要的是 destroying gui:

GuiClose:
GuiEscape:
    Gui, Destroy
return

你所描述的听起来也像我想做的。这是大量的艰苦努力和零敲碎打,但我认为你正在寻找的是 Gui, Cancel 看看下面的代码,看看它是否能解决你的问题。

它不使用 ExitApp,如果您想稍后弹出它,它也不会破坏 window。您必须弄清楚如何放置其余代码,但我相信这就是您要问的。

;Set the GUI window
Gui, Add, Text,, Hit Escape to Clear window when it is active

#F9:: ;show the window with WindowsKey-F9 
Gui, Show, 
return

;set the escape key to clear GUI window
GuiEscape: ; Note: single colon here, not double
Gui, Cancel
Return

如果您有多个 GUI windows,那就有点棘手了。您必须为每个人命名:

;Set the two GUI windows. In example, First is labeled as FirstGUI and second as SecondGUI. Notice how you separate with single colon.
Gui, FirstGUI:Add, Text,, Hit Escape to Clear FirstGUI window when it is active
Gui, SecondGUI:Add, Text,, Hit Escape to Clear SecondGUI window when it is active

#F9:: ;show the two windows ("xCenter y700" is used to prevent the windows from stacking.)
Gui, FirstGUI:Show, xCenter y700, Window Title of First GUI
Gui, SecondGUI:Show, xCenter y900, Window Title of Second GUI
return

;set the escape key to clear for each Gui independently. 

FirstGUIGuiEscape: ; Note that you must add the Gui Name (FirstGUI) to the beginning of the "GuiEscape:" command and also name it in the following:
Gui, FirstGUI:Cancel
Return

SecondGUIGuiEscape: ; And here you must add SecondGUI as noted above.
Gui, SecondGUI:Cancel
Return

回答有点晚了,但希望这对您或其他人有用!