slishnevsky wrote:You didn't understand.
No, I gave you exactly what you asked for.
slishnevsky wrote:
I would like to reuse this window, just replace the text that appears in the window.
Which is what my code does. It only creates one instance of the GUI before you ever call your function. Calling the function only shows the GUI with the text you pass to the
message argument, for the amount of time you pass (in seconds) to the
stay argument. If you leave
stay blank, the GUI will show for a default of 1 second. The timer is passed a negative value so that it is only called once per call of the function.
You can see by the following modification, I call the function in a loop 10 times, giving
stay a value of 5 seconds. However, it sleeps for only 1 second before calling it again. The new text is displayed in the SAME GUI and the timer is reset. It only disappears after the last call and the timer actually runs out at 5 seconds.
Code: Select all
#Requires AutoHotkey v2.0+
MyGui := Gui('-ToolWindow +Border -Caption +AlwaysOnTop')
MyGui.BackColor := '007ACC'
MyGui.SetFont('s30 cWhite', 'Roboto')
MyText := MyGui.Add('text','Center', ' ') ;spaces to accommodate your largest message
Return
F8::
{
Loop 10 {
ShowMessageBox('This is test ' A_Index,5)
Sleep(1000)
}
}
f10::Exitapp
ShowMessageBox(message, stay := 0) {
MyText.Value := message
MyGui.Show()
SetTimer(() => MyGui.Hide(), stay = 0 ? -1000 : stay * -1000)
}
Russ