Jump to content

Parent/Child sample


Holger
 Share

Recommended Posts

THis is just a small example how you could use 1 (main) GUI with different screens, for instance if you have a lot of controls or don't want to delete/hide a lot of controls when you switch to another GUI with the same window-preferences (like in Installer-windows).

#include <GUIConstants.au3>

Global $gui_width   = 300
Global $gui_height  = 400
Global $gui_child_height    = $gui_height - 42
; this window has no controls except the 2 ok/cancel-buttons
Global $main_GUI        = GUICreate("Window Title",$gui_width,$gui_height,-1,-1,BitOr($GUI_SS_DEFAULT_GUI,$WS_CLIPSIBLINGS))
Global $ok_button       = GUICtrlCreateButton("OK",$gui_width - 240,$gui_height - 30,70,20)
Global $cancel_button   = GUICtrlCreateButton("Cancel",$gui_width - 120,$gui_height - 30,70,20)
GUISetState()

; creates the prefs child window that is implemented into the main GUI
Global $prefs_GUI           = GUICreate("",$gui_width,$gui_child_height,0,0,$WS_CHILD,-1,$main_GUI)
GUISetBkColor(0x007788)
Global $prefs_title         = GUICtrlCreateLabel("Preferences",0,5,$gui_width,20,$SS_CENTER)
GUICtrlSetColor(-1,0xFFFFFF)
GUICtrlSetFont(-1,10,600)
Global $prefs_treeview      = GUICtrlCreateTreeView(10,30,280,100,BitOr($TVS_HASBUTTONS,$TVS_DISABLEDRAGDROP,$TVS_CHECKBOXES),$WS_EX_CLIENTEDGE)
Global $prefs_symbols       = GUICtrlCreateTreeViewItem("Show Symbols",$prefs_treeview)
Global $prefs_backup_item   = GUICtrlCreateTreeViewItem("Enable Backup",$prefs_treeview)
Global $prefs_toggle_item   = GUICtrlCreateTreeViewItem("Show ToggleButton",$prefs_treeview)
Global $prefs_about_button  = GUICtrlCreateButton("About",($gui_width - 70) / 2,$gui_child_height - 30,70,20)
GUISetState()

; creates the about child window that is implemented into the main GUI
Global $about_GUI   = GUICreate("",$gui_width,$gui_child_height,0,0,$WS_CHILD,-1,$main_GUI)
GUISetBkColor(0x228855)
Global $about_title = GUICtrlCreateLabel("About",0,5,$gui_width,20,$SS_CENTER)
GUICtrlSetColor(-1,0xFFFFFF)
GUICtrlSetFont(-1,10,600)
Global $about_label = GUICtrlCreateLabel("Only a Parent/Child Window Demo by Holger Kotsch",30,30,$gui_width - 60,60)
GUICtrlSetColor(-1,0xFFFF88)
GUICtrlSetFont(-1,10)
Global $about_prefs_button  = GUICtrlCreateButton("Preferences",($gui_width - 70) / 2,$gui_child_height - 30,70,20)

While 1
    $msg = GUIGetMsg(1)
    Select
        Case $msg[0] = $GUI_EVENT_CLOSE Or $msg[0] = $cancel_button
            ExitLoop
            
        Case $msg[0] = $prefs_about_button
            GUISetState(@SW_HIDE,$prefs_GUI)
            GUISetState(@SW_SHOW,$about_GUI)
            
        Case $msg[0] = $about_prefs_button
            GUISetState(@SW_HIDE,$about_GUI)
            GUISetState(@SW_SHOW,$prefs_GUI)
    EndSelect
WEnd

So there will be created a main-GUI and after that you create easyly some 'sub-screens' for that.

So if you want to hide the controls of one screen you hide the complete (child) screen and switch to the other.

Feel free to use and modify it.

Regards :lmao:

Holger

Link to comment
Share on other sites

@Larry: I know - stupid question?

But do you have the latest version installed? "jpm" added these special constants for the latest release I think.

