Sign in to follow this  
Followers 0
Firstone

Child and Parent Question

7 posts in this topic

#1 ·  Posted (edited)

Hi

How do i make my child window independent of my parent window?

Whenever I close or minimize my child window it does it to the parent as well. But the script remains active, as its still in the system tray.

I would like to know how to make it so if I minimize/close the child window, only the child window closes and the parent window remains up.

I've tried writing down the parent handle in the guicreate part and writing down no parent. They had the same results.

I've also used the search engine, and they seemed to be talking about something slightly different I think. Not sure as I'm new at this.

Also when explaining it, could you dumb it up a bit for me. Since I'm new to programming. :)

Thanks

EDIT: Forgot to add I'm using GUIDelete to close the child window.

Edited by Firstone

Share this post


Link to post
Share on other sites



Firstone,

Please post your code. If you are using GUIGetMessage mode, it sounds to me as if you need to use the "advanced" parameter to determine which window is sending the close/minimise message. But let us see what you have before we jump to conclusions. :)

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

#3 ·  Posted (edited)

Hi thx for ur reply.

I'm using GUIOnEvent

;;; #INCLUDE# ===============================================================================

#include <Array.au3>

#include <File.au3>

#include <GUIConstantsEx.au3>

#include <String.au3>

#include <WindowsConstants.au3>

;;; #OPTIONS# ===============================================================================

Opt("GUIOnEventMode", 1)

;;; #VARIABLES# =============================================================================

Global $MainGUI

Global $AddPupilsGUI

Global $SetTimerGUI

Global $AboutGUI

;;; #GUI CONTROLS# ==========================================================================

$MainGUI = GUICreate("Trainer", 400, 450)

$Edit = GUICtrlCreateEdit("", 0, 0, 400, 340)

GUICtrlSetState($Edit, $GUI_DISABLE)

$FileMenu = GUICtrlCreateMenu("File")

$PupilsItem = GUICtrlCreateMenuItem("Add Pupils", $FileMenu)

$DatabaseItem = GUICtrlCreateMenuItem("Open Data Base", $FileMenu)

$ExitItem = GUICtrlCreateMenuItem("Exit",$FileMenu)

$OptionsMenu = GUICtrlCreateMenu("Options")

$TimerItem = GUICtrlCreateMenuItem("Timer Settings", $OptionsMenu)

$HelpMenu = GUICtrlCreateMenu("Help")

$AboutItem = GUICtrlCreateMenuItem("About Brute Trainer", $HelpMenu)

$Fighting = GUICtrlCreateLabel("", 20, 350)

$ETA = GUICtrlCreateLabel("", 20, 370)

$Progress = GUICtrlCreateProgress(20, 395, 260, 20)

$StartButton = GUICtrlCreateButton("Start", 300, 350, 80, 30)

$CancelButton = GUICtrlCreateButton("Cancel", 300, 390, 80, 30)

;;; #GUI EVENTS# =============================================================================

GUISetOnEvent($GUI_EVENT_CLOSE, "Close", $MainGUI)

GUICtrlSetOnEvent($ExitItem, "Close")

GUICtrlSetOnEvent($PupilsItem, "AddPupils")

GUICtrlSetOnEvent($DatabaseItem, "GetDatabase")

GUICtrlSetOnEvent($TimerItem, "SetTimer")

GUICtrlSetOnEvent($AboutItem, "About")

GUISetState(@SW_SHOW, $MainGUI)

;;; #Functions# ================================================================================

Func AddPupils()

GUISetState(@SW_DISABLE, $MainGUI)

$AddPupilsGUI = GUICreate("Add Pupils", 300, 400, -1, -1, $GUI_SS_DEFAULT_GUI, -1, $MainGUI)

$PupilsEdit = GUICtrlCreateEdit("", 0, 0, 300, 400)

GUISetOnEvent($GUI_EVENT_CLOSE, "CloseChild", $AddPupilsGUI)

GUISetState(@SW_SHOW, $AddPupilsGUI)

EndFunc

Func GetDatabase()

EndFunc

Func SetTimer()

GUISetState(@SW_DISABLE, $MainGUI)

$SetTimerGUI = GUICreate("Timer Settings", 200, 200, -1, -1, $GUI_SS_DEFAULT_GUI, -1, $MainGUI)

