Jump to content

[Solved] Stop GUI until message box closed


Recommended Posts

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
Link to comment
Share on other sites

#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

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.

Link to comment
Share on other sites

  • Moderators

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

 

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

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,
 

Link to comment
Share on other sites

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
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...