lgnihlman Posted January 9, 2010 Share Posted January 9, 2010 I'm having trouble to detect when the child GUI is closed. When closing the child the parent gui also closes, I need a way to detect mouse and kybd actions in the child gui without affecting the parent gui. Does someone have any ideas to fix this, thanks? Here's my script: #include <GuiConstants.au3> #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #NoTrayIcon $script_title = "2win" $gmain=GuiCreate($script_title, 606, 500) $btn_run = GuiCtrlCreateButton("Action", 244, 444, 97, 25,$BS_DEFPUSHBUTTON) GUICtrlCreateMenu("Information",300,200) $filemenu = GUICtrlCreateMenu ("&File") $statmenu = GUICtrlCreateMenu ("&Statistics") $printer = GUICtrlCreateMenuitem ("&Printer",$filemenu) $close = GUICtrlCreateMenuitem ("&Exit Alt+F4",$filemenu) $stat= GUICtrlCreateMenuitem ("&Complete",$statmenu) $stat2= GUICtrlCreateMenuitem ("&Sum",$statmenu) $gchild=GuiCreate($script_title&" child", 306, 300,-1,-1,-1,-1,$gmain) GuiSetState(@SW_SHOW,$gmain) While 1 $msg = GUIGetMsg() Select Case $msg = $btn_run MsgBox(16,"Action","action") Case $msg = $printer MsgBox(32, "Printer", "printer") Case $msg = $stat MsgBox(32, "Stat", "stat") Case $msg = $stat2 $tst=GUISetState(@SW_SHOW,$gchild) Case $msg = $close ExitLoop Case $msg = $GUI_EVENT_CLOSE ExitLoop Case Else EndSelect WEnd Exit Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted January 9, 2010 Moderators Share Posted January 9, 2010 lgnihlman,You need to use the "advanced" parameter of GUIGetMsg - look it up the details in the Help file. Then you can use code like this - look for my comments:expandcollapse popup#include <GuiConstants.au3> #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #NoTrayIcon $script_title = "2win" $gmain = GUICreate($script_title, 606, 500) $btn_run = GUICtrlCreateButton("Action", 244, 444, 97, 25, $BS_DEFPUSHBUTTON) GUICtrlCreateMenu("Information", 300, 200) $filemenu = GUICtrlCreateMenu("&File") $statmenu = GUICtrlCreateMenu("&Statistics") $printer = GUICtrlCreateMenuItem("&Printer", $filemenu) $close = GUICtrlCreateMenuItem("&Exit Alt+F4", $filemenu) $stat = GUICtrlCreateMenuItem("&Complete", $statmenu) $stat2 = GUICtrlCreateMenuItem("&Sum", $statmenu) GUISetState(@SW_SHOW) $gchild = GUICreate($script_title & " child", 306, 300, -1, -1, -1, -1, $gmain) ; Hide the child once created GUISetState(@SW_HIDE) While 1 $msg = GUIGetMsg() Select Case $msg = $btn_run MsgBox(16, "Action", "action") Case $msg = $printer MsgBox(32, "Printer", "printer") Case $msg = $stat MsgBox(32, "Stat", "stat") Case $msg = $stat2 ; Show the child GUISetState(@SW_SHOW, $gchild) While 1 ; Get the advanced return from GUIGetMsg $amsg = GUIGetMsg(1) ; If the message comes from the child If $amsg[1] = $gchild Then ; And it is to close If $amsg[0] = $GUI_EVENT_CLOSE Then ; Then hide the child and return to the main loop GUISetState(@SW_HIDE, $gchild) ExitLoop EndIf EndIf WEnd Case $msg = $close ExitLoop Case $msg = $GUI_EVENT_CLOSE ExitLoop EndSelect WEnd ExitI hope that is clear. Ask again if you still have any questions AFTER you have read the help file! 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...
lgnihlman Posted January 11, 2010 Author Share Posted January 11, 2010 lgnihlman, You need to use the "advanced" parameter of GUIGetMsg - look it up the details in the Help file. Then you can use code like this - look for my comments: expandcollapse popup#include <GuiConstants.au3> #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #NoTrayIcon $script_title = "2win" $gmain = GUICreate($script_title, 606, 500) $btn_run = GUICtrlCreateButton("Action", 244, 444, 97, 25, $BS_DEFPUSHBUTTON) GUICtrlCreateMenu("Information", 300, 200) $filemenu = GUICtrlCreateMenu("&File") $statmenu = GUICtrlCreateMenu("&Statistics") $printer = GUICtrlCreateMenuItem("&Printer", $filemenu) $close = GUICtrlCreateMenuItem("&Exit Alt+F4", $filemenu) $stat = GUICtrlCreateMenuItem("&Complete", $statmenu) $stat2 = GUICtrlCreateMenuItem("&Sum", $statmenu) GUISetState(@SW_SHOW) $gchild = GUICreate($script_title & " child", 306, 300, -1, -1, -1, -1, $gmain) ; Hide the child once created GUISetState(@SW_HIDE) While 1 $msg = GUIGetMsg() Select Case $msg = $btn_run MsgBox(16, "Action", "action") Case $msg = $printer MsgBox(32, "Printer", "printer") Case $msg = $stat MsgBox(32, "Stat", "stat") Case $msg = $stat2 ; Show the child GUISetState(@SW_SHOW, $gchild) While 1 ; Get the advanced return from GUIGetMsg $amsg = GUIGetMsg(1) ; If the message comes from the child If $amsg[1] = $gchild Then ; And it is to close If $amsg[0] = $GUI_EVENT_CLOSE Then ; Then hide the child and return to the main loop GUISetState(@SW_HIDE, $gchild) ExitLoop EndIf EndIf WEnd Case $msg = $close ExitLoop Case $msg = $GUI_EVENT_CLOSE ExitLoop EndSelect WEnd Exit I hope that is clear. Ask again if you still have any questions AFTER you have read the help file! M23 Many thanks M23! Now I got it. Link to comment Share on other sites More sharing options...
lgnihlman Posted January 12, 2010 Author Share Posted January 12, 2010 I have a new problem with the child GUI. When clicking the Exit button the child gui will close but if I then open the child gui again without closing the parent gui first the Exit button will not work. What's my mistake here? Any help and ideas are appreciated,thanks expandcollapse popup#include <GuiConstants.au3> #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #NoTrayIcon $script_title = "2win" $gmain=GuiCreate($script_title, 606, 500) $btn_run = GuiCtrlCreateButton("Action", 244, 444, 97, 25,$BS_DEFPUSHBUTTON) GUICtrlCreateMenu("Information",300,200) $filemenu = GUICtrlCreateMenu ("&File") $statmenu = GUICtrlCreateMenu ("&Statistics") $printer = GUICtrlCreateMenuitem ("&Printer",$filemenu) $close = GUICtrlCreateMenuitem ("&Exit Alt+F4",$filemenu) $stat= GUICtrlCreateMenuitem ("&Complete",$statmenu) $stat2= GUICtrlCreateMenuitem ("&Sum",$statmenu) GUISetState(@SW_SHOW) $gchild=GuiCreate($script_title&" child", 306, 300,-1,-1,-1,-1,$gmain) GUISetState(@SW_HIDE) While 1 $msg = GUIGetMsg() Select Case $msg = $btn_run MsgBox(16,"Action","action") Case $msg = $printer MsgBox(32, "Printer", "printer") Case $msg = $stat MsgBox(32, "Stat", "stat") Case $msg = $stat2 ; Show the child GUISetState(@SW_SHOW, $gchild) $btn_xit = GuiCtrlCreateButton("Exit", 114, 254, 97, 25,$BS_DEFPUSHBUTTON) While 1 ; Get the advanced return from GUIGetMsg $amsg = GUIGetMsg(1) ; If the message comes from the child If $amsg[1] = $gchild Then ; And it is to close If $amsg[0] = $GUI_EVENT_CLOSE Then ; Then hide the child and return to the main loop GUISetState(@SW_HIDE, $gchild) ExitLoop ElseIf $amsg[0]= $btn_xit Then ; Then hide the child and return to the main loop GUISetState(@SW_HIDE, $gchild) ExitLoop EndIf EndIf WEnd Case $msg = $close ExitLoop Case $msg = $GUI_EVENT_CLOSE ExitLoop Case Else EndSelect WEnd Exit Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted January 12, 2010 Moderators Share Posted January 12, 2010 lgnihlman,At the moment you are creating a new button in the same position each time you open the child GUI. Becasue of the way AutoIt layers the controls, the new buttons are hidden under the old ones. So you are clicking the first (and oldest) button while you have reset $btn_xit to the ControlID of the new button, which will be higher. Then when your GUIGetMsg loop fires as you click the oldest (first created) button, the ControlID returned will not match the new value of $btn_exit and so nothing happens.Look at the returns in the SciTE console from this cut-down version of your script:expandcollapse popup#include <GuiConstants.au3> #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #NoTrayIcon $script_title = "2win" $gmain=GuiCreate($script_title, 606, 500) GUICtrlCreateMenu("Information",300,200) $statmenu = GUICtrlCreateMenu ("&Statistics") $stat2= GUICtrlCreateMenuitem ("&Sum",$statmenu) GUISetState(@SW_SHOW) $gchild=GuiCreate($script_title&" child", 306, 300,-1,-1,-1,-1,$gmain) GUISetState(@SW_HIDE) While 1 $msg = GUIGetMsg() Select Case $msg = $stat2 ; Show the child GUISetState(@SW_SHOW, $gchild) $btn_xit = GuiCtrlCreateButton("Exit", 114, 254, 97, 25,$BS_DEFPUSHBUTTON) ConsoleWrite("This is the ControlID set in $btn_exit: " & $btn_xit & @CRLF) While 1 ; Get the advanced return from GUIGetMsg $amsg = GUIGetMsg(1) If $amsg[0] > 0 Then ConsoleWrite("And this is the ControlID returned from GUIGetMsg: " & $amsg[0] & @CRLF) ; If the message comes from the child If $amsg[1] = $gchild Then ; And it is to close If $amsg[0] = $GUI_EVENT_CLOSE Or $amsg[0]= $btn_xit Then :<<<<<< neater syntax here <<<<<<<<<<<<< ; Then hide the child and return to the main loop GUISetState(@SW_HIDE, $gchild) ExitLoop EndIf EndIf WEnd Case $msg = $GUI_EVENT_CLOSE ExitLoop Case Else EndSelect WEnd ExitAll you need to do to solve this is to create the button once when you first create the child GUI:$gchild=GuiCreate($script_title&" child", 306, 300,-1,-1,-1,-1,$gmain) $btn_xit = GuiCtrlCreateButton("Exit", 114, 254, 97, 25,$BS_DEFPUSHBUTTON) ; <<<<< Add this line <<<<<<< GUISetState(@SW_HIDE) ; And not each time you show the child GUI ; Show the child GUISetState(@SW_SHOW, $gchild) $btn_xit = GuiCtrlCreateButton("Exit", 114, 254, 97, 25,$BS_DEFPUSHBUTTON) ; <<<< Remove this line <<<<<<<<<Then it will work as you expect because the returned ControlID will match $btn_exit. 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