DigDeep

Multiple GUI forms

7 posts in this topic

Hi,

Can someone please help here...

When I enter any text in the Input box 1 and Select the Button 1 within Form1, it should open the Form2 containing InputBox2 and Button 2.

Can we get multiple forms built inside each other?

 

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 578, 120, 700, 421)
$Button1 = GUICtrlCreateButton("Button1", 360, 48, 75, 25)
$Input1 = GUICtrlCreateInput("Input1", 40, 48, 257, 24)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

#Region ### START Koda GUI section ### Form=
$Form2 = GUICreate("Form1", 415, 123, 789, 423)
$Button1 = GUICtrlCreateButton("Button2", 288, 48, 75, 25)
$Input2 = GUICtrlCreateInput("Input2", 40, 48, 217, 24)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

        Case $Button1
;~          Pressing the Button 1 should open the $FORM2 and complete actions

    EndSwitch
WEnd

 

Share this post


Link to post
Share on other sites



In the wiki you'll find a tutorial on how to cope with multiple GUIs: https://www.autoitscript.com/wiki/Managing_Multiple_GUIs


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

Here you are

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 578, 120, 700, 421)
$Button1 = GUICtrlCreateButton("Button1", 360, 48, 75, 25)
$Input1 = GUICtrlCreateInput("Input1", 40, 48, 257, 24)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###



While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

        Case $Button1
            #Region ### START Koda GUI section ### Form=
$Form2 = GUICreate("Form1", 415, 123, 789, 423)
$Button1 = GUICtrlCreateButton("Button2", 288, 48, 75, 25)
$Input2 = GUICtrlCreateInput("Input2", 40, 48, 217, 24)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
;~          Pressing the Button 1 should open the $FORM2 and complete actions

    EndSwitch
WEnd

 

1 person likes this

Share this post


Link to post
Share on other sites

You want forms inside of forms? Of course we can do that!

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <WinAPI.au3>

Global $frmMain = GUICreate("Main GUI", 768, 480, -1, -1, BitOR($WS_SIZEBOX, $WS_MAXIMIZEBOX, $WS_MINIMIZEBOX, $WS_CLIPCHILDREN))
Global $inpMainInput = GUICtrlCreateInput("Input1", 10, 10, 100, 20)
Global $btnMainButton = GUICtrlCreateButton("Button1", 120, 10, 100, 20)
Global $aButtons[1][1]
Global $aInputs[1][1]

GUICtrlSetResizing($inpMainInput, $GUI_DOCKALL)
GUICtrlSetResizing($btnMainButton, $GUI_DOCKALL)

GUISetState(@SW_SHOW, $frmMain)

While 1
    $nMsg = GUIGetMsg(1)
    Switch $nMsg[1]
        Case $frmMain
            Switch $nMsg[0]
                Case $GUI_EVENT_CLOSE
                Exit
            Case $btnMainButton
                    Local $frmChild = GUICreate("Form inside form : Count " & UBound($aButtons, $UBOUND_ROWS) - 1, 480, 256, -20, 30, BitOR($WS_SIZEBOX, $WS_MAXIMIZEBOX, $WS_MINIMIZEBOX))
                    Local $inpChildInput = GUICtrlCreateInput("Input2", 10, 10, 200, 20)
                    Local $btnChildButton = GUICtrlCreateButton("Button2", 220, 10, 100, 20)
                    GUICtrlSetResizing($inpChildInput, $GUI_DOCKALL)
                    GUICtrlSetResizing($btnChildButton, $GUI_DOCKALL)

                    $aButtons[UBound($aButtons, $UBOUND_ROWS) - 1][0] = $btnChildButton
                    $aInputs[UBound($aInputs, $UBOUND_ROWS) - 1][0] = $inpChildInput
                    ReDim $aButtons[UBound($aButtons, $UBOUND_ROWS) + 1][1]
                    ReDim $aInputs[UBound($aInputs, $UBOUND_ROWS) + 1][1]

                    _WinAPI_SetParent($frmChild, $frmMain)
                    GUISetState(@SW_SHOW, $frmChild)
            EndSwitch
        Case Else
            Switch $nMsg[0]
                Case $GUI_EVENT_CLOSE
                    GUIDelete($nMsg[1])
                Case Else
                    For $i = 0 to UBound($aButtons, $UBOUND_ROWS) - 1
                        If ($nMsg[0] = $aButtons[$i][0]) Then
                            GUICtrlSetData($aInputs[$i][0], "Button ID " & $aButtons[$i][0] & " for form " & $i & " pressed")
                            ExitLoop
                        EndIf
                    Next
            EndSwitch
    EndSwitch
WEnd

 

Share this post


Link to post
Share on other sites

Thank you topten and all.

Share this post


Link to post
Share on other sites

you could also put the second gui in a function you created and call the function. i find that to make the program in general more organized and easier to follow

$Form1 = GUICreate("Form1", 578, 120, 700, 421)
$Button1 = GUICtrlCreateButton("Button1", 360, 48, 75, 25)
$Input1 = GUICtrlCreateInput("Input1", 40, 48, 257, 24)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

 

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

        Case $Button1
        _secondGUI()
    endswitch


func _sencondGUI()

$Form2 = GUICreate("Form1", 415, 123, 789, 423)
$Button1 = GUICtrlCreateButton("Button2", 288, 48, 75, 25)
$Input2 = GUICtrlCreateInput("Input2", 40, 48, 217, 24)
GUISetState(@SW_SHOW)
endfunc

Share this post


Link to post
Share on other sites

It's not a good practice to create forms in the 'GuiGetMsgLoop' so everytime the Msg ic catched a new form is created. I do this like this:  2GUI.au3

nearly the same as in:

On ‎05‎.‎01‎.‎2016 at 7:49 AM, water said:

In the wiki you'll find a tutorial on how to cope with multiple GUIs: https://www.autoitscript.com/wiki/Managing_Multiple_GUIs

 

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