Jump to content

Understanding Child GUIs


sias
 Share

Recommended Posts

Maybe I don't understand how Child GUIs work, but what I have is a main GUI, and when a button is pressed it brings up a child GUI, in which information is held, also within that child GUI is a button to return the user back to the main GUI (a close button if you will). All this I have made successfully, the problem I am running into is when I close the Child GUI - whether it is destroying it completely or just hiding it - It disables all the controls in my Main GUI.

Is this an issue with multi-threading, or am I just incorrectly handling my child and main GUI? Any and all help is greatly appreciated as always, and an example script is just below.

#include <GUIConstants.au3>
$maingui = GUICreate("Main Gui", 200, 100, -1, -1)
$button1 = GUICtrlCreateButton("Click Here", 10, 10, 75, 25)
$Exit = GUICtrlCreateButton("Exit", 10, 50, 75, 25)
GUISetState()
While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            Exit
        Case $msg = $Exit
            Exit
        Case $msg = $button1
            $childgui = GUICreate("Child GUI", 200, 100, 50, 50)
            $button2 = GUICtrlCreateButton("Click Here", 10, 10, 75, 25)
            GUISetState()
            While 1
                $msg = GUIGetMsg()
                Select
                    Case $msg = $GUI_EVENT_CLOSE
                        Exit
                    Case $msg = $button2
                        GUISetState(@SW_ENABLE, $maingui)
                        GUIDelete($childgui)
                EndSelect
            WEnd
    EndSelect
WEnd

"The true measure of a man is how he treats someone who can do him absolutely no good."

Link to comment
Share on other sites

Maybe I don't understand how Child GUIs work, but what I have is a main GUI, and when a button is pressed it brings up a child GUI, in which information is held, also within that child GUI is a button to return the user back to the main GUI (a close button if you will). All this I have made successfully, the problem I am running into is when I close the Child GUI - whether it is destroying it completely or just hiding it - It disables all the controls in my Main GUI.

Is this an issue with multi-threading, or am I just incorrectly handling my child and main GUI? Any and all help is greatly appreciated as always, and an example script is just below.

#include <GUIConstants.au3>
$maingui = GUICreate("Main Gui", 200, 100, -1, -1)
$button1 = GUICtrlCreateButton("Click Here", 10, 10, 75, 25)
$Exit = GUICtrlCreateButton("Exit", 10, 50, 75, 25)
GUISetState()
While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            Exit
        Case $msg = $Exit
            Exit
        Case $msg = $button1
            $childgui = GUICreate("Child GUI", 200, 100, 50, 50)
            $button2 = GUICtrlCreateButton("Click Here", 10, 10, 75, 25)
            GUISetState()
            While 1
                $msg = GUIGetMsg()
                Select
                    Case $msg = $GUI_EVENT_CLOSE
                        Exit
                    Case $msg = $button2
                        GUISetState(@SW_ENABLE, $maingui)
                        GUIDelete($childgui)
                EndSelect
            WEnd
    EndSelect
