Student_coder

Help Regarding Close Button

5 posts in this topic

#1 ·  Posted (edited)

Hi everyone,

Am having 3 forms - 1 main_form, a_form and b_form. All of them have close button. In the main_form there is two button besides close button - butn1 and butn2. 

If we select butn1 a_form will come else if butn2 b_form will come. When I close the main _frame everything will close which is fine.  If we click on close button in

a_form and b_form then it will close the script which is not fine. If we close a_form or b_form, a_form or b_form should close and main_form should come but it's

not happening. I have tried using while loop and switch which effects the whole code.  Is there any other way to do this??

Quote

while 1
      Switch GUIGetMsg()
         Case $GUI_EVENT_CLOSE
            GUISetState(@SW_HIDE, $delete_frm)
            GUISetState($GUI_ENABLE, $Form1)
            GUISetState(@SW_RESTORE, $Form1)
            ExitLoop

 

 

Edited by Student_coder

Share this post


Link to post
Share on other sites

The wiki has a tutorial on how to handle 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

as i already told (pm) post a runable (reproducer) script showing the issue(s).

Share this post


Link to post
Share on other sites

Student_coder,

Quote

as i already told (pm)

And as I have already told you via PM, in future do NOT PM other forum members asking for help.

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

Opt("GUIOnEventMode", 1)

Global $GUI2

global $GUI = GUICreate("Main GUI", 100, 150, 0, 0)     ;Create Main GUI
GUISetOnEvent($GUI_EVENT_CLOSE, "on_exit")

GUICtrlCreateButton("Exit", 0, 0,100,50)            ;Closing GUI go to on_exit function
GUICtrlSetOnEvent(-1, "on_exit")

GUICtrlCreateButton("GUI2", 0,50,100,50)
GUICtrlSetOnEvent(-1, "GUI2")

GUICtrlCreateButton("GUI3", 0,100,100,50)
GUICtrlSetOnEvent(-1, "GUI3")

GUISetState(@SW_SHOW)

while 1
   sleep(5)
WEnd


func GUI2()
   GUISetState(@SW_HIDE)
global $GUI2 = GUICreate("GUI2", 100, 150, 0, 0)                ;Create Second GUI
GUISetOnEvent($GUI_EVENT_CLOSE, "Close_Settings")       ;When closing GUI go to Close settings

GUICtrlCreateButton("Close GUI", 0, 0, 100,50)
GUICtrlSetOnEvent(-1, "Close_Settings")                 ;Closing button go to close settings

GUISetState(@SW_SHOW)
EndFunc

func GUI3()
   GUISetState(@SW_HIDE)
global $GUI3 = GUICreate("GUI3", 100, 150, 0, 0)                ;Create Third GUI
GUISetOnEvent($GUI_EVENT_CLOSE, "Close_Settings")       ;When closing GUI go to Close Settings

GUICtrlCreateButton("Close GUI", 0, 0, 100,50)
GUICtrlSetOnEvent(-1, "Close_Settings")                 ;Closing button go to close settings

GUISetState(@SW_SHOW)
EndFunc

func Close_Settings()
   if WinExists("GUI2") then                        ;If GUI2 existss delete it
      GUISetState(@SW_SHOW, $GUI)
      GUIDelete($GUI2)                              ;otherwise Close GUI3
   Else
     GUISetState(@SW_SHOW, $GUI)
     GUIDelete($GUI3)
   EndIf
EndFunc


func on_exit()
Exit
EndFunc

Is this what you're trying to do?
Sorry for messy code, I'm not very tidy lol.

Edit:

Just realized what you wanted to do, Edited code.
Dunno if this is the 'Best' Way to do it however it is how I would do it lol.

 

Edit2:
Lol sorry after reading your question AGAIN, I think I understand what you are trying to do. Try this code.
I will leave both here and if I have not addressed your problem hopefully you can adapt the code to fit your needs :)

 

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

Opt("GUIOnEventMode", 1)

Global $GUI2

global $GUI = GUICreate("Main GUI", 100, 150, 0, 0)     ;Create Main GUI
GUISetOnEvent($GUI_EVENT_CLOSE, "on_exit")

GUICtrlCreateButton("Exit", 0, 0,100,50)            ;Closing GUI go to on_exit function
GUICtrlSetOnEvent(-1, "on_exit")

GUICtrlCreateButton("GUI2", 0,50,100,50)
GUICtrlSetOnEvent(-1, "GUI2")

GUICtrlCreateButton("GUI3", 0,100,100,50)
GUICtrlSetOnEvent(-1, "GUI3")

GUISetState(@SW_SHOW)

while 1
   sleep(5)
WEnd


func GUI2()
global $GUI2 = GUICreate("GUI2", 100, 150, 115, 0)                ;Create Second GUI
GUISetOnEvent($GUI_EVENT_CLOSE, "CloseGUI2")       ;When closing GUI go to Close settings

GUICtrlCreateLabel("GUI2", 0, 50)
GUICtrlCreateButton("Close GUI", 0, 0, 100,50)
GUICtrlSetOnEvent(-1, "CloseGUI2")                 ;Closing button go to close settings

GUISetState(@SW_SHOW)
EndFunc

func GUI3()
global $GUI3 = GUICreate("GUI3", 100, 150, 230, 0)                ;Create Third GUI
GUISetOnEvent($GUI_EVENT_CLOSE, "CloseGUI3")       ;When closing GUI go to Close Settings

GUICtrlCreateLabel("GUI3", 0, 50)
GUICtrlCreateButton("Close GUI", 0, 0, 100,50)
GUICtrlSetOnEvent(-1, "CloseGUI3")                 ;Closing button go to close settings
GUISetState(@SW_SHOW)
EndFunc


func CloseGUI2()
GUIDelete($GUI2)
EndFunc

func CloseGUI3()
GUIDelete($GUI3)
EndFunc



func on_exit()
Exit
EndFunc


Again sorry for being messy, Its just how I work :P

Edited by Annonyreeder

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