【问题标题】:Close a msgbox in Autohotkey?在 Autohotkey 中关闭一个 msgbox?
【发布时间】:2020-04-02 22:44:47
【问题描述】:

我有一个 Autohotkey 脚本,它显示一个 msgbox 并且始终位于顶部(拥有这个非常重要)。我希望仅在以下两种情况下关闭 msgbox:

  1. 我自己手动关闭它。
  2. 当特定窗口关闭时,关闭消息框。

这是我目前拥有的代码的主要部分:

    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

我怎样才能做到这一点?

【问题讨论】:

    标签: autohotkey


    【解决方案1】:

    这应该可以工作

    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 线程)。

    【讨论】:

      【解决方案2】:

      您正在通过显示一个 MsgBox 来暂停该线程。只有关闭 MsgBox 后,代码才会继续执行。
      您要么想要制作自己的自定义 gui,就像消息框一样,要么在单独的线程中运行消息框。

      在另一个答案中似乎已经展示了在单独的线程中运行,所以这里创建你自己的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
      }
      

      我使 gui 有点像一个消息框。当然,它可以进一步定制,使其看起来完全像一个消息框,但我认为这不是重点。
      我假设您只是想在屏幕上不断显示一些信息。
      而且,我不会说消息框真的是为此而设计的。

      因此可能值得研究 guis,也会打开许多​​其他可能性。
      例如,也许您想让您的 gui 成为一个实际的半透明点击覆盖,而不是某个带有 OK 按钮的窗口。

      【讨论】:

        猜你喜欢
        • 2019-03-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-03-31
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多