bendover

GUI and MsgBox

7 posts in this topic

#1 ·  Posted (edited)

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

Share this post


Link to post
Share on other sites



#3 ·  Posted

Yes it does because dialog I've written writes the values to VBS file and continues installation. I'd need to know how to handle GUI events and return to GUI after MsgBox is being closed.

Share this post


Link to post
Share on other sites

#4 ·  Posted

Just delete the Exitloop, once ADCheck has completed it will just return to the Gui

Share this post


Link to post
Share on other sites

#5 ·  Posted

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

 

Share this post


Link to post
Share on other sites

#6 ·  Posted

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

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

Thanks for your advice. I modified original code and now it works using functions.

Edited by bendover

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