Sign in to follow this  
Followers 0
jvanegmond

Closing Child Window By X-button

4 posts in this topic

#1 ·  Posted (edited)

I'm looking for a way to close a child window, by pressing it's X. Currently, it closes the whole App.

Edit: What really would be PERFECT, is a way to get the active window.

Edit2:

Case $msg = -3
            $Hwnd = WinGetHandle("")
            Select
                Case $Hwnd = $MainGUI
                    Exit
                Case Else
                    GUIDelete($Hwnd)
            EndSelect

Sooo obvious!!

Here's the code:

#include <GUIConstants.au3>

$GameTitle = "Name"

$MainGUI = GUICreate($GameTitle & " Map Editor", 1024,768,0,0)

$FileMenu = GUICtrlCreateMenu("File")
$New = GUICtrlCreateMenuItem("New",$FileMenu)
GUICtrlCreateMenuItem("",$FileMenu)
$Exit = GUICtrlCreateMenuItem("Exit",$FileMenu)
GUISetState()

While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = -3
            Exit
        Case $msg = $Exit
            Exit
        Case $msg = $New
            $Form1 = GUICreate("New", 359, 155, -1,-1,-1,$WS_EX_TOPMOST,$MainGUI)
            GUICtrlCreateLabel("Name:", 5, 10, 48, 17)
            $Input1 = GUICtrlCreateInput("Grass Test", 55, 5, 191, 22)
            
            GUICtrlCreateGroup("", 5, 35, 260, 115)
                GUICtrlCreateLabel("Width:", 15, 60, 53, 17)
                $Input2 = GUICtrlCreateInput("500", 75, 55, 176, 21,$ES_NUMBER)
                GUICtrlCreateLabel("Height:", 15, 90, 53, 17)
                $Input3 = GUICtrlCreateInput("500", 75, 85, 176, 21,$ES_NUMBER)
                GUICtrlCreateLabel("Background:", 10, 120, 60, 17)
                $Input4 = GUICtrlCreateCombo("Empty", 75, 115, 176, 21)
                GUICtrlSetData(-1,"Grass|Stone|Dirt","Grass")
            
            $Button1 = GUICtrlCreateButton("Ok", 270, 5, 85, 20)
            $Button2 = GUICtrlCreateButton("Cancel", 270, 30, 85, 20)
            
            GUICtrlCreateLabel("Good Luck", 270, 60, 83, 92)
            GUISetState(@SW_SHOW)
            While 1
                $msg = GuiGetMsg()
                Select
                Case $msg = -3 OR $msg = $Button2
                    ExitLoop
                Case $msg = $Button1
                    $Name = GUICtrlRead($Input1)
                    $Width = GUICtrlRead($Input2)
                    $Height = GUICtrlRead($Input3)
                    $Background = GUICtrlRead($Input4)
                    If $Name = "" OR $Width = "" OR $Height = "" Then
                        ExitLoop
                    EndIf
                    GUICreate($Name & ".map - Editor",$Width,$Height,-1,-1,-1,$WS_EX_TOPMOST,$MainGUI)
                    Select
                        Case $Background = "Empty"
                            $File = ""
                        Case $Background = "Grass"
                            $File = @ScriptDir & "\Maps\Textures\Grass1.jpg"
                        Case $Background = "Dirt"
                            $File = @ScriptDir & "\Maps\Textures\Dirt1.jpg"
                        Case $Background = "Stone"
                            $File = @ScriptDir & "\Maps\Textures\Stone1.jpg"
                    EndSelect
                    If $File <> "" Then
                        For $x = 0  to $Width/50
                            For $y = 0 to $Height/50
                                GUICtrlCreatePic($File,$x*50,$y*50,50,50)
                            Next
                        Next
                        $File = ""
                    EndIf
                    GUISetState()
                    ExitLoop
                EndSelect
            WEnd
            GUIDelete($Form1)
    EndSelect
WEnd
Edited by Manadar

Share this post


Link to post
Share on other sites



Hi,

maybe some day you could use this, too:

MsgBox(0,'', _WinGetActive())

