AnonymousX

[Solved] Stop GUI until message box closed

5 posts in this topic

#1 ·  Posted (edited)

Hello,

I'm trying to make it so that when a message box pops up that the GUI will be unresponsive until that message box has been closed. From reading through the help the closest thing I can find is the WinWaitClose function, however this doesn't work fully as desired. If user tries to click on GUI the actions are more just waiting for the message box to close, so that once it closes everything happens at once. I want it so that the GUI is completely unusable until message box is closed. 

 

Below is test code to demonstrate the problem and help explain what I want. Any advice on this?

 

#include <GUIConstantsEx.au3>

Example()

Func Example()
    ; Create a GUI with various controls.
    Local $hGUI = GUICreate("Example")
    Local $idOK = GUICtrlCreateButton("OK", 310, 370, 85, 25)
    local $but = GUICtrlCreateButton("Hello", 150,150,85,25)

    ; Display the GUI.
    GUISetState(@SW_SHOW, $hGUI)
    MsgBox( 262144,"Message","Try hitting the hello button several times,without closing this window. Now close this window and see how script wasn't restricted it just was waiting and storing the instructions")



    WinWaitClose("Message")

    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE, $idOK
                Exit
            case $but
                MsgBox(0,"","Hello")

        EndSwitch
    WEnd

    ; Delete the previous GUI and all controls.
    GUIDelete($hGUI)
EndFunc   ;==>Example

 

Edited by AnonymousX

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

#include <GUIConstantsEx.au3>

Example()

Func Example()
    ; Create a GUI with various controls.
    Local $hGUI = GUICreate("Example")
    Local $idOK = GUICtrlCreateButton("OK", 310, 370, 85, 25)
    Local $but = GUICtrlCreateButton("Hello", 150, 150, 85, 25)

    ; Display the GUI.
    GUISetState(@SW_SHOW, $hGUI)
    GUISetState(@SW_DISABLE, $hGUI) ;added
    MsgBox(262144, "Message", "Try hitting the hello button several times,without closing this window. Now close this window and see how script wasn't restricted it just was waiting and storing the instructions")
    GUISetState(@SW_ENABLE, $hGUI);added


;~  WinWaitClose("Message")

    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE, $idOK
                Exit
            Case $but

                MsgBox(0, "", "Hello")

        EndSwitch
    WEnd

    ; Delete the previous GUI and all controls.
    GUIDelete($hGUI)
EndFunc   ;==>Example

EDIT: check the help file for additional info :P

Edited by 232showtime
1 person likes this

ill get to that... i still need to learn and understand a lot of codes graduated.gif

Correct answer, learn to walk before you take on that marathon.

Share this post


Link to post
Share on other sites

#3 ·  Posted

AnonymousX,

A better solution is to set the correct style for the MsgBox like this:

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

Example()

Func Example()
    ; Create a GUI with various controls.
    Local $hGUI = GUICreate("Example")
    Local $idOK = GUICtrlCreateButton("OK", 310, 370, 85, 25)
    local $but = GUICtrlCreateButton("Hello", 150,150,85,25)

    ; Display the GUI.
    GUISetState(@SW_SHOW, $hGUI)
    MsgBox($MB_TOPMOST + $MB_TASKMODAL,"Message","Try hitting the hello button several times,without closing this window. Now close this window and see how script wasn't restricted it just was waiting and storing the instructions")

    WinWaitClose("Message")

    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE, $idOK
                Exit
            case $but
                MsgBox(0,"","Hello")

        EndSwitch
    WEnd

    ; Delete the previous GUI and all controls.
    GUIDelete($hGUI)
EndFunc   ;==>Example

All is explained in the Modal MsgBox Styles tutorial in the Wiki.

M23

 

3 people like this

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

#4 ·  Posted

Normal way:

#include <GUIConstantsEx.au3>

Example()

Func Example()
    ; Create a GUI with various controls.
    Local $hGUI = GUICreate("Example")
    Local $idOK = GUICtrlCreateButton("OK", 310, 370, 85, 25)
    Local $but = GUICtrlCreateButton("Hello", 150, 150, 85, 25)

    ; Display the GUI.
    GUISetState(@SW_SHOW, $hGUI)
    MsgBox(262144, "Message", "Try hitting the hello button several times,without closing this window. " & _
            "Now close this window and see how script wasn't restricted it just was waiting and storing the instructions", 0, $hGUI)

;~     WinWaitClose("Message")

    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE, $idOK
                Exit
            Case $but
                MsgBox(0, "", "Hello")

        EndSwitch
    WEnd

    ; Delete the previous GUI and all controls.
    GUIDelete($hGUI)
EndFunc   ;==>Example

 


Regards,
 

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Thanks everyone for the help!