GUICtrlCreateLabel("Start Timer:", 20, 25)

$StartInput = GUICtrlCreateInput("02:30", 80, 20, 40, 20)

$ShutdownCheckbox = GUICtrlCreateCheckbox("Shutdown PC When Finished", 20, 50)

$ForceCheckbox = GUICtrlCreateCheckbox("Force Shutdown", 20, 75)

GUISetOnEvent($GUI_EVENT_CLOSE, "CloseChild", $SetTimerGUI)

GUISetState(@SW_SHOW, $SetTimerGUI)

EndFunc

Func About()

GUISetState(@SW_DISABLE, $MainGUI)

$AboutGUI = GUICreate("About", 200, 100, -1, -1, $GUI_SS_DEFAULT_GUI, -1, $MainGUI)

GUICtrlCreateLabel("Trainer.", 20, 20, 150, 50)

GUISetOnEvent($GUI_EVENT_CLOSE, "CloseChild", $AboutGUI)

GUISetState(@SW_SHOW, $AboutGUI)

EndFunc

Func CloseChild()

GUIDelete($AddPupilsGUI)

GUIDelete($SetTimerGUI)

GUIDelete($AboutGUI)

GUISetState(@SW_ENABLE, $MainGUI)

EndFunc

Func Close()

Exit

EndFunc

While 1

Sleep(1000)

WEnd

Edited by Firstone

Share this post


Link to post
Share on other sites

Firstone,

The problem is the same - just the GUI mode differs!

You need to define a function for each of your child windows so that when the close/minimise button is clicked it knows what to do. I have added such a function for the [X] button of the AddPupils GUI which should let you develop the others (look for the <<<<<<<<<<<):

;;; #INCLUDE# ===============================================================================
#include <Array.au3>
#include <File.au3>
#include <GUIConstantsEx.au3>
#include <String.au3>
#include <WindowsConstants.au3>

;;; #OPTIONS# ===============================================================================
Opt("GUIOnEventMode", 1)

;;; #VARIABLES# =============================================================================
Global $MainGUI
Global $AddPupilsGUI
Global $SetTimerGUI
Global $AboutGUI

;;; #GUI CONTROLS# ==========================================================================
$MainGUI = GUICreate("Trainer", 400, 450)
$Edit = GUICtrlCreateEdit("", 0, 0, 400, 340)
GUICtrlSetState($Edit, $GUI_DISABLE)
$FileMenu = GUICtrlCreateMenu("File")
$PupilsItem = GUICtrlCreateMenuItem("Add Pupils", $FileMenu)
$DatabaseItem = GUICtrlCreateMenuItem("Open Data Base", $FileMenu)
$ExitItem = GUICtrlCreateMenuItem("Exit",$FileMenu)
$OptionsMenu = GUICtrlCreateMenu("Options")
$TimerItem = GUICtrlCreateMenuItem("Timer Settings", $OptionsMenu)
$HelpMenu = GUICtrlCreateMenu("Help")
$AboutItem = GUICtrlCreateMenuItem("About Brute Trainer", $HelpMenu)
$Fighting = GUICtrlCreateLabel("", 20, 350)
$ETA = GUICtrlCreateLabel("", 20, 370)
$Progress = GUICtrlCreateProgress(20, 395, 260, 20)
$StartButton = GUICtrlCreateButton("Start", 300, 350, 80, 30)
$CancelButton = GUICtrlCreateButton("Cancel", 300, 390, 80, 30)

;;; #GUI EVENTS# =============================================================================
GUISetOnEvent($GUI_EVENT_CLOSE, "Close", $MainGUI)
GUICtrlSetOnEvent($ExitItem, "Close")
GUICtrlSetOnEvent($PupilsItem, "AddPupils")
GUICtrlSetOnEvent($DatabaseItem, "GetDatabase")
GUICtrlSetOnEvent($TimerItem, "SetTimer")
GUICtrlSetOnEvent($AboutItem, "About")
GUISetState(@SW_SHOW, $MainGUI)

