Sign in to follow this  
Followers 0
Feonixx

Window status

6 posts in this topic

#Include <GUIConstants.au3>

$main = GUICreate("Main",150,85,50,50)
$Button1 = GUICtrlCreateButton("Click for another window",5,30,140,30)
$Button2 = 0
$GUI1 = 0
GUISetState()
While 1
    
    
    While 1
        $msg = GUIGetMsg()
            Select
            Case $msg = $Button1
                GUIDelete($main)
                $GUI1 = GUICreate("Button 1 Window",150,85,100,100)
                $Button2 = GUICtrlCreateButton("Button",25,30,100,20)
                GUISetState(@SW_SHOW, $GUI1)
            Case $msg = $GUI_EVENT_CLOSE
                Exit
            EndSelect
    WEnd    

    While 1 
        $msg = GUIGetMsg()
        Select
            Case $msg = $Button2
                GUIDelete($GUI1)
                GUISetState(@SW_SHOW, $main)
        EndSelect
    WEnd        


WEnd

So basically i want it to open a window. When you click the button it will close the main one, and open a new one. When you click that windows button, it will go back to the original box. When i click the second boxes button, it opens the same form, and doesnt close :/ Any help?

Share this post


Link to post
Share on other sites



Don't delete the main GUI with GUIDelete($main), just hide it with GuiSetState(@SW_HIDE, $main).

muttley


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

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Don't delete the main GUI with GUIDelete($main), just hide it with GuiSetState(@SW_HIDE, $main).

muttley

kk, i changed to this,

#Include <GUIConstants.au3>

$main = GUICreate("Main",150,85,50,50)
$Button1 = GUICtrlCreateButton("Click for another window",5,30,140,30)
$Button2 = 0
$GUI1 = 0
GUISetState()
While 1
    
    While 1 
        $msg = GUIGetMsg()
        Select
            Case $msg = $Button1
                GUISetState(@SW_HIDE, $main)
                $GUI1 = GUICreate("Button window",400,200,50,50)
                $Button2 = GUICtrlCreateButton("Open window",50,50,200,20)
                GUISetState(@SW_SHOW, $GUI1)
            Case $msg = $GUI_EVENT_CLOSE
                Exit
        EndSelect
    Wend
            
    While 1 
        $msg = GUIGetMsg()
        Select
            Case $msg = $Button2
                GUISetState(@SW_HIDE, $GUI1)
                Sleep(100)
                GUISetState(@SW_SHOW, $main)
        EndSelect
    Wend        
WEnd

Still doesnt want to change back to the main frame :/

Edited by Feonixx

Share this post


Link to post
Share on other sites

Your code is messy, I recommend you to initialize the GUI's first, and then show/hide them accordingly, instead of creating them when you need them.

$GUI1 = GUICreate("Window #1", 100, 100)
$btn1 = GUICtrlCreateButton("Switch windows", 10, 10, 80, 80)

$GUI2 = GUICreate("Window #3", 100, 100)
$btn2 = GUICtrlCreateButton("Switch windows", 10, 10, 80, 80)

GUISetState(@SW_SHOW, $GUI1)

While 1
  Switch GUIGetMsg()
  Case $GUI_EVENT_CLOSE
    Exit
  Case $btn1
    GUISetState(@SW_HIDE, $GUI1)
    GUISetState(@SW_SHOW, $GUI2)
  Case $btn2
    GUISetState(@SW_HIDE, $GUI2)
    GUISetState(@SW_SHOW, $GUI1)
  Sleep(10)
WEnd

This does exactly what you want, but (I think) it is cleaner.

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

kk, i changed to this,

#Include <GUIConstants.au3>

$main = GUICreate("Main",150,85,50,50)
$Button1 = GUICtrlCreateButton("Click for another window",5,30,140,30)
$Button2 = 0
$GUI1 = 0
GUISetState()
While 1
    
    While 1 
        $msg = GUIGetMsg()
        Select
            Case $msg = $Button1
                GUISetState(@SW_HIDE, $main)
                $GUI1 = GUICreate("Button window",400,200,50,50)
                $Button2 = GUICtrlCreateButton("Open window",50,50,200,20)
                GUISetState(@SW_SHOW, $GUI1)
            Case $msg = $GUI_EVENT_CLOSE
                Exit
        EndSelect
    Wend
            
    While 1 
        $msg = GUIGetMsg()
        Select
            Case $msg = $Button2
                GUISetState(@SW_HIDE, $GUI1)
                Sleep(100)
                GUISetState(@SW_SHOW, $main)
        EndSelect
    Wend        
WEnd

Still doesnt want to change back to the main frame :/

Yeah, the logic is still broke because there is no ExitLoop for either of the message loops. Add the ExitLoop to the button cases, and you should delete rather than hide the second GUI because every time you go back to it you are creating a new one:
#Include <GUIConstants.au3>

$main = GUICreate("Main",150,85,50,50)
$Button1 = GUICtrlCreateButton("Click for another window",5,30,140,30)
$Button2 = 0
$GUI1 = 0
GUISetState()
While 1
    
    While 1
        $msg = GUIGetMsg()
        Select
            Case $msg = $Button1
                GUISetState(@SW_HIDE, $main)
                $GUI1 = GUICreate("Button window",400,200,50,50)
                $Button2 = GUICtrlCreateButton("Open window",50,50,200,20)
                GUISetState(@SW_SHOW, $GUI1)
                ExitLoop
            Case $msg = $GUI_EVENT_CLOSE
                Exit
        EndSelect
    Wend
            
    While 1
        $msg = GUIGetMsg()
        Select
            Case $msg = $Button2
                GUIDelete($GUI1)
                Sleep(100)
                GUISetState(@SW_SHOW, $main)
                ExitLoop
        EndSelect
    Wend        
WEnd

muttley

Edit: Quoted the wrong post at the top.

Edited by PsaltyDS

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

Share this post


Link to post
Share on other sites

Haha thanks guys. Seems real difficult until someone shows me how :) the defining before i need them definitely is a confusion saver, and yea i never thought about the delete, itd keep hiding like 100's of windows muttley

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
Sign in to follow this  
Followers 0