Jump to content

msgbox


Richard
 Share

Recommended Posts

Isn't it so that a messagebox should block of all other window manipulations until closed?

In the following example code the button can be clicked while the messagebox is present, creating several instances of the msgbox.

How can this be avoided?

#include <GUIConstantsEx.au3>

$a = GUICreate("Hello World", 300, 200)
GUICtrlCreateLabel("Hello world! How are you?", 30, 10)

$b= GUICtrlCreateButton("OK", 70, 50, 60)

$c = GUICtrlCreateButton("quit", 170, 50, 60)

GUISetState(@SW_SHOW)

While 1
  $msg = GUIGetMsg()

  Select
  Case $msg =$b
      MsgBox(0, "GUI Event", "You pressed OK!")
      
    Case $msg = $c
      MsgBox(0, "GUI Event", "You clicked CLOSE! Exiting...")
      ExitLoop  

    Case $msg = $GUI_EVENT_CLOSE 
      MsgBox(0, "GUI Event", "You clicked CLOSE! Exiting...")
      ExitLoop
  EndSelect
WEnd
Link to comment
Share on other sites

It does block them... Instead they are sent to the queue, so when the MsgBox finishes it then executes the next. If you want to stop that the just disable the GUI while the MsgBox is showing:

#include <GUIConstantsEx.au3>

$a = GUICreate("Hello World", 300, 200)
GUICtrlCreateLabel("Hello world! How are you?", 30, 10)

$b = GUICtrlCreateButton("OK", 70, 50, 60)

$c = GUICtrlCreateButton("quit", 170, 50, 60)

GUISetState(@SW_SHOW)

While 1
    $msg = GUIGetMsg()

    Select
        Case $msg = $b
            GUISetState(@SW_DISABLE)
            MsgBox(0, "GUI Event", "You pressed OK!")
            GUISetState(@SW_ENABLE)

        Case $msg = $c
            GUISetState(@SW_DISABLE)
            MsgBox(0, "GUI Event", "You clicked CLOSE! Exiting...")
            GUISetState(@SW_ENABLE)
            ExitLoop

        Case $msg = $GUI_EVENT_CLOSE
            GUISetState(@SW_DISABLE)
            MsgBox(0, "GUI Event", "You clicked CLOSE! Exiting...")
            GUISetState(@SW_ENABLE)
            ExitLoop
    EndSelect
WEnd

Mat

Link to comment
Share on other sites

this seems to work too:

msgbox(8192,"NOTICE",$sp[1])

It does block them... Instead they are sent to the queue, so when the MsgBox finishes it then executes the next. If you want to stop that the just disable the GUI while the MsgBox is showing:

#include <GUIConstantsEx.au3>

$a = GUICreate("Hello World", 300, 200)
GUICtrlCreateLabel("Hello world! How are you?", 30, 10)

$b = GUICtrlCreateButton("OK", 70, 50, 60)

$c = GUICtrlCreateButton("quit", 170, 50, 60)

GUISetState(@SW_SHOW)

While 1
    $msg = GUIGetMsg()

    Select
        Case $msg = $b
            GUISetState(@SW_DISABLE)
            MsgBox(0, "GUI Event", "You pressed OK!")
            GUISetState(@SW_ENABLE)

        Case $msg = $c
            GUISetState(@SW_DISABLE)
            MsgBox(0, "GUI Event", "You clicked CLOSE! Exiting...")
            GUISetState(@SW_ENABLE)
            ExitLoop

        Case $msg = $GUI_EVENT_CLOSE
            GUISetState(@SW_DISABLE)
            MsgBox(0, "GUI Event", "You clicked CLOSE! Exiting...")
            GUISetState(@SW_ENABLE)
            ExitLoop
    EndSelect
WEnd

Mat

Link to comment
Share on other sites

With this code there is still a strange behaviour.

When clicking OK on the first button, the window closes. Why?

------------------------------------------------------------------

It does block them... Instead they are sent to the queue, so when the MsgBox finishes it then executes the next. If you want to stop that the just disable the GUI while the MsgBox is showing:

#include <GUIConstantsEx.au3>

$a = GUICreate("Hello World", 300, 200)
GUICtrlCreateLabel("Hello world! How are you?", 30, 10)

$b = GUICtrlCreateButton("OK", 70, 50, 60)

$c = GUICtrlCreateButton("quit", 170, 50, 60)

GUISetState(@SW_SHOW)

While 1
    $msg = GUIGetMsg()

    Select
        Case $msg = $b
            GUISetState(@SW_DISABLE)
            MsgBox(0, "GUI Event", "You pressed OK!")
            GUISetState(@SW_ENABLE)

        Case $msg = $c
            GUISetState(@SW_DISABLE)
            MsgBox(0, "GUI Event", "You clicked CLOSE! Exiting...")
            GUISetState(@SW_ENABLE)
            ExitLoop

        Case $msg = $GUI_EVENT_CLOSE
            GUISetState(@SW_DISABLE)
            MsgBox(0, "GUI Event", "You clicked CLOSE! Exiting...")
            GUISetState(@SW_ENABLE)
            ExitLoop
    EndSelect
WEnd

Mat

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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...