Jump to content

help plz


Recommended Posts

hey guys i have a function set to a button, this function has its own GUI

now i have two problems which i cannot find the solution for

1. first, the function has a next button which loops the function, my first problem is that it is making another window each time the function is looped, how do i close each window when next is pressed? and as such keeping only the 2 windows open? the main menu and only 1 window for the function?

2. this same function exits the whole thing when exit is pressed, how do i set it so that it only closes the window/s for that function only so it can return to the main menu?

here is the code for the main menu:

$gui=GUICreate("Utilities Collection")
GUISetState(@SW_SHOW, $gui)
$Button1=GUICtrlCreateButton("Exit", 346, 5, 50, 25)
$Button2=GUICtrlCreateButton("Random number", 5, 5, 100, 25)
GUICtrlCreateLabel("creates a random number between and including 1 and 5500" & @lf & "for Death Rulettes in the V2 clone", 5, 30)
$Button3=GUICtrlCreateButton("File Maker", 5, 70, 100, 25)
GUICtrlCreateLabel("Creates a file with any extension, perfect for premaking a script, config or text file", 5, 95) 
$Button4=GUICtrlCreateButton("Record an error", 5, 125, 100, 25)
GUICtrlCreateLabel("Records an error from a window as a file", 5, 150)

main menu works fine and so do the other functions, its only this one i want to fix:

Func randomnumber()
$LowerLimit = 1
$UpperLimit = 5500

$RandomNumber = Random($LowerLimit,$UpperLimit,1)

GUICreate("RandomNumber", 100, 100)
GUISetState(@SW_SHOW)
GUICtrlCreateLabel($RandomNumber, 40, 5)
$Button1=GUICtrlCreateButton("Next", 20, 45)
$Button2=GUICtrlCreateButton("Exit", 60, 45)

While 1
        $msg = GUIGetMsg()
        Switch $msg
        Case $Button1
        randomnumber()
        Case $Button2
        Exit
        EndSwitch
        If $msg = $GUI_EVENT_CLOSE Then ExitLoop
    WEnd
    GUIDelete()
EndFunc

tried search and even help to no avail

thanks in advance

Edited by snowman533

Intermediate AutoIt/Autohotkey User

Link to comment
Share on other sites

You can do it like this in the second message loop in the randomnumber function:

Func randomnumber()

   Local $hSecondGUI = GUICreate("RandomNumber", 100, 100)
   GUISwitch($hSecondGUI)
   .
   .

   Switch GUIGetMsg()
       Case $Button1
           GUIDelete($hSecondGUI)
           randomnumber()
        
    
       Case $Button2, $GUI_EVENT_CLOSE
           ExitLoop
   EndSwitch
...
EndFunc
Edited by Authenticity
Link to comment
Share on other sites

See if it can help you:

#include <GuiConstants.au3>

Dim $hGUI1 = GUICreate('GUI1', 200, 200)
Dim $Button1 = GUICtrlCreateButton('Button1', 65, 90, 70, 25)

GUISetState()

While 1
    Switch GUIGetMsg()
        Case $Button1
            Do
                Sleep(20)
            Until _CallGUI2()
    
        Case $GUI_EVENT_CLOSE
            GUIDelete($hGUI1)
            ExitLoop
    EndSwitch
    Sleep(20)
WEnd


Func _CallGUI2()
    Local $hGUI2 = GUICreate('GUI2', 200, 200, 20, 20, -1, -1, $hGUI1)
    Local $Button2 = GUICtrlCreateButton('Button2', 65, 90, 70, 25)
    GUISetState()
    
    While 1
        Switch GUIGetMsg()
            Case $Button2
                GUIDelete($hGUI2)
                Return False
                
            Case $GUI_EVENT_CLOSE
                GUIDelete($hGUI2)
                Return True
        EndSwitch
        Sleep(20)
    WEnd
EndFunc
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...