Jump to content

Create a number of GUI's based on an InputBox prompt


Kalin
 Share

Recommended Posts

Can anyone help with this?

Here's what I have, not working at the moment.

#include <GUIConstantsEx.au3>
$InputBox = InputBox("Enter the number of windows you would like to open", "Enter the number below", GUICreate("Towns GUI...", 668, 587, 167, 108))
GUISetState()
While 1
$gMsg = GUIGetMsg()
If $gMsg = $GUI_EVENT_CLOSE Then
    Exit
EndIf
WEnd

Edit: Solved. Thanks for the idea BugFix, but an array wouldn't be required for this:

#include <GUIConstantsEx.au3>

$InputBox = InputBox("Enter the number of windows you would like to open", "Enter the number of windows you would like to open below.")

For $i = 1 To $InputBox Step 1
GUICreate("Towns GUI...", 668, 587, 167, 108)
GUISetState()
Next

While 1
$gMsg = GUIGetMsg()
If $gMsg = $GUI_EVENT_CLOSE Then
Exit
EndIf
WEnd
Edited by Kalin
Link to comment
Share on other sites

I don't know the sense of this - but so you can do it:

#include <GUIConstantsEx.au3>
$InputBox = InputBox("Enter the number of windows you would like to open", "Enter the number below", 2)
Local $aGUI[$InputBox], $aBtn[1], $y = 10
If $InputBox > 2 Then ReDim $aBtn[$InputBox-1]

For $i = 0 To UBound($aGUI) -1
    $aGUI[$i] = GUICreate("Towns GUI " & $i+1, 668, 587, 167, 108)
    If $i = 0 Then
        For $j = 0 To UBound($aBtn) -1
            $aBtn[$j] = GUICtrlCreateButton('Open GUI ' & $j+2, 10, $y, 80, 20)
            $y += 30
        Next
    EndIf
Next
GUISetState(@SW_SHOW, $aGUI[0])

While 1
    $gMsg = GUIGetMsg(1)
    Switch $gMsg[0]
        Case $GUI_EVENT_CLOSE
            If $gMsg[1] = $aGUI[0] Then Exit
            For $i = 1 To UBound($aGUI) -1
                If $gMsg[1] = $aGUI[$i] Then
                    GUISetState(@SW_HIDE, $aGUI[$i])
                    GUISetState(@SW_SHOW, $aGUI[0])
                    ExitLoop
                EndIf
            Next
    EndSwitch
    For $i = 0 To UBound($aBtn) -1
        If $gMsg[0] = $aBtn[$i] Then
            GUISetState(@SW_HIDE, $aGUI[0])
            GUISetState(@SW_SHOW, $aGUI[$i+1])
        EndIf
    Next
WEnd

Best Regards BugFix  

Link to comment
Share on other sites

I don't know the sense of this - but so you can do it:

#include <GUIConstantsEx.au3>
$InputBox = InputBox("Enter the number of windows you would like to open", "Enter the number below", 2)
Local $aGUI[$InputBox], $aBtn[1], $y = 10
If $InputBox > 2 Then ReDim $aBtn[$InputBox-1]

For $i = 0 To UBound($aGUI) -1
    $aGUI[$i] = GUICreate("Towns GUI " & $i+1, 668, 587, 167, 108)
    If $i = 0 Then
        For $j = 0 To UBound($aBtn) -1
            $aBtn[$j] = GUICtrlCreateButton('Open GUI ' & $j+2, 10, $y, 80, 20)
            $y += 30
        Next
    EndIf
Next
GUISetState(@SW_SHOW, $aGUI[0])

While 1
    $gMsg = GUIGetMsg(1)
    Switch $gMsg[0]
        Case $GUI_EVENT_CLOSE
            If $gMsg[1] = $aGUI[0] Then Exit
            For $i = 1 To UBound($aGUI) -1
                If $gMsg[1] = $aGUI[$i] Then
                    GUISetState(@SW_HIDE, $aGUI[$i])
                    GUISetState(@SW_SHOW, $aGUI[0])
                    ExitLoop
                EndIf
            Next
    EndSwitch
    For $i = 0 To UBound($aBtn) -1
        If $gMsg[0] = $aBtn[$i] Then
            GUISetState(@SW_HIDE, $aGUI[0])
            GUISetState(@SW_SHOW, $aGUI[$i+1])
        EndIf
    Next
WEnd

This wasn't exactly what I was looking for, but thanks for the idea. Edited by Kalin
Link to comment
Share on other sites

This works much better in GuiOnEventMode than it does with message loops:

#include <GuiConstantsEx.au3>

Opt("GuiOnEventMode", 1)

Global $iX = 0, $iY = 0 ; Globals to tile new child windows

_CreateMaster()

While 1
    Sleep(10)
WEnd

Func _CreateMaster()
    Local $hMaster = GUICreate("Test Master", 300, 300)
    GUISetOnEvent($GUI_EVENT_CLOSE, "_Quit", $hMaster)
    GUICtrlCreateButton("Create New Child", 100, 250, 100, 30)
    GUICtrlSetOnEvent(-1, "_CreateNewChild")
    GUISetState(@SW_SHOW, $hMaster)
EndFunc   ;==>_CreateMaster

Func _CreateNewChild()
    ; Update coordinates for tiling
    $iX += 100
    If $iX >= @DesktopWidth - 250 Then $iX = 100
    $iY += 100
    If $iY >= @DesktopHeight - 250 Then $iY = 100

    ; Create GUI
    Local $hChild = GUICreate("", 250, 250, $iX, $iY)
    GUISetOnEvent($GUI_EVENT_CLOSE, "_CloseChild", $hChild)
    WinSetTitle($hChild, "", "Test Child:  " & $hChild)
    GUICtrlCreateButton("Create New Child", 75, 150, 100, 30)
    GUICtrlSetOnEvent(-1, "_CreateNewChild")
    GUICtrlCreateButton("INFO", 75, 200, 100, 30)
    GUICtrlSetOnEvent(-1, "_InfoButton")
    GUISetState(@SW_SHOW, $hChild)
EndFunc   ;==>_CreateNewChild

Func _CloseChild()
    GUIDelete(@GUI_WinHandle)
EndFunc   ;==>_CloseChild

Func _InfoButton()
    MsgBox(64, "Child GUI Info", "GUI Handle = " & @GUI_WinHandle & @CRLF & _
            "GUI Title = " & WinGetTitle(@GUI_WinHandle, "") & @CRLF & _
            "Button Handle = " & ControlGetHandle(@GUI_WinHandle, "", @GUI_CtrlHandle))
EndFunc   ;==>_InfoButton

Func _Quit()
    Exit
EndFunc   ;==>_Quit

Note that all the GUIs and buttons can operate independently of each other, and the child GUIs can be closed/used individually without impacting the rest of them. All this is done with very few Global variables because the macros tell the event functions everything they need to know about which GUI/Control was clicked. (It could be no Globals at all if you don't bother with the tiling.)

:graduated:

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
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...