Jump to content

Continue the script without waiting for MsgBox


Recommended Posts

Dear AutoIt Community,

i want my script to pop-up a MsgBox, but at the same time to continue the script.

ConsoleWrite("Hello - 1" & @CRLF)
MsgBox(0, "", "Hello - 2")
ConsoleWrite("Hello - 3" & @CRLF)

If I do it as above, the script is paused and waiting for me to close the MsgBox to continue on the third line.

I don't want to set a timer to close the MsgBox either, because I will read the contents of the MsgBox but want my script continue to the next lines.

I didn't see any kind of restriction on the MsgBox help file that will cause the script to be paused.

Can you please tell / show me if this is possible?

TY.

Link to comment
Share on other sites

  • Moderators

taylansan,

search for "NotifyBox" by Yashied - that is a sort of MsgBox which does not pause the script. Or look at the Notify UDF in my sig - that produces small 2-line dialogs that pop in from the side of the screen.

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

MsgBox is a blocking GUI that needs interaction before continuing on with the script. It essentially pauses the script waiting for a response.

It is not possible to continue in your script, unless you response to the MsgBox prompt.

Snips & Scripts


My Snips: graphCPUTemp ~ getENVvars
My Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4

Feel free to use any of my code for your own use.                                                                                                                                                           Forum FAQ

 

Link to comment
Share on other sites

I just make a custom message box.

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

$hMsgBoxGUI = GUICreate("", 248, 168)
GUISetBkColor(0xFFFFFF)

$SaveButton = GUICtrlCreateButton("Save", 32, 120, 75, 25)
$CancelButton = GUICtrlCreateButton("Cancel", 145, 120, 75, 25)
$Label1 = GUICtrlCreateLabel("Some text", 24, 64, 114, 22)
GUICtrlSetFont(-1, 12, 400, 0, "Arial")
GUICtrlSetColor(-1, 0x3399FF)
$Label2 = GUICtrlCreateLabel("Save this Search", 9, 16, 223, 36)
GUICtrlSetFont(-1, 20, 800, 0, "Arial")
GUICtrlSetColor(-1, 0x3399FF)
GUISetState(@SW_SHOW)

; Loop until the user exits.
While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            ExitLoop

    EndSwitch
WEnd

 

 

Edited by Herb191
I did not past all the code the first time
Link to comment
Share on other sites

  • Moderators

Herb191,

That dialog blocks just like the API-generated MsgBox and so does not meet the OP's requirement.

ViciousXUSMC,

Unfortunately adding a "non-blocking parameter" would mean a complete rewrite of the ExtMsgBox UDF - and as there is already my Notify UDF which does not block the script........

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

You can always do it this way.

