Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

display a MsgBox without pausing the script



  • Please log in to reply
11 replies to this topic
Xao
  • Members
  • 7 posts
  • Last active:
  • Joined: 23 Jan 2013

when you use the MsgBox command it will not execute the next lines until you press the OK button.

is there a way to make my scrtips continue without the need to press the OK button?

 

a simple example:

 

MsgBox, starting...

Run, run.bat, , Hide

 

of course, in this simple case I could just display the MsgBox after the Run command,

but there are cases in which I would like to display a message box without interrupting the script



GodlyCheese
  • Members
  • 719 posts
  • Last active: Nov 11 2014 07:12 PM
  • Joined: 30 Aug 2012
✓  Best Answer

Make your own MsgBox using the GUI commands and it won't default to stopping your thread; the whole "Not run until OK/Cancel/Close" thing is written into the MsgBox command, I don't think there's a way around it. Here's all you need:

Gui, Add, Text, ,I am a msgbox that will not stop your current thread.
Gui, Add, Button, gGUIClose, Ok
Gui, Show, Center, Msgbox
Tooltip, Script is still running
Sleep 20000
Tooltip,
Return

GUIClose:
Gui, Destroy
Return


Jack Dunning
  • Members
  • 217 posts
  • Last active: Nov 11 2015 08:40 PM
  • Joined: 08 Apr 2013

If you just want to display a message without the need to hit a button to continue or close the box, then you could use SplashTextOn.

Run notepad.exe
SplashTextOn ,200 ,200 , Splash, This is a test
Sleep 2000
Run notepad.exe
SplashTextOff

I currently do a regular blog for AutoHotkey beginners and have posted a number of AutoHotkey help pages at ComputorEdge.com. As I learn, I pass it on.

 

AutoHotkey scripts and apps for beginners and more ideas.


Rijul Ahuja
  • Members
  • 763 posts
  • Last active: Nov 25 2013 10:16 AM
  • Joined: 14 Mar 2012

How about ToolTip? It works similar to above mentioned SplashText. You can display tiny text while the program executes.


Abandon the forum. The community has decided in a democratic vote to leave this website because of inactive and perverse administration.

Very few of the contributing members remain here.


BrandonHotkey
  • Members
  • 691 posts
  • Last active: Oct 21 2015 09:41 PM
  • Joined: 21 May 2012

You could create gui window in which you will type the text.



Guest10
  • Members
  • 1216 posts
  • Last active: Oct 30 2015 05:12 PM
  • Joined: 27 Oct 2012

thanks! this is a great, useful script.

 

Make your own MsgBox using the GUI commands and it won't default to stopping your thread; the whole "Not run until OK/Cancel/Close" thing is written into the MsgBox command, I don't think there's a way around it. Here's all you need:

Gui, Add, Text, ,I am a msgbox that will not stop your current thread.
Gui, Add, Button, gGUIClose, Ok
Gui, Show, Center, Msgbox
Tooltip, Script is still running
Sleep 20000
Tooltip,
Return

GUIClose:
Gui, Destroy
Return


Dave-
  • Members
  • 46 posts
  • Last active: May 17 2013 04:57 PM
  • Joined: 30 Nov 2010

you can also use settimer to run the messagebox in a separate thread

SetTimer, showmessage, -10
;program code continues execution
return

showmessage:
    msgbox, I am a msgbox that will not stop your current thread.
return


Guest10
  • Members
  • 1216 posts
  • Last active: Oct 30 2015 05:12 PM
  • Joined: 27 Oct 2012

i wonder why return is (always) required with SetTimer?

SetTimer, showmessage, -10
;program code continues execution
return

 

 

you can also use settimer to run the messagebox in a separate thread

SetTimer, showmessage, -10
;program code continues execution
return

showmessage:
    msgbox, I am a msgbox that will not stop your current thread.
return


robert_ilbrink
  • Members
  • 561 posts
  • Last active: Mar 10 2015 08:36 PM
  • Joined: 05 May 2012

Otherwise the code will continue with executing the showmessage: code UNTIL it hits a Return there. and your'e not fast enough to close the MsgBox in under 10 ms, so the timer is effectively never used.And instead of two threads, it now is one thread....



Guest10
  • Members
  • 1216 posts
  • Last active: Oct 30 2015 05:12 PM
  • Joined: 27 Oct 2012

what about this case? any other alternatives for this to work?

what is expected: Loop1 looping every 10 minutes and Loop2 looping every 10 seconds all the time simultaneously & concurrently.

 

SetTimer, Loop1, 600000 ; 10 minutes

; No Return

SetTimer, Loop2, 10000 ; 10 seconds
Return

Loop1:
MsgBox Loop1
Return

Loop2:
MsgBox Loop2
Return



Dave-
  • Members
  • 46 posts
  • Last active: May 17 2013 04:57 PM
  • Joined: 30 Nov 2010

it's because settimer calls a label section and label sections have to be terminated with a return statement. settimer will launch a separate thread in -10 milliseconds. the negative sign in front of the -10 will make it execute just once instead of repeatedly. the separate thread think is important.

 

because the actual msgbox is now running in a separate thread, the main part of the program that contained the settimer statement will not wait for you to cancel the msgbox. instead it will charge ahead to the statements below the settimer and you could leave the msgbox on your window all day and the main program execution would continue.



Dave-
  • Members
  • 46 posts
  • Last active: May 17 2013 04:57 PM
  • Joined: 30 Nov 2010

run 3 threads simultaneously. the msgboxes will all display simultaneously and every one of them runs in a different thread!

SetTimer, Loop1, -10 

SetTimer, Loop2, -10

msgbox, im in a different thread
Return

Loop1:
MsgBox Loop1
Return

Loop2:
MsgBox Loop2
Return