twelo Posted April 16, 2010 Share Posted April 16, 2010 hi i have a parent gui & child gui both working fine but when i close child window and return to parent windows no controls works on parent windows expandcollapse popup#include <GUIConstants.au3> #include <WindowsConstants.au3> #include <GuiConstantsEx.au3> #include <StaticConstants.au3> #include <ButtonConstants.au3> #include <GuiMenu.au3> $PARENT = GUICreate("PARENT", 300, 300, -1, -1) $File = GUICtrlCreateMenu("File") $2ndGUI = GUICtrlCreateMenuItem("Child Win", $File) $About = GUICtrlCreateMenuItem("About", $File) $Button1 = GUICtrlCreateButton("BUTTON 1", 100, 125, 100, 50, $WS_GROUP) GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Select Case $nMsg = $GUI_EVENT_CLOSE Exit Case $nMsg = $About MsgBox(8192, "about", "Parent Child Windows") Case $nMsg = $Button1 MsgBox(8192, "1st Msg", "hello this is parent window") Case $nMsg = $2ndGUI Opt("GUIOnEventMode", 1) $CHILD = GUICreate("CHILD", 200, 200) GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEClicked") $Button2 = GUICtrlCreateButton("BUTTON 2", 50, 100, 100, 50, $WS_GROUP) GUICtrlSetOnEvent($Button2, "OKButton") GUISetState(@SW_SHOW) While 1 Sleep(1000) WEnd EndSelect WEnd Func OKButton() MsgBox(8192, "2nd Msg", "hello this is child window") EndFunc Func CLOSEClicked() GUIDelete($CHILD) GUISwitch($PARENT) EndFunc it is necessary for me to put GUISetOnEvent in child windows i tried with Opt("GUISetOnEvent", 0) GUISwitch Return in CLOSEClicked() function but none works CLOSEClicked() is not in loop so i can not use exitloop Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted April 16, 2010 Moderators Share Posted April 16, 2010 twelo,2 things wrong with that code which prevent the parent regaining control:1. You never leave the Child While...WEnd loop as you have no way of breaking out of it. Using Opt("TrayIconDebug", 1) would have made that obvious - go read about it in the Help file. 2. You set OnEvent mode for the Child GUI, but never reset MessageLoop mode. So even if the code had handed control back to the Parent, your GUIGetMsg call would always have produced 0 (Details in the Help file under <GUI Reference> ). Changing GUI modes in a single script is something to be vary wary of - you can easily end up in the wrong mode at the wrong time. If you fix those 2 problems, the code works as it should:expandcollapse popup#include <GUIConstants.au3> #include <WindowsConstants.au3> #include <GuiConstantsEx.au3> #include <StaticConstants.au3> #include <ButtonConstants.au3> #include <GuiMenu.au3> $PARENT = GUICreate("PARENT", 300, 300, -1, -1) $File = GUICtrlCreateMenu("File") $2ndGUI = GUICtrlCreateMenuItem("Child Win", $File) $About = GUICtrlCreateMenuItem("About", $File) $Button1 = GUICtrlCreateButton("BUTTON 1", 100, 125, 100, 50, $WS_GROUP) GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() if $nMsg <> 0 Then ConsoleWrite($nMsg & @CRLF) Select Case $nMsg = $GUI_EVENT_CLOSE Exit Case $nMsg = $About MsgBox(8192, "about", "Parent Child Windows") Case $nMsg = $Button1 MsgBox(8192, "1st Msg", "hello this is parent window") Case $nMsg = $2ndGUI Opt("GUIOnEventMode", 1) $CHILD = GUICreate("CHILD", 200, 200) GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEClicked") $Button2 = GUICtrlCreateButton("BUTTON 2", 50, 100, 100, 50, $WS_GROUP) GUICtrlSetOnEvent($Button2, "OKButton") GUISetState(@SW_SHOW) While WinExists("CHILD") ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< Sleep(10) WEnd EndSelect WEnd Func OKButton() MsgBox(8192, "2nd Msg", "hello this is child window") EndFunc ;==>OKButton Func CLOSEClicked() GUIDelete($CHILD) GUISwitch($PARENT) Opt("GUIOnEventMode", 0) ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< EndFunc ;==>CLOSEClickedI added the <<<<<<<<<<<<<<<<< lines. I hope that everything is clear. M23 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
twelo Posted April 16, 2010 Author Share Posted April 16, 2010 i was trying to overcome it from 2 daysnow this line works & thanks While WinExists("CHILD") i m using While WinExists($CHILD) i hope no problem with it.if $nMsg <> 0 Then ConsoleWrite($nMsg & @CRLF) after removing this line, script also works fine, i think it was only for debug info (i only removed it coz it always write something in console) Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted April 16, 2010 Moderators Share Posted April 16, 2010 twelo, You are correct on both counts. M23 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area 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