However:

$GUI_SS_DEFAULT_GUI = $WS_MINIMIZEBOX + $WS_CAPTION + $WS_POPUP + $WS_SYSMENU

So long...

Holger

Link to comment
Share on other sites

Just another sample, try it and take a look :lmao:

#include <GUIConstants.au3>

Global $main_GUI,$ok_button,$cancel_button,$prefs_GUI

; this window has no controls except the 2 ok/cancel-buttons
$main_GUI           = GUICreate("Window Title",400,250,-1,-1,BitOr($GUI_SS_DEFAULT_GUI,$WS_CLIPSIBLINGS))
$ok_button          = GUICtrlCreateButton("OK",100,220,70,20)
$cancel_button      = GUICtrlCreateButton("Cancel",210,220,70,20)

$main_tree          = GUICtrlCreateTreeView(10,10,150,200)
$about_item         = GUICtrlCreateTreeViewItem("About",$main_tree)
$general_item       = GUICtrlCreateTreeViewItem("General",$main_tree)
$colors_item        = GUICtrlCreateTreeViewItem("Colors",$general_item)
$fonts_item         = GUICtrlCreateTreeViewItem("Fonts",$general_item)
$preferences_item   = GUICtrlCreateTreeViewItem("Preferences",$main_tree)
$backup_item        = GUICtrlCreateTreeViewItem("Backup",$preferences_item)
$tools_item         = GUICtrlCreateTreeViewItem("Tools",$preferences_item)

GUISetState()

; creates the prefs child window that is implemented into the main GUI
Global $prefs_GUI   = GUICreate("",220,210,170,0,$WS_CHILD,-1,$main_GUI)
;GUISetBkColor(0x257788); just for dimensing the child
$prefs_title        = GUICtrlCreateGroup("Preferences",0,4,220,206)
$prefs_treeview     = GUICtrlCreateTreeView(10,30,200,100,BitOr($TVS_HASBUTTONS,$TVS_DISABLEDRAGDROP,$TVS_CHECKBOXES),$WS_EX_CLIENTEDGE)
$prefs_symbols      = GUICtrlCreateTreeViewItem("Show Symbols",$prefs_treeview)
$prefs_backup_item  = GUICtrlCreateTreeViewItem("Enable Backup",$prefs_treeview)
$prefs_toggle_item  = GUICtrlCreateTreeViewItem("Show ToggleButton",$prefs_treeview)

$prefs_button1      = GUICtrlCreateCheckbox("Check1",10,140,70,20,$BS_PUSHLIKE)
$prefs_button2      = GUICtrlCreateCheckbox("Check2",90,140,70,20,$BS_PUSHLIKE)
$prefs_button3      = GUICtrlCreateCheckbox("Check3",10,170,70,20,$BS_PUSHLIKE)
$prefs_button4      = GUICtrlCreateCheckbox("Check4",90,170,70,20,$BS_PUSHLIKE)

; creates the about child window that is implemented into the main GUI
$about_GUI          = GUICreate("",220,210,170,0,$WS_CHILD,-1,$main_GUI)
$about_title        = GUICtrlCreateGroup("About",0,4,220,206)
$about_label        = GUICtrlCreateLabel("Only a Parent/Child Window Demo by Holger Kotsch",10,30,180,40)
$input              = GUICtrlCreateInput(">>Put your name here<<",10,100,200,20,$ES_CENTER)

GUISetState()

While 1
    $msg = GUIGetMsg(1)
    Select
        Case $msg[0] = $GUI_EVENT_CLOSE Or $msg[0] = $cancel_button
            ExitLoop
            
        Case $msg[0] = $about_item
            GUISetState(@SW_HIDE,$prefs_GUI)
            GUISetState(@SW_SHOW,$about_GUI)
            
        Case $msg[0] = $preferences_item
            GUISetState(@SW_HIDE,$about_GUI)
            GUISetState(@SW_SHOW,$prefs_GUI)
    EndSelect
WEnd

So long....

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