Jump to content

GUI and MsgBox


Recommended Posts

I have written a dialog which reads user selections, writes values to VBS script and exits after pushing button. Dialog needs a feature to check some values based on selections. GUI should show MsgBox if certain CheckBox is cheked and return to main dialog. The problem is that after showing MsgBox script exists instead of returning to GUI. It should return to GUI as long as "If" condition is true ($GUI_CHECKED in this example).

Here's simple example:

#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <MsgBoxConstants.au3>
#include <GUIComboBox.au3>
#include <Array.au3>
#include <AD.au3>
$Form1 = GUICreate("Form1", 391, 260, 192, 124)
$Input = GUICtrlCreateInput("", 48, 112, 121, 21)
$CheckBox = GUICtrlCreateCheckbox("CheckBox", 184, 112, 97, 17)
$Button = GUICtrlCreateButton("Install", 144, 200, 75, 25)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
         Case $Button
            $readCheckBox = GUICtrlRead ($CheckBox)
            $readInput = GUICtrlRead ($Input)
            ADCheck ()
            ExitLoop
    EndSwitch
 WEnd

Func ADCheck ()
   If GUICtrlRead ($CheckBox) = $GUI_CHECKED Then
      MsgBox ($MB_SYSTEMMODAL, "VAR", "Hello")
   EndIf
EndFunc

Edited by bendover
Link to comment
Share on other sites

You could do something like this:

 

#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <MsgBoxConstants.au3>
#include <GUIComboBox.au3>
#include <Array.au3>
;#include <AD.au3>
$Form1 = GUICreate("Form1", 391, 260, 192, 124)
$Input = GUICtrlCreateInput("", 48, 112, 121, 21)
$CheckBox = GUICtrlCreateCheckbox("CheckBox", 184, 112, 97, 17)
$Button = GUICtrlCreateButton("Install", 144, 200, 75, 25)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
         Case $Button
            $readCheckBox = GUICtrlRead ($CheckBox)
            $readInput = GUICtrlRead ($Input)
            If ADCheck() Then ExitLoop
    EndSwitch
 WEnd

Func ADCheck ()
   If GUICtrlRead ($CheckBox) = $GUI_CHECKED Then Return MsgBox ($MB_SYSTEMMODAL, "VAR", "Hello")
EndFunc

 

Link to comment
Share on other sites

bendover,

Try something like this...

#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <MsgBoxConstants.au3>
#include <GUIComboBox.au3>
#include <Array.au3>
;#include <AD.au3>
$Form1 = GUICreate("Form1", 391, 260, 192, 124)
$Input = GUICtrlCreateInput("", 48, 112, 121, 21)
$CheckBox = GUICtrlCreateCheckbox("CheckBox", 184, 112, 97, 17)
$Button = GUICtrlCreateButton("Install", 144, 200, 75, 25)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button
            ;$readCheckBox = GUICtrlRead ($CheckBox)    ; not sure what this is for
            $readInput = GUICtrlRead($Input)
            If ADCheck() Then _go_do_something_else()
            GUICtrlSetState($Input, $gui_focus)         ; set cursor to input box
    EndSwitch
WEnd

Func ADCheck()
    If GUICtrlRead($CheckBox) = $GUI_CHECKED Then Return MsgBox($MB_SYSTEMMODAL, "VAR", "Hello")
EndFunc   ;==>ADCheck

Func _go_do_something_else()
    MsgBox(0, '', 'Hi, I"m doing something else...', 2)
EndFunc   ;==>_go_do_something_else

Incidentally, your original code would return you to the message loop if you had followed Jos's advice...

kylomas

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

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