WEndoÝ÷ Ûú®¢×ºÚ"µÍÚ[ÛYH    ÑÕRPÛÛÝ[Ë]LÉÝÂÌÍÛXZ[ÝZHHÕRPÜX]J  ][ÝÓXZ[ÝZI][ÝËLLKLJBÌÍØ]ÛHHÕRPÝÜX]P]Û  ][ÝÐÛXÚÈI][ÝËLL
ÍKJBÌÍÑ^]HÕRPÝÜX]P]Û    ][ÝÑ^]    ][ÝËL
L
ÍKJBÕRTÙ]Ý]J
BÚ[HB  ÌÍÛÙÈHÕRQÙ]ÙÊ
BÙ[XÝØÙH    ÌÍÛÙÈH ÌÍÑÕRWÑUSÐÓÔÑB^]ØÙH  ÌÍÛÙÈH ÌÍÑ^]^]ØÙH ÌÍÛÙÈH ÌÍØ]ÛBBBQÕRTÙ]Ý]JÕ×ÑTÐPK ÌÍÛXZ[ÝZJB  ÌÍØÚ[ÝZHHÕRPÜX]J ][ÝÐÚ[ÕRI][ÝËL
L
LLK ÌÍÛXZ[ÝZJB  ÌÍØ]ÛHÕRPÝÜX]P]Û    ][ÝÐÛXÚÈI][ÝËLL
ÍKJBÕRTÙ]Ý]J
BÚ[HB  ÌÍÛÙÈHÕRQÙ]ÙÊ
BÙ[XÝØÙH    ÌÍÛÙÈH ÌÍÑÕRWÑUSÐÓÔÑB^]ØÙH  ÌÍÛÙÈH ÌÍØ]ÛÕRTÙ]Ý]JÕ×ÑSPK   ÌÍÛXZ[ÝZJBÕRQ[]J   ÌÍØÚ[ÝZJBBBBBBY^]ÛÜ[Ù[XÝÑ[[Ù[XÝÑ[
Link to comment
Share on other sites

Alternative.

#include <WindowsConstants.au3>

$hParent = GUICreate ("GUI Parent!", 800, 600, Default, Default, BitOR ($GUI_SS_DEFAULT_GUI , $WS_CLIPCHILDREN))
$hButton1 = GUICtrlCreateButton ("Button", 300, 20)
$hChild = GUICreate ("Child", 200, 500, 10, 10, Default, BitOR ($WS_EX_MDICHILD, $WS_EX_TOOLWINDOW), $hParent)
GUISetState (@SW_SHOW, $hParent)
GUISetState (@SW_SHOW, $hChild)

While 1
    $nMsg = GUIGetMsg (1)
    Switch $nMsg[1]
        Case $hParent;Message is parent GUI
            Switch $nMsg[0]
                Case -3
                    Exit
                Case $hButton1
                    MsgBox (0, "", "WOO")
            EndSwitch
        Case $hChild
            Switch $nMsg[0]
                Case -3
                    GUISetState (@SW_HIDE, $hChild)
                    Sleep (2000)
                    Exit
            EndSwitch
    EndSwitch
WEnd

Please excuse the window styles which are probably wrong...

Link to comment
Share on other sites

  • 8 months later...

#include <WindowsConstants.au3>

$hParent = GUICreate ("GUI Parent!", 800, 600, Default, Default, BitOR ($GUI_SS_DEFAULT_GUI , $WS_CLIPCHILDREN))
$hButtonP1 = GUICtrlCreateButton ("Pop", 300, 20)
$hButtonP2 = GUICtrlCreateButton ("Child", 300, 50)
$hButtonP3 = GUICtrlCreateButton ("Child2", 300, 70)
$hChild = GUICreate ("Child", 200, 500, 10, 10, Default, BitOR ($WS_EX_MDICHILD, $WS_EX_TOOLWINDOW), $hParent)
$hButtonC1 = GUICtrlCreateButton ("Pop", 20, 20)
$hChild2 = GUICreate ("Child", 250, 300, 400, 10, Default, BitOR ($WS_EX_MDICHILD, $WS_EX_TOOLWINDOW), $hParent)
$hButtonCo1 = GUICtrlCreateButton ("Pop", 20, 20)
GUISetState (@SW_SHOW, $hParent)
GUISetState (@SW_SHOW, $hChild)
GUISetState (@SW_SHOW, $hChild2)

While 1
    $nMsg = GUIGetMsg (1)
    Switch $nMsg[1]
        Case $hParent;Message is parent GUI
            Switch $nMsg[0]
                Case -3
                    Exit
                Case $hButtonP1
                    MsgBox (0, "", "Parent control")
                Case $hButtonP2
                    GUISetState (@SW_SHOW, $hChild)                 
                Case $hButtonP3
                    GUISetState (@SW_SHOW, $hChild2)                    
                    
            EndSwitch
        Case $hChild
            Switch $nMsg[0]
                Case -3
                    GUISetState (@SW_HIDE, $hChild)
                Case $hButtonC1
                    MsgBox (0, "", "Child control")
                EndSwitch
        Case $hChild2
            Switch $nMsg[0]
                Case -3
                    GUISetState (@SW_HIDE, $hChild2)
                Case $hButtonCo1
                    MsgBox (0, "", "Child2 control")
            EndSwitch
                
                
    EndSwitch
WEnd
Now i got it...

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...