Jump to content

GUI child


myspacee
 Share

Recommended Posts

Hello to all,

see example of child gui :

;====================================================
;============= Example of a child window ============
;====================================================
; AutoIt version: 3.0.103
; Language:       English
; Author:         "SlimShady"
;
; ----------------------------------------------------------------------------
; Script Start
; ----------------------------------------------------------------------------

;Include constants
#include <GUIConstantsEx.au3>

Opt('MustDeclareVars', 1)

_Main()

Func _Main()

    ;Initialize variables
    Local $GUIWidth = 250, $GUIHeight = 250
    Local $ParentWin, $ParentWin_Pos, $ChildWin, $msg

    ;Create main/parent window
    $ParentWin = GUICreate("Parent GUI", $GUIWidth, $GUIHeight)
    ;Save the position of the parent window
    $ParentWin_Pos = WinGetPos($ParentWin, "")
    ;Show the parent window/Make the parent window visible
    GUISetState(@SW_SHOW)

    ;Create child window and add the parameter to make it the child of the parent window
    $ChildWin = GUICreate("Child GUI", $GUIWidth, $GUIHeight, $ParentWin_Pos[0] + 100, $ParentWin_Pos[1] + 100, -1, -1, $ParentWin)
    ;Show the child window/Make the child window visible
    GUISetState(@SW_SHOW)

    ;Switch to the parent window
    GUISwitch($ParentWin)

    ;Loop until:
    ;- user presses Esc when focused to the parent window
    ;- user presses Alt+F4 when focused to the parent window
    ;- user clicks the close button of the parent window
    While 1
        ;After every loop check if the user clicked something in the GUI windows
        $msg = GUIGetMsg(1)
        Select
            ;Check if user clicked on a close button of any of the 2 windows
            Case $msg[0] = $GUI_EVENT_CLOSE
                ;Check if user clicked on the close button of the child window
                If $msg[1] = $ChildWin Then
                    MsgBox(64, "Test", "Child GUI will now close.")
                    ;Switch to the child window
                    GUISwitch($ChildWin)
                    ;Destroy the child GUI including the controls
                    GUIDelete()
                    ;Check if user clicked on the close button of the parent window
                ElseIf $msg[1] = $ParentWin Then
                    MsgBox(64, "Test", "Parent GUI will now close.")
                    ;Switch to the parent window
                    GUISwitch($ParentWin)
                    ;Destroy the parent GUI including the controls
                    GUIDelete()
                    ;Exit the script
                    Exit
                EndIf

        EndSelect

    WEnd
EndFunc   ;==>_Main

But this example allow to select also main gui when child is on screen.

I want, when child is called, that main window is not selectable, but don't understand how...

Anyone can teach me?

Thank you,

m.

Link to comment
Share on other sites

  • Moderators

myspacee,

This is one way to do it - disable the parent GUI when the child GUI is visible: :mellow:

#include <GUIConstantsEx.au3>

; Create parent
$hGUI = GUICreate("Parent", 500, 500)

$hButton_Child = GUICtrlCreateButton("Child", 10, 10, 80, 30)
$hButton_Test  = GUICtrlCreateButton("Test", 10, 50, 80, 30)

GUISetState()

; Create child
$hGUI_Child = GUICreate("Child", 200, 200)

GUISetState(@SW_HIDE)

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $hButton_Test
            MsgBox(0, "Test", "You pressed the button!")
        Case $hButton_Child
            GUISetState($GUI_DISABLE, $hGUI)
            GUISetState(@SW_SHOW, $hGUI_Child)
            While 1

                Switch GUIGetMsg()
                    Case $GUI_EVENT_CLOSE
                        GUISetState(@SW_HIDE, $hGUI_Child)
                        GUISetState($GUI_ENABLE, $hGUI)
                        ExitLoop
                EndSwitch
            WEnd

    EndSwitch

WEnd

Try pressing the Test button when the child is visible! :(

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