Jdavis Posted December 18, 2008 Posted December 18, 2008 (edited) In my working with parent / child windows, I've apparently broken my ability to even close the windows. I've gone over the examples and done a lot of staring, but I can't figure out where I'm going wrong.Here's what I'm testing with that replicates the issue:expandcollapse popup#include <GUIConstantsEx.au3> Opt( "MustDeclareVars", 1 ) Global $parentWindow, $childWindow, $button, $parentWindowWidth = 600, $parentWindowHeight = 600 _createParentWindow() While 1 Local $guiMsg $guiMsg = GUIGetMsg( 1 ) Select Case $guiMsg[0] = $button _createChildWindow() Case $guiMsg[0] = $GUI_EVENT_CLOSE If $guiMsg[1] = $childWindow Then GUISwitch( $childWindow ) GUIDelete() ElseIf $guiMsg[1] = $parentWindow Then GUIDelete( $parentWindow ) GUIDelete() Exit EndIf EndSelect WEnd Func _createParentWindow( ) $parentWindow = GUICreate( "Parent Window", $parentWindowWidth, $parentWindowHeight ) $button = GUICtrlCreateButton( "Click Me!", 250, 300, 100, 20 ) GUISetState( @SW_SHOW ) EndFunc Func _createChildWindow( ) Local $parentWindowPosition, $childWindowWidth = 300, $childWindowHeight = 300 $parentWindowPosition = WinGetPos( $parentWindow, '' ) $childWindow = GUICreate( "Child Window", $parentWindowWidth / 2, $parentWindowHeight / 2, $parentWindowPosition[0] + ( $parentWindowWidth / 2 ) - ( $childWindowWidth / 2 ), $parentWindowPosition[1] + ( $parentWindowHeight / 2 ) - ( $childWindowHeight / 2 ), -1, -1, $parentWindow ) GUISetState( @SW_SHOW ) GUISwitch( $parentWindow ) EndFuncI have this feeling it's something incredibly simple that I'm overlooking.Any ideas?EditDoh!Why is it that I discover the problem shortly after asking! Edited December 18, 2008 by Jdavis
Skruge Posted December 18, 2008 Posted December 18, 2008 Edit Doh! Why is it that I discover the problem shortly after asking!You discovered the problem, but did you discover a solution? The problem is, you're reusing $childWindow, thus losing the handles of all previously created child windows. Since GUIGetMsg(1) gives you the window handle, you can close it directly: Select Case $guiMsg[0] = $button _createChildWindow() Case $guiMsg[0] = $GUI_EVENT_CLOSE If $guiMsg[1] = $parentWindow Then GUIDelete($parentWindow) Exit Else GUIDelete($guiMsg[1]) EndIf EndSelect This allows you to close orphaned windows, but it will not let you do anything else with them. In order to do this, I recommend maintaining a list of child window handles. [font="Tahoma"]"Tougher than the toughies and smarter than the smarties"[/font]
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