Jump to content

control lost from parent windows


twelo
 Share

Recommended Posts

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

#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

  • Moderators

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:

#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   ;==>CLOSEClicked

I added the <<<<<<<<<<<<<<<<< lines. I hope that everything is clear. :(

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 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

 

Link to comment
Share on other sites

i was trying to overcome it from 2 days

now 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

  • Moderators

twelo,

You are correct on both counts. :(

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 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

 

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...