;;; #Functions# ================================================================================
Func AddPupils()
GUISetState(@SW_DISABLE, $MainGUI)
$AddPupilsGUI = GUICreate("Add Pupils", 300, 400, -1, -1, $GUI_SS_DEFAULT_GUI, -1, $MainGUI)
$PupilsEdit = GUICtrlCreateEdit("", 0, 0, 300, 400)
GUISetOnEvent($GUI_EVENT_CLOSE, "CloseChild", $AddPupilsGUI)
GUISetState(@SW_SHOW, $AddPupilsGUI)
GUISetOnEvent($GUI_EVENT_CLOSE, "AddPupilsClose", $AddPupilsGUI) ; <<<<<<<<<< Added
EndFunc

Func GetDatabase()
EndFunc

Func SetTimer()
GUISetState(@SW_DISABLE, $MainGUI)
$SetTimerGUI = GUICreate("Timer Settings", 200, 200, -1, -1, $GUI_SS_DEFAULT_GUI, -1, $MainGUI)
GUICtrlCreateLabel("Start Timer:", 20, 25)
$StartInput = GUICtrlCreateInput("02:30", 80, 20, 40, 20)
$ShutdownCheckbox = GUICtrlCreateCheckbox("Shutdown PC When Finished", 20, 50)
$ForceCheckbox = GUICtrlCreateCheckbox("Force Shutdown", 20, 75)
GUISetOnEvent($GUI_EVENT_CLOSE, "CloseChild", $SetTimerGUI)
GUISetState(@SW_SHOW, $SetTimerGUI)
EndFunc

Func About()
GUISetState(@SW_DISABLE, $MainGUI)
$AboutGUI = GUICreate("About", 200, 100, -1, -1, $GUI_SS_DEFAULT_GUI, -1, $MainGUI)
GUICtrlCreateLabel("Trainer.", 20, 20, 150, 50)
GUISetOnEvent($GUI_EVENT_CLOSE, "CloseChild", $AboutGUI)
GUISetState(@SW_SHOW, $AboutGUI)
EndFunc

Func CloseChild()
GUIDelete($AddPupilsGUI)
GUIDelete($SetTimerGUI)
GUIDelete($AboutGUI)
GUISetState(@SW_ENABLE, $MainGUI)
EndFunc

Func Close()
Exit
EndFunc

Func AddPupilsClose()  ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<  Added
    GUIDelete($AddPupilsGUI)
    GUISetState(@SW_ENABLE, $MainGUI)
EndFunc

While 1
Sleep(1000)
WEnd

Please ask again if you have any problems with the other GUIs.

M23

P.S. It makes it easier to read code if you use Code tags. Put [autoit ] before and [/autoit ] after your posted code (but omit the trailing space - it is only there so the tags display here).


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)

The main GUI doesn't minimize with the child, it just falls behind other windows when you minimize the child because it is disabled.

The main problem with your Close function is not that you have to break it out into other functions, but you have to make sure you have a valid handle when you call GuiDelete(). If the value is undefined (blank or 0) then it deletes the last used GUI (see documentation). Calling it three times is gonna delete pretty much all active GUIs. Try this if you really want to close all open children in one go. Otherwise if you want finer control, do as Melba23 suggested.

;;; #INCLUDE# ===============================================================================
#include <Array.au3>
#include <File.au3>
#include <GUIConstantsEx.au3>
#include <String.au3>
#include <WindowsConstants.au3>

;;; #OPTIONS# ===============================================================================
Opt("GUIOnEventMode", 1)

;;; #VARIABLES# =============================================================================
Global $MainGUI = 0
Global $AddPupilsGUI = 0
Global $SetTimerGUI = 0
Global $AboutGUI = 0

;;; #GUI CONTROLS# ==========================================================================
$MainGUI = GUICreate("Trainer", 400, 450)
$Edit = GUICtrlCreateEdit("", 0, 0, 400, 340)
GUICtrlSetState($Edit, $GUI_DISABLE)
$FileMenu = GUICtrlCreateMenu("File")
$PupilsItem = GUICtrlCreateMenuItem("Add Pupils", $FileMenu)
$DatabaseItem = GUICtrlCreateMenuItem("Open Data Base", $FileMenu)
$ExitItem = GUICtrlCreateMenuItem("Exit", $FileMenu)
$OptionsMenu = GUICtrlCreateMenu("Options")
$TimerItem = GUICtrlCreateMenuItem("Timer Settings", $OptionsMenu)
$HelpMenu = GUICtrlCreateMenu("Help")
$AboutItem = GUICtrlCreateMenuItem("About Brute Trainer", $HelpMenu)
$Fighting = GUICtrlCreateLabel("", 20, 350)
$ETA = GUICtrlCreateLabel("", 20, 370)
$Progress = GUICtrlCreateProgress(20, 395, 260, 20)
$StartButton = GUICtrlCreateButton("Start", 300, 350, 80, 30)
$CancelButton = GUICtrlCreateButton("Cancel", 300, 390, 80, 30)