Special thanks to you Melba23,

That is exactly how I thought it should be done, I just would have never known by the description in the message box help what " Task modal " meant, and never would have thought to test that. Thanks for helping!

 

Edited by AnonymousX

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

    • Nareshm
      By Nareshm
      I have autoit script like this :
      winActivate ("BillReceipt") ControlClick ( "BillReceipt", "", "[NAME:winviewer]", "right") Send ( "{ENTER}") WinWait ("Print") ControlClick ("Print", "", "[CLASS:Button; INSTANCE:13]") Winwait ("Save As") WinActivate ("Save As") Send ("{TAB 5} {Backspace} ^v {Enter}") I need Saved successfully msgbox with file name as i saved like Filename.extension (Example = test.pdf is saved successfull)

      Please Help
    • Verssuss
      By Verssuss
      hi guys i want avoid to multiple MsgBox by hold Hotkey "]" in my script
       
      #include <GuiConstantsEx.au3> #include <Windowsconstants.au3> #include <SendMessage.au3> #include <WinAPI.au3> ;~ HotKeySet("{[}", "_boxminus") HotKeySet("{]}", "_boxplus") HotKeySet("{ESC}", "On_Exit") $hGUI = GUICreate("", 100, 100, -1, -1, $WS_POPUP, BitOr($WS_EX_LAYERED, $WS_EX_COMPOSITED, $WS_EX_TOPMOST)) GUISetBkColor(0x00FF00) GuiCtrlCreateLabel("", 3, 3, 94, 94) GUICtrlSetBkColor(-1, 0xABCDEF) GUICtrlSetResizing(-1, $GUI_DOCKBORDERS) GUISetState() _WinAPI_SetLayeredWindowAttributes($hGui, 0xABCDEF) $box_range = 100 While 1 $pos = MouseGetPos() WinMove($hGUI, "", $pos[0] - ($box_range / 2), $pos[1] - ($box_range / 2), $box_range, $box_range) WEnd ;~ Func _boxminus() ;~ If $box_range >= 30 Then $box_range = $box_range - 10 ;~ If $box_range < 30 Then $box_range = $box_range - 1 ;~ EndFunc Func _boxplus() If $box_range < 200 Then $box_range = $box_range + 10 Else MsgBox(0,"ERROR", "Maximum size already exist") EndIf EndFunc Func On_Exit() Exit EndFunc i wish after i get first MsgBox another gonna replaced with first one or just cancel in and apeear again
      how can i make it right ???
    • hcI
      By hcI
      Hello !
      I'm making a little script with only a tray option, no GUI.
      And i would like to know if someone created a function to set a personalized icon in top-left corner of the MsgBox and/or InputBox...
      -hcI
    • SkysLastChance
      By SkysLastChance
      I am a little confused and not sure what I am doing wrong.
      I am trying to get a OK and Cancel button that is always on top. 
      $MB_OKCANCEL 1 OK and Cancel $MB_TOPMOST 262144 MsgBox() has top-most attribute set  
      But when I try to run this code. 
      $Msg = MsgBox(1 & 262144, "Registration", "Would you like to continue?") I get this.

    • Tigerweld
      By Tigerweld
      I have a simple msgbox function that I need to use in multiple places, but have different outcomes.  For example, in one location if the left button was pressed I need it to write a one of the reg values.  How do I accomplish this?
       
      #include <GUIConstantsEx.au3> Opt('MustDeclareVars', 1) Local $reg0 = RegWrite("HKLM\SOFTWARE\Wow6432Node\Newton\Default\Servers", "WRKSTN_ID", "REG_DWORD", "0") Local $reg1 = RegWrite("HKLM\SOFTWARE\Wow6432Node\Newton\Default\Servers", "WRKSTN_ID", "REG_DWORD", "1") Local $reg2 = RegWrite("HKLM\SOFTWARE\Wow6432Node\Newton\Default\Servers", "WRKSTN_ID", "REG_DWORD", "2") Local $reg3 = RegWrite("HKLM\SOFTWARE\Wow6432Node\Newton\Default\Servers", "WRKSTN_ID", "REG_DWORD", "3") Local $reg4 = RegWrite("HKLM\SOFTWARE\Wow6432Node\Newton\Default\Servers", "WRKSTN_ID", "REG_DWORD", "4") MainGUI() Func MainGUI() Local $Left, $Right, $msg GUICreate("Light") Opt("GUICoordMode", 2) $Left = GUICtrlCreateButton("Left", 10, 30, 50) $Right = GUICtrlCreateButton("Right", 0, -1) GUISetState() While 1 $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE ExitLoop Case $msg = $Left ; write reg value Case $msg = $Right ; write reg value EndSelect WEnd EndFunc