Func _WinGetActive()
    $OptWSC = Opt('WinSearchChildren', 1)
    $aWinList = WinList()
    For $iCount = 1 To $aWinList[0][0]
        If $aWinList[$iCount][0] <> '' And WinActive($aWinList[$iCount][0]) Then
            Opt('WinSearchChildren', $OptWSC)
            Return $aWinList[$iCount][0]
        EndIf
    Next
    Opt('WinSearchChildren', $OptWSC)
    Return 0
EndFunc

So long,

Mega


Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Share this post


Link to post
Share on other sites

Should probably just make it a different function:

#include <GUIConstants.au3>
Dim $NewGUI = 0
$GameTitle = "Name"

$MainGUI = GUICreate($GameTitle & " Map Editor", 1024,768,0,0)

$FileMenu = GUICtrlCreateMenu("File")
$New = GUICtrlCreateMenuItem("New",$FileMenu)
GUICtrlCreateMenuItem("",$FileMenu)
$Exit = GUICtrlCreateMenuItem("Exit",$FileMenu)
GUISetState()

While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = -3
            Exit
        Case $msg = $Exit
            Exit
        Case $msg = $New
            $Form1 = GUICreate("New", 359, 155, -1,-1,-1,$WS_EX_TOPMOST,$MainGUI)
            GUICtrlCreateLabel("Name:", 5, 10, 48, 17)
            $Input1 = GUICtrlCreateInput("Grass Test", 55, 5, 191, 22)
            
            GUICtrlCreateGroup("", 5, 35, 260, 115)
                GUICtrlCreateLabel("Width:", 15, 60, 53, 17)
                $Input2 = GUICtrlCreateInput("500", 75, 55, 176, 21,$ES_NUMBER)
                GUICtrlCreateLabel("Height:", 15, 90, 53, 17)
                $Input3 = GUICtrlCreateInput("500", 75, 85, 176, 21,$ES_NUMBER)
                GUICtrlCreateLabel("Background:", 10, 120, 60, 17)
                $Input4 = GUICtrlCreateCombo("Empty", 75, 115, 176, 21)
                GUICtrlSetData(-1,"Grass|Stone|Dirt","Grass")
            
            $Button1 = GUICtrlCreateButton("Ok", 270, 5, 85, 20)
            $Button2 = GUICtrlCreateButton("Cancel", 270, 30, 85, 20)
            
            GUICtrlCreateLabel("Good Luck", 270, 60, 83, 92)
            GUISetState(@SW_SHOW)
            While 1
                $msg = GuiGetMsg()
                Select
                Case ($msg = -3 OR $msg = $Button2) And Not WinExists($NewGUI)
                    ExitLoop
                Case $msg = -3 And WinExists($NewGUI)
                    GUIDelete($NewGUI)
                Case $msg = $Button1
                    $Name = GUICtrlRead($Input1)
                    $Width = GUICtrlRead($Input2)
                    $Height = GUICtrlRead($Input3)
                    $Background = GUICtrlRead($Input4)
                    If $Name = "" OR $Width = "" OR $Height = "" Then
                        ExitLoop
                    EndIf
                    _ChildGUI($Name, $Width, $Height, $Background)
                EndSelect
            WEnd
            GUIDelete($Form1)
    EndSelect
WEnd

Func _ChildGUI($Name, $Width, $Height, $Background)
    $NewGUI = GUICreate($Name & ".map - Editor",$Width,$Height,-1,-1,-1,$WS_EX_TOPMOST,$MainGUI)
    Select
        Case $Background = "Empty"
            $File = ""
        Case $Background = "Grass"
            $File = @ScriptDir & "\Maps\Textures\Grass1.jpg"
        Case $Background = "Dirt"
            $File = @ScriptDir & "\Maps\Textures\Dirt1.jpg"
        Case $Background = "Stone"
            $File = @ScriptDir & "\Maps\Textures\Stone1.jpg"
    EndSelect
    If $File <> "" Then
        For $x = 0  to $Width/50
            For $y = 0 to $Height/50
                GUICtrlCreatePic($File,$x*50,$y*50,50,50)
            Next
        Next
        $File = ""
    EndIf
    GUISetState()
    While 1
        $msg2 = GUIGetMsg()
        If $msg2 = -3 Then ExitLoop
    WEnd
    GUIDelete($NewGUI)  
EndFunc


[center]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.[/center]

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