Punnichio Posted December 6, 2006 Share Posted December 6, 2006 (edited) Hello there fellas! I've stumbled upon a simple problem: I have a parent GUI, and 3 children, but when I hit a "Hide" button on a child GUI, the whole application shuts down...how can I prevent this from happening? (I only want the particular child to close) Thanks in advance Edited December 6, 2006 by Punnichio Link to comment Share on other sites More sharing options...
GaryFrost Posted December 6, 2006 Share Posted December 6, 2006 Hello there fellas! I've stumbled upon a simple problem: I have a parent GUI, and 3 children, but when I hit a "Hide" button on a child GUI, the whole application shuts down...how can I prevent this from happening? (I only want the particular child to close)Thanks in advance With-out short script which can duplicate the problem I would need to get my crystal ball, but it's broken at this time. SciTE for AutoItDirections for Submitting Standard UDFs Don't argue with an idiot; people watching may not be able to tell the difference. Link to comment Share on other sites More sharing options...
Punnichio Posted December 6, 2006 Author Share Posted December 6, 2006 I'm sorry to hear that, I hope you get it fixed soon, in the meantime here's the code... If $msg = $Button_1 Then GuiSetState( @SW_SHOW, $child_[1]) If $msg = $Button_2 Then GuiSetState( @SW_SHOW, $child_[2]) If $msg = $Button_3 Then GuiSetState( @SW_SHOW, $child_[3]) If $msg = $othermenuitem Then GUISetState( @SW_SHOW, $child_[4]) If $msg = $Button_13 Then Winclose("Section1") If $msg = $Button_14 Then Winclose("Section2") If $msg = $Button_15 Then Winclose("Shutdown") Example: when I hit "button_15" it closes the whole GUI instead of only the GUI with the title "Shutdown" Link to comment Share on other sites More sharing options...
GaryFrost Posted December 6, 2006 Share Posted December 6, 2006 I'm sorry to hear that, I hope you get it fixed soon, in the meantime here's the code... If $msg = $Button_1 Then GuiSetState( @SW_SHOW, $child_[1]) If $msg = $Button_2 Then GuiSetState( @SW_SHOW, $child_[2]) If $msg = $Button_3 Then GuiSetState( @SW_SHOW, $child_[3]) If $msg = $othermenuitem Then GUISetState( @SW_SHOW, $child_[4]) If $msg = $Button_13 Then Winclose("Section1") If $msg = $Button_14 Then Winclose("Section2") If $msg = $Button_15 Then Winclose("Shutdown") Example: when I hit "button_15" it closes the whole GUI instead of only the GUI with the title "Shutdown" Still guessing here, so why not use GuiDelete($WinHandle) Assuming you created the gui window and captured the handle I.E. $WinHandle = GuiCreate("ShutDown") SciTE for AutoItDirections for Submitting Standard UDFs Don't argue with an idiot; people watching may not be able to tell the difference. Link to comment Share on other sites More sharing options...
Punnichio Posted December 6, 2006 Author Share Posted December 6, 2006 GUIdelete did the trick superb, thanks alot Link to comment Share on other sites More sharing options...
Pa Callender Posted December 8, 2006 Share Posted December 8, 2006 My guess as to why this happens is that WinClose probably sends $GUI_EVENT_CLOSE to the window. And because you probably have one whole loop and GUIGetMsg returns messages for all windows, your While 1 ... WEnd loop picks this p and assumes it is for the parent GUI, therefore closes it and closes the children. [size="4"]YOU SHALL NOT PARSE!![/size] Link to comment Share on other sites More sharing options...
JohnBailey Posted February 22, 2007 Share Posted February 22, 2007 Is there an example file somewhere of closing child windows using their X in the title bar? A decision is a powerful thing Link to comment Share on other sites More sharing options...
Valuater Posted February 22, 2007 Share Posted February 22, 2007 maybe... expandcollapse popup;==================================================== ;============= Example of a child window ============ ;==================================================== ; AutoIt version: 3.0.103 ; Language: English ; Author: "SlimShady" ; ; ---------------------------------------------------------------------------- ; Script Start ; ---------------------------------------------------------------------------- ;Include constants #include <GUIConstants.au3> ;Initialize variables Global $IniFile Global $GUIWidth Global $GUIHeight $GUIWidth = 250 $GUIHeight = 250 ;Create main/parent window $ParentWin = GUICreate("Parent GUI", $GUIWidth, $GUIHeight) ;Save the position of the parent window $ParentWin_Pos = WinGetPos($ParentWin, "") ;Show the parent window/Make the parent window visible GUISetState(@SW_SHOW) ;Create child window and add the parameter to make it the child of the parent window $ChildWin = GUICreate("Child GUI", $GUIWidth, $GUIHeight, $ParentWin_Pos[0] + 100, $ParentWin_Pos[1] + 100, -1, -1, $ParentWin) ;Show the child window/Make the child window visible GUISetState(@SW_SHOW) ;Switch to the parent window GUISwitch($ParentWin) ;Loop until: ;- user presses Esc when focused to the parent window ;- user presses Alt+F4 when focused to the parent window ;- user clicks the close button of the parent window While 1 ;After every loop check if the user clicked something in the GUI windows $msg = GUIGetMsg(1) Select ;Check if user clicked on a close button of any of the 2 windows Case $msg[0] = $GUI_EVENT_CLOSE ;Check if user clicked on the close button of the child window If $msg[1] = $ChildWin Then MsgBox(64, "Test", "Child GUI will now close.") ;Switch to the child window GUISwitch($ChildWin) ;Destroy the child GUI including the controls GUIDelete() ;Check if user clicked on the close button of the parent window ElseIf $msg[1] = $ParentWin Then MsgBox(64, "Test", "Parent GUI will now close.") ;Switch to the parent window GUISwitch($ParentWin) ;Destroy the parent GUI including the controls GUIDelete() ;Exit the script Exit EndIf EndSelect WEnd 8) Link to comment Share on other sites More sharing options...
JohnBailey Posted February 22, 2007 Share Posted February 22, 2007 (edited) Thank you!! That was driving me nuts. I just reread up on the GUIGetMsg(1). Before I couldn't understand it's usage. Now I see more how it's setting the array. With this method there is no way to create the child window "after the fact." I'm just thinking for future usage. Just curious and trying to understand all the ins-and-outs.Addition: Thank you furthermore, this has made me understand and use GUIState's optional parameter. I'm really understanding the GUIGetMsg more now. It's pretty sweet. Edited February 22, 2007 by JohnBailey A decision is a powerful thing Link to comment Share on other sites More sharing options...
Valuater Posted February 22, 2007 Share Posted February 22, 2007 after the fact expandcollapse popup#include <GUIConstants.au3> ;Initialize variables Global $IniFile, $ChildWin Global $GUIWidth = 250 Global $GUIHeight = 250 $ParentWin = GUICreate("Parent GUI", $GUIWidth, $GUIHeight) $ParentWin_Pos = WinGetPos($ParentWin, "") $btn = GUICtrlCreateButton("Child", 50, 50, 80, 25) GUISetState(@SW_SHOW) While 1 $msg = GUIGetMsg() If $msg = -3 And WinActive($ParentWin) Then Exit If $msg = $btn Then MakeChild() WEnd Func MakeChild() $ChildWin = GUICreate("Child GUI", $GUIWidth, $GUIHeight, $ParentWin_Pos[0] + 100, $ParentWin_Pos[1] + 100, -1, -1, $ParentWin) GUISetState(@SW_SHOW) While 2 $msg2 = GUIGetMsg() If $msg2 = -3 And WinActive($ChildWin) Then GUIDelete($ChildWin) ExitLoop EndIf WEnd EndFunc ;==>MakeChild I just butchurd the prev code.... there are many ways to do this 8) Link to comment Share on other sites More sharing options...
JohnBailey Posted February 23, 2007 Share Posted February 23, 2007 While 1 $msg = GUIGetMsg() If $msg = -3 And WinActive($ParentWin) Then Exit If $msg = $btn Then MakeChild() WEnd I looked through GUIConstantsEx.au3. So the -3 means $GUI_EVENT_CLOSE? This is so much shorter than typing that out, but I just wanted to verify that it means that. I really want to understand the meaning of everything you wrote out. You and xCal provided GREAT examples! These should be in the help file, in my opinion. A decision is a powerful thing Link to comment Share on other sites More sharing options...
Valuater Posted February 23, 2007 Share Posted February 23, 2007 So the -3 means $GUI_EVENT_CLOSE?yes...Welcome8) Link to comment Share on other sites More sharing options...
Emiel Wieldraaijer Posted February 23, 2007 Share Posted February 23, 2007 HI Look at the source of the inventorgamei found it very usefull http://www.autoitscript.com/forum/index.php?showtopic=20028Emiel Best regards,Emiel Wieldraaijer Link to comment Share on other sites More sharing options...
JohnBailey Posted February 26, 2007 Share Posted February 26, 2007 HI Look at the source of the inventorgamei found it very usefull http://www.autoitscript.com/forum/index.php?showtopic=20028EmielEmiel, I can't seem to find the source at that link. I flipped through the thread and still nothing. I'm probably missing something obvious. Where is it on there? A decision is a powerful thing Link to comment Share on other sites More sharing options...
Emiel Wieldraaijer Posted February 26, 2007 Share Posted February 26, 2007 OK .. when you download the inventor game the source is included .. but here's the solution Lets say you create a menu with special thanks to other people who helped you and we call it credit expandcollapse popupinclude <GUIConstants.au3> Opt("TrayMenuMode", 1) Opt("GUIResizeMode", 1) AutoItSetOption("TrayIconHide", 1) $Parent = GuiCreate("Parent" , 250, 150) $Filemenu = GUICtrlCreateMenu ("&File") $Helpmenu = GUICtrlCreateMenu ("&?") $FilemenuExit = GUICtrlCreateMenuitem ("&Exit", $filemenu) $HelpmenuCredits = GUICtrlCreateMenuitem ("&Credit", $helpmenu) GUICtrlCreateLabel ("Nothing here", 20,40,150,20) GUICtrlCreateLabel ("Select menu ? and click credits", 20,60,150,20) GUISetState() Func Credits () GuiSetState (@SW_DISABLE, $Parent) $Child = GuiCreate("Say Thnx",200,80,-1,-1) $ChildFilemenu = GUICtrlCreateMenu ("&File") $ChildFilemenuExit = GUICtrlCreateMenuitem ("&Exit", $ChildFilemenu) GUICtrlCreateLabel ("i would like to say thanks to Emiel", 20,40) GUISetState(@SW_SHOW, $Child) While 2 $msgchild = GUIGetMsg () If $msgchild = $GUI_EVENT_CLOSE then ExitLoop EndIf Select case $msgchild = $ChildFilemenuExit Exitloop EndSelect Wend GuiDelete ($Child) GuiSetState (@SW_ENABLE, $Parent) GuiSetState (@SW_RESTORE, $Parent) GuiSwitch ($Parent) EndFunc While 1 $msg = GUIGetMsg () If $msg = $GUI_EVENT_CLOSE then Exit EndIf Select case $msg = $FilemenuExit exit case $msg = $HelpmenuCredits Credits () Endselect WEnd Best regards,Emiel Wieldraaijer Link to comment Share on other sites More sharing options...
JohnBailey Posted February 26, 2007 Share Posted February 26, 2007 Yes definite props to those who give me such awesome direction! Learning the syntax of and using autoit is/has been wonderful. Xcal, Valuater, and yourself so far have been so helpful in me understanding how to do child window close (and more as a result).Why would you suggest this method over Valuater's or SlimShady's? A decision is a powerful thing Link to comment Share on other sites More sharing options...
Emiel Wieldraaijer Posted February 26, 2007 Share Posted February 26, 2007 My solution is not better.... I think the other solutions are better but also more complex.. I believe .. we should start with the basics and learn .. thats my opinion Emiel Best regards,Emiel Wieldraaijer Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now