Sign in to follow this  
Followers 0
Country73

Parent / Child

7 posts in this topic

#1 ·  Posted (edited)

Been searching this site, and going through the Help File, but still can't get my head around this.

In this example, I have a parent window with one button and a child window with one button.

Selecting the Parent window button - Child window is displayed.

Selecting the Child window button - Displays the message, but does not hide the child window.

I can close the child window, by clicking on the X in title, but I want the button to handle this.

Once I have the basics worked out I plan on adding a lot more functions, but I can't get this figured out.

#include <GUIConstantsEx.au3>

$ParentGui      =   GUICreate( "NightWatchman50 Settings", 535, 440, 150, 150 )
$ChangeDays     =   GUICtrlCreateButton( "ShutdownDays", 410, 150, 100, 25 )
GUISetState(@SW_SHOW)

$ChangeDaysWin  =   GUICreate( "ChangeDays - Settings", 310, 240, 150, 150, -1, -1, $ParentGui )
$DCCancel       =   GUICtrlCreateButton( "Cancel", 100, 200, 80, 25 )
GUISetState(@SW_HIDE)

GUISwitch( $ParentGui )
While 1
    $msg = GUIGetMsg(1)
    Select
        Case $msg[0] = $GUI_EVENT_CLOSE
            IF $msg[1] = $ChangeDaysWin Then
                MsgBox( 64, "Hide", "ChangeDaysWin will now hide." )
                GUISwitch( $ChangeDaysWin )
                GUISetState( @SW_HIDE, $ChangeDaysWin )
            ElseIf $msg[1] = $ParentGui Then
                MsgBox( 64, "Close", "All windows will now close." )
                GUISwitch( $ParentGui )
                GUIDelete()
                Exit
            EndIf
        Case $msg[0] = $ChangeDays
            GUISwitch( $ChangeDaysWin )
            GUISetState( @SW_SHOW, $ChangeDaysWin )
        Case $msg[0]  = $DCCancel
            If $msg[1] = $ChangeDaysWin Then
                MsgBox( 64, "Cancel", "Clicked Cancel in ChangeDays" )
                GUISetState( @SW_HIDE, $ChangeDays )
            EndIf
    EndSelect
WEnd

Any assistance in what I currently have, or should I be looking in a different direction to handle this?

The child window will eventually have a list of Checkbox's and Radio buttons, but I can't really start on that until I can figure this part out.

Appreciate anyone's assistance.

Edited by Country73

If you try to fail and succeed which have you done?AutoIt Forum Search

Share this post


Link to post
Share on other sites



That's the problem with using variable names that are so similar, sometimes you confuse yourself and the answer never pops out on you :P

If $msg[1] = $ChangeDaysWin Then
                MsgBox( 64, "Cancel", "Clicked Cancel in ChangeDays" )
                GUISetState( @SW_HIDE, $ChangeDays )
            EndIfoÝ÷ ÙW«²ëºÚ"µÍY  ÌÍÛÙÖÌWHH ÌÍÐÚ[ÙQ^ÕÚ[[ÙÐÞ

    ][ÝÐØ[Ù[    ][ÝË  ][ÝÐÛXÚÙYØ[Ù[[Ú[ÙQ^É][ÝÈ
BÕRTÙ]Ý]JÕ×ÒQK    ÌÍÐÚ[ÙQ^ÕÚ[
B[Y
?

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Share this post


Link to post
Share on other sites

Son of a gun, :P

I'm kicking myself now... and I WILL work on setting better variables to limit my confusions.

Ok, now that the stupidity {on my part} has been cleared up.

Is that the correct way to use the $msg[0] & $msg[1] ?

Can't really find a definitive post on the method for using that. Basically went through trial/error to get what I had.

Thank you,


If you try to fail and succeed which have you done?AutoIt Forum Search

Share this post


Link to post
Share on other sites

Son of a gun, :P

I'm kicking myself now... and I WILL work on setting better variables to limit my confusions.

Ok, now that the stupidity {on my part} has been cleared up.

Is that the correct way to use the $msg[0] & $msg[1] ?

Can't really find a definitive post on the method for using that. Basically went through trial/error to get what I had.

Thank you,

I've never personally used it. I always create functions for my child gui's. But after reading the description, for GUIGetMsg()'s first parameter, in the help file, I'd have to say yes, that looks fine.

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Share this post


Link to post
Share on other sites

I'm going to try to put a little more of my Child together, then post what I've got.

It'll take me a bit to go over my variables and set them up to cut out any confusion. :P

But I would appreciate another set of eyes on this so I don't get too far down the road and realize there's a better way to write it.

Again, appreciate all of your help.


If you try to fail and succeed which have you done?AutoIt Forum Search

Share this post


Link to post
Share on other sites

I'm going to try to put a little more of my Child together, then post what I've got.

It'll take me a bit to go over my variables and set them up to cut out any confusion. :P

But I would appreciate another set of eyes on this so I don't get too far down the road and realize there's a better way to write it.

Again, appreciate all of your help.

You could use events... I personally like structuring my GUI's with functions to track them easier, and limit confusions... Something like:
#include <GUIConstantsEx.au3>

_MainGUI()

Func _MainGUI()
    Local $v_main_msg, $n_changedays_message = 0
    Local $h_gui = GUICreate("NightWatchman50 Settings", 535, 440, 150, 150)
    Local $h_changedays_button = GUICtrlCreateButton( "ShutdownDays", 410, 150, 100, 25)
    GUISetState()
    
    While 1
        $v_main_msg = GUIGetMsg(1)
        Switch $v_main_msg[0]
            Case $GUI_EVENT_CLOSE
                If ($v_main_msg[1] = $h_gui) Then
                    GUIDelete($h_gui)
                    ExitLoop
                EndIf
            Case $h_changedays_button
                GUISetState(@SW_LOCK, $h_gui)
                $n_changedays_message = _ChangeDaysGUI($h_gui)
                GUISetState(@SW_UNLOCK, $h_gui)
                If $n_changedays_message = -3 Then
                    MsgBox(64, "Info", "The gui was closed using the X")
                ElseIf $n_changedays_message = -2 Then
                    MsgBox(64, "Info", "The gui was closed using the cancel button")
                Else
                    MsgBox(64, "Info", "The function was returned because it carried out what I wanted.")
                EndIf
        EndSwitch
    WEnd
EndFunc

Func _ChangeDaysGUI($h_parent)
    Local $v_changedays_msg
    Local $h_changedays_gui  = GUICreate( "ChangeDays - Settings", 310, 240, 150, 150, -1, -1, $h_parent)
    Local $h_cancel_button =  GUICtrlCreateButton( "Cancel", 100, 200, 80, 25 )
    GUISetState()
    
    While 1
        $v_changedays_msg = GUIGetMsg(1)
        Switch $v_changedays_msg[0]
            Case $GUI_EVENT_CLOSE
                If ($v_changedays_msg[1] = $h_changedays_gui) Then
                    GUIDelete($h_changedays_gui)
                    Return -3
                EndIf
            Case $h_cancel_button
                GUIDelete($h_changedays_gui)
                Return -2
        EndSwitch
    WEnd
    Return 1    
EndFunc

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Share this post


Link to post
Share on other sites

Well, I'll test what you have provided - play around with it for it a bit - and see what works out best.

I'll post some data after I have time to test things out.

Thanks again,


If you try to fail and succeed which have you done?AutoIt Forum Search

Share this post


Link to post
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
Sign in to follow this  
Followers 0