Skip to content

Instantly share code, notes, and snippets.

@nimdahk
Created April 12, 2012 18:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nimdahk/2369691 to your computer and use it in GitHub Desktop.
Save nimdahk/2369691 to your computer and use it in GitHub Desktop.
Provides a MessageBox with a Parent and Timeout. By just me.
#NoEnv
Run, Notepad.exe
WinWaitActive, ahk_exe Notepad.exe
HWND := WinExist()
MsgBox, % MessageBox.Show("Hello world!", 2 + 64, "Notepad", 3000, HWND)
ExitApp
Class MessageBox {
Static ID := {1: "OK", 2: "Cancel", 3: "Abort", 4: "Retry", 5: "Ignore", 6: "Yes", 7: "No"
, 10: "TryAgain", 11: "Continue"}
Static TimerProc := RegisterCallback("MessageBox.TimeOut")
Show(MB_Msg, MB_Options = 0, MB_Title = "", MB_Timeout = 0, MB_Owner = 0) {
This.Title := MB_Title <> "" ? MB_Title : A_ScriptName
This.Text := MB_Msg
If (MB_TimeOut > 0)
TID := DllCall("User32.dll\SetTimer", "Ptr", A_ScriptHwnd, "Ptr", 0, "UInt", MB_TimeOut
, "Ptr", This.TimerProc, "Ptr")
This.TimedOut := False
RC := DllCall("User32.dll\MessageBox", "Ptr", MB_Owner, "Str", This.Text, "Str", This.Title, "UInt", MB_Options)
DllCall("User32.dll\KillTimer", "Ptr", A_ScriptHwnd, "Ptr", TID)
If (This.TimedOut)
Return "TimeOut"
Return This.ID[RC]
}
TimeOut() { ; TimerProc
If (This <> A_ScriptHwnd)
Return ""
SetTitleMatchMode, 3
If WinExist(MessageBox.Title . " ahk_class #32770", MessageBox.Text) {
MessageBox.TimedOut := True
ControlClick, Button1
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment