Jump to content

Reenter previous loop after func call


Recommended Posts

Hey everyone...

I am working on a GUI that features a menu item "About". When the user clicks it, it calls a function that draws a new GUI and disables the previous GUI. When the user closes that, the About GUI is deleted and the previous, "Main", GUI is reenabled. After this happens, I would like the script to return to the previous loop that called the About GUI function - Is this possible? I've been trying and searching for a while but cannot seem to find anything.

Here is a small example of what I mean...

form_Example()

Func form_Example()

    Global $hExample = GUICreate("GUI Example, @DesktopWidth, @DesktopHeight - 40, 0, 0, BitOR($WS_MAXIMIZEBOX, $WS_MINIMIZEBOX))

    Global $idHelpMenu = GUICtrlCreateMenu("Help")

        Global $idHelpMenu_About = GUICtrlCreateMenuItem("About", $idHelpMenu)

    Global $sLogInUser = form_LogIn()

EndFunc

Func form_HelpMenu_About()

    GUISetState(@SW_DISABLE, $hExample)

    Local $hAboutBox = GUICreate("About", 400, 600, -1, -1, Default, $WS_EX_TOPMOST)
    GUISetState(@SW_SHOW, $hAboutBox)

    While 1

        Local $nMsg = GUIGetMsg()

        Switch $nMsg
            Case $GUI_EVENT_CLOSE
                GUISetState(@SW_ENABLE, $hExample)
                GUIDelete($hAboutBox)
                ExitLoop ;AND GO BACK TO LOGIN FUNC

        EndSwitch
    WEnd
EndFunc

Func form_LogIn()

    Local $hLogIn = GUICreate("f_logIn", 350, 400, -1, -1, $WS_CHILD, $WS_EX_TOPMOST, $hExample)

    While 1

        Local $nMsg = GUIGetMsg()

        Switch $nMsg
            Case $GUI_EVENT_CLOSE
                Exit

            Case $idHelpMenu_About
                form_HelpMenu_About()

;RE-ENTER LOOP HERE!!!

        EndSwitch

    WEnd

EndFunc

Thanks, Eric

Link to comment
Share on other sites

Well your example does not work but I think I know what you're trying to do. Look in the help file under GUIGetMsg or check out this link on managing multiple GUIs.

Here's another small example

#include <GUIConstants.au3>


Global $hExample = GUICreate("GUI Example", 800, 600, 0, 0, BitOR($WS_MAXIMIZEBOX, $WS_MINIMIZEBOX))
Global $idHelpMenu = GUICtrlCreateMenu("Help")
Global $idHelpMenu_About = GUICtrlCreateMenuItem("About", $idHelpMenu)
Global $hAbout = GUICreate("About", 400, 300)
GUICtrlCreateLabel("This program is just an example.", 10, 10, 380, 280)

GUISetState(@SW_SHOW, $hExample)

While (True)
    Local $aGuiMsg = GUIGetMsg(1) ; Get array of messages, since we're working with multiple dialogs.
    Switch ($aGuiMsg[0])
        Case $GUI_EVENT_CLOSE
            Switch ($aGuiMsg[1])
                Case $hExample
                    GUIDelete($hExample)
                    GUIDelete($hAbout)
                    Exit 0
                Case $hAbout
                    GUISetState(@SW_ENABLE, $hExample)
                    GUISetState(@SW_HIDE, $hAbout)
            EndSwitch
        Case $idHelpMenu_About
            GUISetState(@SW_DISABLE, $hExample)
            GUISetState(@SW_SHOW, $hAbout)
    EndSwitch
WEnd

 

Link to comment
Share on other sites

Thanks, @InunoTaishou - I was running out of work when I posted and didn't get a chance to test the example. Sorry for that! o:) The full code I have works, but at this point, I am unable to post all of it for sensitivity reasons. I was just trying to share the general idea.

I'll take a look at the various resources you posted and, hopefully, something clicks. Thanks again!  

Link to comment
Share on other sites

Alright - so I read through what you suggested and I understand the concept but am having trouble implementing it into my application. I've got it organized in a way that makes sense to me, but when you run it obviously something is still wrong. Would you mind taking a look? This is the full code this time.

 

#NoTrayIcon

;   Library Inclusions

    #include <Array.au3>
    #include <AutoItConstants.au3>
    #include <ButtonConstants.au3>
    #include <Crypt.au3>
    #include <EditConstants.au3>
    #include <Inet.au3>
    #include <File.au3>
    #include <FontConstants.au3>
    #include <GUIConstantsEx.au3>
    #include <GuiMenu.au3>
    #include <StaticConstants.au3>
    #include <WindowsConstants.au3>

;   Declarations

    AutoItSetOption("MustDeclareVars", 1)

    Global $sMainDir = "G:\Eric\LoginGUITesting\"
    Global $aGUIMsg = GUIGetMsg(1)

;   ********** Start of the Script **********
;

form_mainProgram()


;   ********** End  of the  Script **********
;

Func form_mainProgram()

    Global $hMainProgram = GUICreate("BT Dashboard", @DesktopWidth, @DesktopHeight - 40, 0, 0, BitOR($WS_MAXIMIZEBOX, $WS_MINIMIZEBOX))
        GUISetBkColor(0xDDDDDD, $hMainProgram)
        GUISetIcon($sMainDir & "Images\hacuIcon.ico")
        GUISetState(@SW_SHOW, $hMainProgram)
        WinSetState($hMainProgram,"",@SW_MAXIMIZE)

    Global $idFileMenu = GUICtrlCreateMenu("File")

        Global $idFileMenu_Exit = GUICtrlCreateMenuItem("Exit", $idFileMenu)

    Global $idEditMenu = GUICtrlCreateMenu("Edit")
        GUICtrlSetState($idEditMenu, $GUI_DISABLE)

    Global $idViewMenu = GUICtrlCreateMenu("View")
        GUICtrlSetState($idViewMenu, $GUI_DISABLE)

    Global $idHelpMenu = GUICtrlCreateMenu("Help")

        Global $idHelpMenu_About = GUICtrlCreateMenuItem("About", $idHelpMenu)

    Global $idAdminMenu = GUICtrlCreateMenu("Admin")
        GUICtrlSetState($idAdminMenu, $GUI_DISABLE)

    Global $sLogInUser = form_LogIn()

EndFunc

Func form_HelpMenu_About()

    GUISetState(@SW_DISABLE, $hMainProgram)

    Global $hAboutBox = GUICreate("About", 400, 600, -1, -1, Default, $WS_EX_TOPMOST)
    GUISetState(@SW_SHOW, $hAboutBox)

EndFunc

Func form_LogIn()

    Global $hLogIn = GUICreate("f_logIn", 350, 400, -1, -1, $WS_CHILD, $WS_EX_TOPMOST, $hMainProgram)
        GUISetBkColor(0xFFFFFF)
        GUISetState(@SW_SHOW, $hLogIn)

    Local $shape_headerLine = GUICtrlCreateGraphic(30, 70, 290, 2)
        GUICtrlSetBkColor($shape_headerLine, 0xEAEAEA)

    Local $l_header = GUICtrlCreateLabel("User Login", 30, 20, 200, 50)
        GUICtrlSetFont($l_header, 22, 400, "", "Segoe UI", $CLEARTYPE_QUALITY)
        GUICtrlSetBkColor($l_header, 0xFFFFFF)
        GUICtrlSetColor($l_header, 0x009BAA)

    Local $sUserNameFocus = "Email Address"
    Local $i_userName = GUICtrlCreateInput("", 60, 128, 250, 29)
        GUICtrlSendMsg($i_userName, $EM_SETCUEBANNER, False, $sUserNameFocus)
        GUICtrlSetBkColor($i_userName, 0xF0EEF0)
        GUICtrlSetColor($i_userName, 0x333333)
        GUICtrlSetFont($i_userName, 12, 500, "", "Segoe UI", $CLEARTYPE_QUALITY)
        GUICtrlSetTip($i_userName, "Enter a valid email address", "Username", $TIP_INFOICON, $TIP_CENTER)

        GUICtrlCreatePic($sMainDir & "Images\userIcon.bmp", 36, 136, 12, 12, $BS_BITMAP)

    Local $sPasswordFocus = "Password"
    Local $i_password = GUICtrlCreateInput("", 60, 176, 250, 29, $ES_PASSWORD)
        GUICtrlSendMsg($i_password, $EM_SETCUEBANNER, False, $sPasswordFocus)
        GUICtrlSetBkColor($i_password, 0xF0EEF0)
        GUICtrlSetColor($i_password, 0x333333)
        GUICtrlSetFont($i_password, 12, 500, "", "Segoe UI", $CLEARTYPE_QUALITY)
        GUICtrlSetTip($i_password, "Enter your matching password", "Password", $TIP_INFOICON, $TIP_CENTER)

        GUICtrlCreatePic($sMainDir & "Images\passIcon.bmp", 35, 183, 15, 15, $BS_BITMAP)

    Local $l_forgotPass = GUICtrlCreateLabel("Forgot your password?", 60, 230, 120, 17)
        GUICtrlSetFont(-1, 8, 400, 0, "Segoe UI")
        GUICtrlSetColor($l_forgotPass, 0x009BAA)
        GUICtrlSetFont($l_forgotPass, 9, 500, "", "Segoe UI", $CLEARTYPE_QUALITY)
        GUICtrlSetCursor($l_forgotPass, 0)

    Local $l_requestLogin = GUICtrlCreateLabel("Request credentials", 60, 260, 103, 17)
        GUICtrlSetFont(-1, 8, 400, 0, "Segoe UI")
        GUICtrlSetColor($l_requestLogin, 0x009BAA)
        GUICtrlSetFont($l_requestLogin, 9, 500, "", "Segoe UI", $CLEARTYPE_QUALITY)
        GUICtrlSetCursor($l_requestLogin, 0)

    Local $b_logIn = GUICtrlCreateButton("", 0, 325, 350, 75, $BS_BITMAP)
        GUICtrlSetImage($b_logIn, $sMainDir & "Images\loginButton.bmp")

EndFunc

Func form_ResetPass()

    Global $hPassReset = GUICreate("f_passReset", 350, 300, -1, -1, $WS_CHILD, $WS_EX_TOPMOST, $hMainProgram)
    GUISetBkColor(0xFFFFFFF)

    Local $l_header = GUICtrlCreateLabel("Password Reset", 30, 20, 200, 50)
    GUICtrlSetFont($l_header, 22, 400, "", "Segoe UI", $CLEARTYPE_QUALITY)
    GUICtrlSetBkColor($l_header, 0xFFFFFF)
    GUICtrlSetColor($l_header, 0x009BAA)

    Local $shape_headerLine = GUICtrlCreateGraphic(30, 70, 290, 2)
    GUICtrlSetBkColor($shape_headerLine, 0xEAEAEA)

    Local $tabStop = GUICtrlCreateTab(0, 0, 1, 1)
    GUICtrlSetBkColor($tabStop, 0xFFFFFF)

    Local $sUserNameFocus = "Email Address"
    Local $i_userName = GUICtrlCreateInput("", 60, 128, 250, 29)
    GUICtrlSendMsg($i_userName, $EM_SETCUEBANNER, False, $sUserNameFocus)
    GUICtrlSetBkColor($i_userName, 0xF0EEF0)
    GUICtrlSetColor($i_userName, 0x333333)
    GUICtrlSetFont($i_userName, 12, 500, "", "Segoe UI", $CLEARTYPE_QUALITY)
    GUICtrlSetTip($i_userName, "Enter a valid email address", "Username", $TIP_INFOICON, $TIP_CENTER)

    GUICtrlCreatePic($sMainDir & "Images\userIcon.bmp", 36, 136, 12, 12, $BS_BITMAP)

    Local $l_ReturnLogIn = GUICtrlCreateLabel("Return to the Login Screen", 60, 175, 140, 17)
    GUICtrlSetFont(-1, 8, 400, 0, "Segoe UI")
    GUICtrlSetColor($l_ReturnLogIn, 0x009BAA)
    GUICtrlSetFont($l_ReturnLogIn, 9, 500, "", "Segoe UI", $CLEARTYPE_QUALITY)
    GUICtrlSetCursor($l_ReturnLogIn, 0)

    Local $b_passReset = GUICtrlCreateButton("", 0, 225, 350, 75, $BS_BITMAP)
    GUICtrlSetImage($b_passReset, $sMainDir & "Images\passResetButton.bmp")

    GUISetState(@SW_SHOW)

EndFunc

Func PassCheck($sUserName, $sPass)

    ; Grab the stored password

    Local $aStoredPass
    Local Const $CALG_SHA_256 = 0x0000800c

    _FileReadToArray($sMainDir & "userAccounts.csv", $aStoredPass, $FRTA_NOCOUNT, ",")

    For $i = 0 To $aStoredPass
        If $sUserName = $aStoredPass[$i][0] Then
            _Crypt_Startup

            Local $sHashedPass = _Crypt_HashData($sPass, $CALG_SHA_256)

            If $sHashedPass = $aStoredPass[$i][4] Then
                MsgBox(0,"","Passwords Match!")
            Else
                MsgBox(0,"","Passwords do not match. Please try again.")
            EndIf

            _Crypt_Shutdown

        EndIf
    Next
EndFunc

Func loop_GUIGetMsg()

    While 1
        Switch ($aGUIMsg[1])
            Case $hMainProgram

                Switch $aGUIMsg[0]

                    Case $GUI_EVENT_CLOSE
                        Exit

                    Case $idFileMenu_Exit
                        Exit

                    Case $idHelpMenu_About
                        form_HelpMenu_About()

                EndSwitch

            Case $hLogIn

            Case $hPassReset

            Case $hAboutBox

        EndSwitch
    WEnd

EndFunc


 

Edited by ericbartha
Link to comment
Share on other sites

No matter where I call the "loop_GUIGetMsg" function the script terminates early and gives this warning. I'll keep playing with it for now.

--> Press Ctrl+Alt+Break to Restart or Ctrl+Break to Stop
"G:\Eric\LoginGUITesting\loginForm.au3" (240) : ==> Variable used without being declared.:
Case $hPassReset
Case ^ ERROR
->13:14:44 AutoIt3.exe ended.rc:1
Link to comment
Share on other sites

I removed the Opt must declare vals and it ran fine, but still instantly closed. This makes me think it is never even getting to the  while 1loop for some reason.

I'll try declaring all vars and reorganizing the flow a little. Thanks for your continuned support InunoTaishou. This is what makes the AutoIt community so great.

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