ConsoleWrite("Hello - 1" & @CRLF)
Run(@AutoItExe & ' /AutoIt3ExecuteLine "MsgBox(4096, '''', ''Hello - 2'')"')
ConsoleWrite("Hello - 3" & @CRLF)

 

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

8 years in AutoIt, 30 posts, still learning something new.

Thanks M23, MikahS, ViciousXUSMC

​It's a constant journey, but no problem. ;)

I learned something new as well.

Snips & Scripts


My Snips: graphCPUTemp ~ getENVvars
My Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4

Feel free to use any of my code for your own use.                                                                                                                                                           Forum FAQ

 

Link to comment
Share on other sites

That dialog blocks just like the API-generated MsgBox and so does not meet the OP's requirement.

​Am a missing something basic here? If he wants to show a message box a still continue on with the script why wouldn’t this work?

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

Global $g_CancelButton

ConsoleWrite("Hello - 1" & @CRLF)
MakeMsgBox()
ConsoleWrite("Hello - 3" & @CRLF)

; Loop until the user exits.
While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE, $g_CancelButton
            ExitLoop

    EndSwitch
WEnd

Func MakeMsgBox()
    $hMsgBoxGUI = GUICreate("", 248, 168)
    GUISetBkColor(0xFFFFFF)
    $SaveButton = GUICtrlCreateButton("Save", 32, 120, 75, 25)
    $g_CancelButton = GUICtrlCreateButton("Cancel", 145, 120, 75, 25)
    $Label1 = GUICtrlCreateLabel("Some text", 24, 64, 114, 22)
    GUICtrlSetFont(-1, 12, 400, 0, "Arial")
    GUICtrlSetColor(-1, 0x3399FF)
    $Label2 = GUICtrlCreateLabel("Save this Search", 9, 16, 223, 36)
    GUICtrlSetFont(-1, 20, 800, 0, "Arial")
    GUICtrlSetColor(-1, 0x3399FF)
    GUISetState(@SW_SHOW)
EndFunc   ;==>MakeMsgBox

Link to comment
Share on other sites

  • Moderators

Herb191,

Unlike the code in your first post that will indeed meet the OP's requirement.  However, as it stands it is limited to a single dialog at a time, which may or may not be a problem.

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Something that might help others understand how MsgBox works in various ways: Modal MsgBox Styles - AutoIt Wiki

Snips & Scripts


My Snips: graphCPUTemp ~ getENVvars
My Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4

Feel free to use any of my code for your own use.                                                                                                                                                           Forum FAQ

 

Link to comment
Share on other sites

Using BrewManNH's way :

#pragma compile(AutoItExecuteAllowed, True) 
Opt("GuiOnEventMode", 1)
Global $stop = 0

GUICreate("My GUI", 250, 100) 
$label = GUICtrlCreateLabel("", 20, 30, 50, 20)
$btn = GUICtrlCreateButton("stop", 10, 60, 50, 20)
GUICtrlSetOnEvent(-1, "_stop")
GUISetState()  

For $i = 1 to 100
  If $i = 10 Then Run(@AutoItExe & ' /AutoIt3ExecuteLine "MsgBox(0, '''', ''$i was 10'')"')
  If $stop Then Exitloop
  GuiCtrlSetData($label, $i)
  Sleep(300)
Next

Func _stop()
  $stop = 1
EndFunc

But this doesn't allow the use of variables from the main script in the MsgBox

Link to comment
Share on other sites

  • Moderators

mikell,

But this doesn't allow the use of variables from the main script in the MsgBox

Yes it does:

#pragma compile(AutoItExecuteAllowed, True)
Opt("GuiOnEventMode", 1)
Global $stop = 0, $sText = "Hi There"

GUICreate("My GUI", 250, 100)
$label = GUICtrlCreateLabel("", 20, 30, 50, 20)
$btn = GUICtrlCreateButton("stop", 10, 60, 50, 20)
GUICtrlSetOnEvent(-1, "_stop")
GUISetState()

For $i = 1 to 100
  If $i = 10 Then Run(@AutoItExe & ' /AutoIt3ExecuteLine "MsgBox(0, ""' & $sText & '"", ''$i was 10'')"')

  If $stop Then Exitloop
  GuiCtrlSetData($label, $i)
  Sleep(300)
Next

Func _stop()
  $stop = 1
EndFunc

You just need to get the quotes right - and, yes, it took me several goes!

M23 

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

If you want to get an answer back from your MsgBox:

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <MsgBoxConstants.au3>

#pragma compile(AutoItExecuteAllowed, True)

Opt( "GuiOnEventMode", 1 )

Global $iStop = 0, $lbl2, $lbl3

Local $hGui = GUICreate( "My GUI", 250, 100 )
GUISetOnEvent( $GUI_EVENT_CLOSE, "Stop" )
GUIRegisterMsg( $WM_USER, "WM_MSGBOX" )

GUICtrlCreateLabel( "Loop: ", 10, 10, 30, 20 )
Local $lbl1 = GUICtrlCreateLabel( "", 50, 10, 30, 20 )

GUICtrlCreateLabel( "MsgBox: ", 110, 10, 50, 20 )
$lbl2 = GUICtrlCreateLabel( "", 170, 10, 30, 20 )
GUICtrlCreateLabel( "Answer: ", 110, 40, 50, 20 )
$lbl3 = GUICtrlCreateLabel( "", 170, 40, 30, 20 )

Local $btn = GUICtrlCreateButton( "Stop", 10, 60, 50, 20 )
GUICtrlSetOnEvent( -1, "Stop" )

Local $sText = "Hi There"

GUISetState()