;;; #GUI EVENTS# =============================================================================
GUISetOnEvent($GUI_EVENT_CLOSE, "Close", $MainGUI)
GUICtrlSetOnEvent($ExitItem, "Close")
GUICtrlSetOnEvent($PupilsItem, "AddPupils")
GUICtrlSetOnEvent($DatabaseItem, "GetDatabase")
GUICtrlSetOnEvent($TimerItem, "SetTimer")
GUICtrlSetOnEvent($AboutItem, "About")
GUISetState(@SW_SHOW, $MainGUI)

;;; #Functions# ================================================================================
Func AddPupils()
    GUISetState(@SW_DISABLE, $MainGUI)
    $AddPupilsGUI = GUICreate("Add Pupils", 300, 400, -1, -1, $GUI_SS_DEFAULT_GUI, -1, $MainGUI)
    $PupilsEdit = GUICtrlCreateEdit("", 0, 0, 300, 400)
    GUISetOnEvent($GUI_EVENT_CLOSE, "CloseChild", $AddPupilsGUI)
    GUISetState(@SW_SHOW, $AddPupilsGUI)
EndFunc   ;==>AddPupils

Func GetDatabase()
EndFunc   ;==>GetDatabase

Func SetTimer()
    GUISetState(@SW_DISABLE, $MainGUI)
    $SetTimerGUI = GUICreate("Timer Settings", 200, 200, -1, -1, $GUI_SS_DEFAULT_GUI, -1, $MainGUI)
    GUICtrlCreateLabel("Start Timer:", 20, 25)
    $StartInput = GUICtrlCreateInput("02:30", 80, 20, 40, 20)
    $ShutdownCheckbox = GUICtrlCreateCheckbox("Shutdown PC When Finished", 20, 50)
    $ForceCheckbox = GUICtrlCreateCheckbox("Force Shutdown", 20, 75)
    GUISetOnEvent($GUI_EVENT_CLOSE, "CloseChild", $SetTimerGUI)
    GUISetState(@SW_SHOW, $SetTimerGUI)
EndFunc   ;==>SetTimer

Func About()
    GUISetState(@SW_DISABLE, $MainGUI)
    $AboutGUI = GUICreate("About", 200, 100, -1, -1, $GUI_SS_DEFAULT_GUI, -1, $MainGUI)
    GUICtrlCreateLabel("Trainer.", 20, 20, 150, 50)
    GUISetOnEvent($GUI_EVENT_CLOSE, "CloseChild", $AboutGUI)
    GUISetState(@SW_SHOW, $AboutGUI)
EndFunc   ;==>About

Func CloseChild()
    If $AddPupilsGUI Then GUIDelete($AddPupilsGUI)
    $AddPupilsGUI = 0
    If $SetTimerGUI Then GUIDelete($SetTimerGUI)
    $SetTimerGUI = 0
    If $AboutGUI Then GUIDelete($AboutGUI)
    $AboutGUI = 0
    GUISetState(@SW_ENABLE, $MainGUI)
    WinActivate($MainGUI)
EndFunc   ;==>CloseChild

Func Close()
    Exit
EndFunc   ;==>Close

While 1
    Sleep(1000)
WEnd
Edited by wraithdu

Share this post


Link to post
Share on other sites

Thanks It worked perfectly. Didn't see that part to clearly in the help file hehe.

I decided to go with placing it all in one function. Looks neater that way. :)

Also I was unsure how to post it on forum with the autoit feature. When I tried earlier it place it all on one line.

Thanks again!

Share this post


Link to post
Share on other sites

Well, when a Mommy GUI and a Daddy GUI love each other very much, they decide to get together and...

Oh, your question has already been answered.

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