Jump to content

Help Regarding Close Button


Recommended Posts

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
Link to comment
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 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

  • Moderators

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

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

Link to comment
Share on other sites

#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
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...