Jump to content
taylansan

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?

Share this post


Link to post
Share on other sites

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

 

Share this post


Link to post
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

 

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

Melba, not sure how often a feature like this is requested but I like your extended message box udf.  Would a non blocking parameter be easy enough to add to your udf? 

Share this post


Link to post
Share on other sites

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

 

Share this post


Link to post
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

Share this post


Link to post
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

 

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

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

 

Share this post


Link to post
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

 

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

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

 

Share this post


Link to post
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

 

Share this post


Link to post
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

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

Share this post


Link to post
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

  • Similar Content

    • By lee321987
      Sometimes when I call several MsgBox's they start popping up under other windows, which the requires ALT + TAB or click the taskbar icon.
      I just wanted to share this workaround:
      Just add a simple GUI in your program:
      #include <GUIConstantsEx.au3> $Form1 = GUICreate("Form1", 1, 1, 0, 0) GUISetState(@SW_SHOW) The GUI window size here is 1x1 so it will be nearly invisible, and at the top-left of your screen.
      It seems as long as that GUI is there all MsgBox's appear on top!
      I only tend to create several MsgBox's in a row when I'm actually writing and testing scripts, so the GUI being there is no big deal (I just remove/comment the GUI creation right before I build the .EXE).
      Have a great day!!!
       
       
    • By editcheck
      Hi, after years of use autoit i am tired to type all time:
      msgbox('','','Hi')
      So, wanna mod the function for set default values... or some more changes.
      where is the function?
      or there are another modes for debug messages that i do not knowed ? XD [just wanna like alert('text')]
      And is there any place for all integrates functions ?
      Thank. Sry my english =E
    • By Ackerz
      Hi guys,
      So I am trying to automate a task and this task has an input box with an already set character "9". 
      I have just decided that I don't really need the input as an option but it's good to leave however for this instance I would like it to run past this point automatically. I've tried numerous ways to try and automate the use of the "OK" button using ControlClick and various other options. I just can't seem to see where this point in the script is. Scoured the forums for anything similar but didn't have any luck finding anything. Sorry to be a pain and I hope someone can help, if I haven't explained in enough detail please don't hesitate to ask for more.
      Many thanks,
      Ackerz
       
      Local $len Local $n Local $buff Local $aMyDate $Len = InputBox("Test",$msgPrompt,"9") $len = StringStripWS($len,$STR_STRIPALL) ;Check that user has entered a vaild password length if not StringIsDigit($len) or $len = 0 Then MsgBox(48,"Error","Invaild Integer was entered" & @CRLF & "Program will now exit.") Exit EndIf ;This creates the random password. for $i = 1 to $Len ;Pick a random char between 1 and the pwsMask Length $n = int(random(1,StringLen($pwsMask))) ;Concat each char that has been picked out of pwsMask to $buff $buff = $Buff & StringMid($pwsmask,$n,1) Next  
    • By xtcislove
      Hello,
      as a start in Autoit i tried something i was missing since im using Autoit. 

      I build a custom MessageBox which has a large amount of custom options and which scales its size on the parameters you set. 

      Aviable Settings:
      -Title
      -Unlimited Buttons
      -Text Color (Buttons, Text)

      -Background Color (Msgbox, Buttons, Label) 

      -Button Timeout
      -Autoclose Timeout
      -Icon (Default, No Icon, Custom)

      -Label/ Button Style. 
      -Transparency

      I tried to keep this as close as i could to a Msgbox i was used too on my batch times.

      After i was ready i realised, @Melba23 probably build a way better msgbox which would have suit my needs enterly, anyway thanks to @Melba23 because i use his Stringsize UDF. 

       
       
      local $Message = _sMsgBox("Test", 6, "Continue?") if @extended <> -1 Then MsgBox(0, @extended, $Message&" Button pressed")  
      ScalingMessageBox.au3
    • By SkysLastChance
      I am having a hard time understanding why this is not working. I was hoping some one could help explain it to me. 
      $tags = $oIE.document.GetElementsByTagName("input") For $tag in $tags $class_value = $tag.GetAttribute("class") If string($class_value) = "fTs-p3298-l0 wplEditControl" Then $target = $tag ExitLoop EndIF Next MsgBox(0,"",$target) If $target = "fTs-p3298-l0 wplEditControl" THEN MsgBox(0,"","itworked") I have tried 
       MsgBox(0,"",$target.Attribute)  MsgBox(0,"",$target.Value)  MsgBox(0,"",$target.InnerText) I would expect to see this in the msgbox
      fTs-p3298-l0 wplEditControl  
×
×
  • Create New...