在 Autohotkey 中关闭一个消息框?
Close a msgbox in Autohotkey?
我有一个 Autohotkey 脚本,它显示一个消息框并且总是在最前面(拥有这个非常重要)。我希望仅在这两种情况下关闭 msgbox:
- 我自己手动关闭了
- 当特定的 window 关闭时,则关闭 msgbox。
这是我目前拥有的代码的主要部分:
msgbox,262144,TimesheetBlah,% list "`n" "`n" list2
clipboard := listCopy
WinActivate,Manage: Time Entry
WinShow, Manage: Time Entry
WinWait, Manage: Time Entry
WinWaitClose ; Wait for the exact window found by WinWait to be closed.
ControlClick, Button1, TimesheetBlah // This should close the msgbox, but it doesn't
if WinExist("*TimesheetBlah*"){
WinClose ; use the window found above // This doesn't close the msgbox either
我怎样才能做到这一点?
这应该有效
WinShow, Manage: Time Entry
WinWait, Manage: Time Entry
WinActivate,Manage: Time Entry
SetTimer, CloseMsgBox, -1000 ; run only once
msgbox,262144,TimesheetBlah,% list "`n" "`n" list2
CloseMsgBox:
WinWaitClose, Manage: Time Entry
WinClose, TimesheetBlah ahk_class #32770
Return
因为 a timer's thread can interrupt other threads(在本例中是 msgbox 线程)。
您正在通过显示 MsgBox 来暂停该线程。只有关闭 MsgBox 后,代码才会继续执行。
您要么想要制作自己的自定义图形用户界面,就像一个消息框,要么 运行 单独线程中的消息框。
运行 在一个单独的线程中似乎已经在另一个答案中展示了,所以这里是创建你自己的 GUI:
Gui, +AlwaysOnTop +ToolWindow ;see docs for description of options
Gui, Add, Text, y20, Hi!
Gui, Add, Button, x96 y63 w75 h23 gGuiClose, OK ;go-label
Gui, Show, Center w181 h91, NiceTitleForOurMsgBox
WinActivate, Untitled - Notepad
WinShow ;can use the last found window, though this command is doing nothing for us(?)
WinWait, Untitled - Notepad
WinWaitClose, Untitled - Notepad
WinClose, NiceTitleForOurMsgBox
;Sure, we could also control click, but lets not.
;ControlClick, Button1, NiceTitleForOurMsgBox
Return
;runs automatically when the gui is closed,
;or also runs from the OK button (via g-label)
GuiClose()
{
ExitApp
}
我把图形用户界面做得有点像消息框。当然,它可以进一步自定义,使其看起来完全像一个消息框,但我认为这不是重点。
我假设您只是想不断地在屏幕上显示一些信息。
老实说,我不会说消息框真的是为此而设计的。
因此可能值得研究 guis,也会打开很多其他可能性。
例如,您可能想让您的图形用户界面成为一个实际的半透明点击覆盖层,而不是一些带有确定按钮的 window。
我有一个 Autohotkey 脚本,它显示一个消息框并且总是在最前面(拥有这个非常重要)。我希望仅在这两种情况下关闭 msgbox:
- 我自己手动关闭了
- 当特定的 window 关闭时,则关闭 msgbox。
这是我目前拥有的代码的主要部分:
msgbox,262144,TimesheetBlah,% list "`n" "`n" list2
clipboard := listCopy
WinActivate,Manage: Time Entry
WinShow, Manage: Time Entry
WinWait, Manage: Time Entry
WinWaitClose ; Wait for the exact window found by WinWait to be closed.
ControlClick, Button1, TimesheetBlah // This should close the msgbox, but it doesn't
if WinExist("*TimesheetBlah*"){
WinClose ; use the window found above // This doesn't close the msgbox either
我怎样才能做到这一点?
这应该有效
WinShow, Manage: Time Entry
WinWait, Manage: Time Entry
WinActivate,Manage: Time Entry
SetTimer, CloseMsgBox, -1000 ; run only once
msgbox,262144,TimesheetBlah,% list "`n" "`n" list2
CloseMsgBox:
WinWaitClose, Manage: Time Entry
WinClose, TimesheetBlah ahk_class #32770
Return
因为 a timer's thread can interrupt other threads(在本例中是 msgbox 线程)。
您正在通过显示 MsgBox 来暂停该线程。只有关闭 MsgBox 后,代码才会继续执行。
您要么想要制作自己的自定义图形用户界面,就像一个消息框,要么 运行 单独线程中的消息框。
运行 在一个单独的线程中似乎已经在另一个答案中展示了,所以这里是创建你自己的 GUI:
Gui, +AlwaysOnTop +ToolWindow ;see docs for description of options
Gui, Add, Text, y20, Hi!
Gui, Add, Button, x96 y63 w75 h23 gGuiClose, OK ;go-label
Gui, Show, Center w181 h91, NiceTitleForOurMsgBox
WinActivate, Untitled - Notepad
WinShow ;can use the last found window, though this command is doing nothing for us(?)
WinWait, Untitled - Notepad
WinWaitClose, Untitled - Notepad
WinClose, NiceTitleForOurMsgBox
;Sure, we could also control click, but lets not.
;ControlClick, Button1, NiceTitleForOurMsgBox
Return
;runs automatically when the gui is closed,
;or also runs from the OK button (via g-label)
GuiClose()
{
ExitApp
}
我把图形用户界面做得有点像消息框。当然,它可以进一步自定义,使其看起来完全像一个消息框,但我认为这不是重点。
我假设您只是想不断地在屏幕上显示一些信息。
老实说,我不会说消息框真的是为此而设计的。
因此可能值得研究 guis,也会打开很多其他可能性。
例如,您可能想让您的图形用户界面成为一个实际的半透明点击覆盖层,而不是一些带有确定按钮的 window。