For $i = 1 to 100
  If $i = 10 Then Run( @AutoItExe & ' /AutoIt3ExecuteLine "DllCall(''user32.dll'', ''lresult'', ''SendMessageW'', ''hwnd'', ""' & $hGui & '"", ''uint'', ""' & $WM_USER & '"", ''wparam'', ""' & $i & '"", ''lparam'', MsgBox( ""' & $MB_OKCANCEL    & '"", ""' & $sText & '"", ''I was '' & ""' & $i & '"" ))"' )
  If $i = 15 Then Run( @AutoItExe & ' /AutoIt3ExecuteLine "DllCall(''user32.dll'', ''lresult'', ''SendMessageW'', ''hwnd'', ""' & $hGui & '"", ''uint'', ""' & $WM_USER & '"", ''wparam'', ""' & $i & '"", ''lparam'', MsgBox( ""' & $MB_YESNOCANCEL & '"", ""' & $sText & '"", ''I was '' & ""' & $i & '"" ))"' )
  If $i = 20 Then Run( @AutoItExe & ' /AutoIt3ExecuteLine "DllCall(''user32.dll'', ''lresult'', ''SendMessageW'', ''hwnd'', ""' & $hGui & '"", ''uint'', ""' & $WM_USER & '"", ''wparam'', ""' & $i & '"", ''lparam'', MsgBox( ""' & $MB_RETRYCANCEL & '"", ""' & $sText & '"", ''I was '' & ""' & $i & '"" ))"' )

  If $iStop Then Exitloop
  GuiCtrlSetData( $lbl1, $i )
  Sleep(300)
Next

Func Stop()
  $iStop = 1
EndFunc

Func WM_MSGBOX( $hWnd, $iMsg, $wParam, $lParam )
  Switch $wParam
    Case 10, 15, 20
      GuiCtrlSetData( $lbl2, Int( $wParam ) )
      GuiCtrlSetData( $lbl3, Int( $lParam ) )
  EndSwitch
EndFunc

 

Link to comment
Share on other sites

one more way
this can spawn an external independant MsgBox detached from the main script, but from the main script you can still check what has been pressed on the external MsgBox. This mode can also be used for InputBox as well

Local $pid = SpawnMsgBox(1, "Extern MsgBox", "I am detached from the main script") ; Spawn an independant msgbox


Local $msg = "Hi" & @CRLF & " hit OK to check external MsgBox status"
While 1
    MsgBox(0, "internal MsgBox", $msg)
    Switch CheckExternal($pid)
        Case 1 ; OK Button Pressed
            MsgBox(0, "Result", "OK button was pressed on external MsgBox")
            Exit
        Case 2 ; Cancel Button Pressed
            MsgBox(0, "Result", "Cancel button was pressed on external MsgBox")
            Exit
        Case -1 ;
            MsgBox(0, "Result", "External MsgBox closed for timeout")
            Exit
    EndSwitch
    $msg = "At " & @HOUR & ":" & @MIN & ":" & @SEC & " external MsgBox was still there"
WEnd

; this receives result from the external MsgBox
Func CheckExternal($pid)
    Return StdoutRead($pid)
EndFunc   ;==>CheckExternal

; This spawn an MsgBox and returns the related PID
Func SpawnMsgBox($iflag = 0, $sTitle = "", $sText = "", $iTimeout = 0)
    Return Run(@AutoItExe & ' /AutoIt3ExecuteLine "ConsoleWrite(MsgBox(' & $iflag & ', ''' & $sTitle & ''', ''' & $sText & ''', ' & $iTimeout & '))"', "", "", 0x2) ; 0x2 ($STDOUT_CHILD)
EndFunc   ;==>SpawnMsgBox

 

Edited by Chimp

 

image.jpeg.9f1a974c98e9f77d824b358729b089b0.jpeg Chimp

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Link to comment
Share on other sites

  • 7 years later...

Hi everybody :)
I'm aware Gianni's last post just above was written 7 years ago, but there's something important to add to his script.

First of all, the script is great because it returns (simply) what has been pressed by the user on the external MsgBox, which is a crucial information when more than 1 button can be pressed in this external MsgBox.

The script runs fine when it's not compiled, but it doesn't work when compiled... unless we add the following line at the beginning of the script :

#pragma compile(AutoItExecuteAllowed, True)

I just found this line in one of Nine's script and it's also in AutoIt help file, at the very end of the topic Running Scripts (chapter "Important notes")

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...