Jump to content

Script inside a script?


SynNaz
 Share

Recommended Posts

Is it possible to run a script inside a script? I mean I have the following script

#include <GUIConstantsEx.au3>

Opt('MustDeclareVars', 1)

_Main()

Func _Main()
    Local $filemenu, $separator1
    Local $exititem, $helpmenu, $aboutitem, $okbutton, $cancelbutton
    Local $msg
    #forceref $separator1

    GUICreate("program", 500, 400)

    $filemenu = GUICtrlCreateMenu("File")
    $separator1 = GUICtrlCreateMenuItem("", $filemenu)
    $exititem = GUICtrlCreateMenuItem("Exit", $filemenu)
    $helpmenu = GUICtrlCreateMenu("Help")
    $aboutitem = GUICtrlCreateMenuItem("About", $helpmenu)

    $okbutton = GUICtrlCreateButton("OK", 50, 130, 70, 20)

    $cancelbutton = GUICtrlCreateButton("Cancel", 180, 130, 70, 20)

    GUISetState()

    While 1
        $msg = GUIGetMsg()


        Select
            Case $msg = $GUI_EVENT_CLOSE Or $msg = $cancelbutton
                ExitLoop

            Case $msg = $exititem
                ExitLoop

            Case $msg = $okbutton
                _Main2()

            Case $msg = $aboutitem
                MsgBox(64, "About", "bbb" & @crlf & "bbb")
        EndSelect
    WEnd

    GUIDelete()

    Exit
EndFunc

Func _Main2()
    Local $filemenu, $separator1
    Local $exititem, $helpmenu, $aboutitem, $okbutton, $cancelbutton
    Local $msg
    #forceref $separator1

    GUICreate("aaa", 100, 100)

    $filemenu = GUICtrlCreateMenu("File")
    $separator1 = GUICtrlCreateMenuItem("", $filemenu)
    $exititem = GUICtrlCreateMenuItem("Exit", $filemenu)
    $helpmenu = GUICtrlCreateMenu("Help")
    $aboutitem = GUICtrlCreateMenuItem("About", $helpmenu)

    $okbutton = GUICtrlCreateButton("OK", 50, 130, 70, 20)

    $cancelbutton = GUICtrlCreateButton("Cancel", 180, 130, 70, 20)

    GUISetState()

    While 1
        $msg = GUIGetMsg()


        Select
            Case $msg = $GUI_EVENT_CLOSE Or $msg = $cancelbutton
                winkill ("aaa");

            Case $msg = $exititem
                winkill ("aaa");

            Case $msg = $okbutton
                MsgBox(0, "Click", "You clicked OK!")

            Case $msg = $aboutitem
                MsgBox(64, "About", "aaa" & @crlf & "aaa")
        EndSelect
    WEnd

    GUIDelete()

    Exit
EndFunc

When I click OK on the first window, it pops the second window. I can't close the second window unless if I use ctrl+alt+delete. Also, I can work on the second window, but the first window has freezed.

Can someone tell me how to repair this bug?

Edited by SynNaz
Link to comment
Share on other sites

  • Developers

Try:

#include <GUIConstantsEx.au3>

Opt('MustDeclareVars', 1)

_Main()

Func _Main()
    Local $filemenu, $separator1
    Local $exititem, $helpmenu, $aboutitem, $okbutton, $cancelbutton
    Local $msg
    #forceref $separator1

    GUICreate("program", 500, 400)

    $filemenu = GUICtrlCreateMenu("File")
    $separator1 = GUICtrlCreateMenuItem("", $filemenu)
    $exititem = GUICtrlCreateMenuItem("Exit", $filemenu)
    $helpmenu = GUICtrlCreateMenu("Help")
    $aboutitem = GUICtrlCreateMenuItem("About", $helpmenu)

    $okbutton = GUICtrlCreateButton("OK", 50, 130, 70, 20)

    $cancelbutton = GUICtrlCreateButton("Cancel", 180, 130, 70, 20)

    GUISetState()

    While 1
        $msg = GUIGetMsg()


        Select
            Case $msg = $GUI_EVENT_CLOSE Or $msg = $cancelbutton
                ExitLoop

            Case $msg = $exititem
                ExitLoop

            Case $msg = $okbutton
                _Main2()

            Case $msg = $aboutitem
                MsgBox(64, "About", "bbb" & @crlf & "bbb")
        EndSelect
    WEnd

    GUIDelete()

    Exit
EndFunc

Func _Main2()
    Local $filemenu, $separator1
    Local $exititem, $helpmenu, $aboutitem, $okbutton, $cancelbutton
    Local $msg
    #forceref $separator1

    GUICreate("aaa", 100, 100)

    $filemenu = GUICtrlCreateMenu("File")
    $separator1 = GUICtrlCreateMenuItem("", $filemenu)
    $exititem = GUICtrlCreateMenuItem("Exit", $filemenu)
    $helpmenu = GUICtrlCreateMenu("Help")
    $aboutitem = GUICtrlCreateMenuItem("About", $helpmenu)

    $okbutton = GUICtrlCreateButton("OK", 50, 130, 70, 20)

    $cancelbutton = GUICtrlCreateButton("Cancel", 180, 130, 70, 20)

    GUISetState()

    While 1
        $msg = GUIGetMsg()


        Select
            Case $msg = $GUI_EVENT_CLOSE Or $msg = $cancelbutton
                ExitLoop
            Case $msg = $exititem
                ExitLoop
            Case $msg = $okbutton
                MsgBox(0, "Click", "You clicked OK!")
            Case $msg = $aboutitem
                MsgBox(64, "About", "aaa" & @crlf & "aaa")
        EndSelect
    WEnd

    GUIDelete()
EndFunc

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

#include <GUIConstantsEx.au3>

Opt('MustDeclareVars', 1)

_Main()

Func _Main()
    Local $filemenu, $separator1
    Local $exititem, $helpmenu, $aboutitem, $okbutton, $cancelbutton
    Local $msg, $handle_main1
    #forceref $separator1

    $handle_main1 = GUICreate("program", 500, 400)

    $filemenu = GUICtrlCreateMenu("File")
    $separator1 = GUICtrlCreateMenuItem("", $filemenu)
    $exititem = GUICtrlCreateMenuItem("Exit", $filemenu)
    $helpmenu = GUICtrlCreateMenu("Help")
    $aboutitem = GUICtrlCreateMenuItem("About", $helpmenu)

    $okbutton = GUICtrlCreateButton("OK", 50, 130, 70, 20)

    $cancelbutton = GUICtrlCreateButton("Cancel", 180, 130, 70, 20)

    GUISetState()

    While 1
        $msg = GUIGetMsg()


        Select
            Case $msg = $GUI_EVENT_CLOSE Or $msg = $cancelbutton
                ExitLoop

            Case $msg = $exititem
                ExitLoop

            Case $msg = $okbutton
                _Main2()
                GUISwitch($handle_main1); <----- switch gui here

            Case $msg = $aboutitem
                MsgBox(64, "About", "bbb" & @crlf & "bbb")
        EndSelect
    WEnd

    GUIDelete()

    Exit
EndFunc

Func _Main2()
    Local $filemenu, $separator1
    Local $exititem, $helpmenu, $aboutitem, $okbutton, $cancelbutton
    Local $msg, $handle_main2
    #forceref $separator1

    $handle_main2 = GUICreate("aaa", 100, 100)

    $filemenu = GUICtrlCreateMenu("File")
    $separator1 = GUICtrlCreateMenuItem("", $filemenu)
    $exititem = GUICtrlCreateMenuItem("Exit", $filemenu)
    $helpmenu = GUICtrlCreateMenu("Help")
    $aboutitem = GUICtrlCreateMenuItem("About", $helpmenu)

    $okbutton = GUICtrlCreateButton("OK", 50, 130, 70, 20)

    $cancelbutton = GUICtrlCreateButton("Cancel", 180, 130, 70, 20)

    GUISetState()
    GUISwitch($handle_main2); <----- switch gui here
    While 1
        $msg = GUIGetMsg()


        Select
            Case $msg = $GUI_EVENT_CLOSE Or $msg = $cancelbutton
                GUIDelete($handle_main2); <--- delete gui here
                Return ; <---- return to func call line

            Case $msg = $exititem
                GUIDelete($handle_main2); <--- delete gui here
                Return ; <---- return to func call line

            Case $msg = $okbutton
                MsgBox(0, "Click", "You clicked OK!")

            Case $msg = $aboutitem
                MsgBox(64, "About", "aaa" & @crlf & "aaa")
        EndSelect
    WEnd

    ; removed irrelevent code down here

EndFunc

Use GuiSwitch() to set the events to the gui that you expect to handle them.

Link to comment
Share on other sites

You can try this way too.

#include <ButtonConstants.au3>
#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>
#include <GUIConstants.au3>
#include <StaticConstants.au3>
#NoTrayIcon

$Form1 = GUICreate("MAIN GUI", 265, 137) ;creating MAIN GUI
$Button1 = GUICtrlCreateButton("About", 24, 72, 73, 25, $WS_GROUP)
$nope = GUICtrlCreateButton("Exit", 168, 72, 73, 25, $WS_GROUP)
$Label1 = GUICtrlCreateLabel("This is a GUI 1`S LABEL", 72, 24, 120, 17)
$hfilemenu=GUICtrlCreateMenu("File")
$hfilemenu_fisrtitem=GUICtrlCreateMenuItem("About",$hfilemenu)
GUICtrlCreateMenuItem("",$hfilemenu)
$hfilemenu_itemEXIT=GUICtrlCreateMenuItem("Exit",$hfilemenu)
GUICtrlCreateMenuItem("",$hfilemenu)
GUISetState(@SW_SHOW)


While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1

            _haqqda()
        Case $nope
            $hanswer=MsgBox(65,"Do You Want Exit?","Dou You Want Exit?",15)
            If $hanswer="1" Then
                Exit
            EndIf
        Case $hfilemenu_fisrtitem
            _haqqda()
        Case $hfilemenu_itemEXIT
            $hanswer=MsgBox(65,"Do You Want Exit?","Dou You Want Exit?",15) ; timeout=15 sec
            If $hanswer="1" Then    ; 1 <= mean OK. See the help file of Autoit for msgbox() You can find about it :)
                Exit
            EndIf




    EndSwitch
WEnd


Func _haqqda()
GUIDelete($Form1) ;deleting $Form1 . This is a previous GUI .
$Form2 = GUICreate("About", 324, 234)   ;creating second GUI .In that case this is a <ABOUT> GUI.
$Label1 = GUICtrlCreateLabel("Product Name", 152, 24, 72, 17, BitOR($SS_NOTIFY,$WS_GROUP,$WS_VISIBLE,$WS_CHILD))
$Label2 = GUICtrlCreateLabel("Version", 152, 48, 39, 17, BitOR($SS_NOTIFY,$WS_GROUP,$WS_VISIBLE,$WS_CHILD))
$Label4 = GUICtrlCreateLabel("Comments: ", 16, 160, 53, 17, BitOR($SS_NOTIFY,$WS_GROUP,$WS_VISIBLE,$WS_CHILD))
$Label3 = GUICtrlCreateLabel("sh3llc043r", 16, 136, 48, 17, BitOR($SS_NOTIFY,$WS_GROUP,$WS_VISIBLE,$WS_CHILD))
$Button2 = GUICtrlCreateButton("&OK", 112, 208, 75, 25, BitOR($WS_TABSTOP,$WS_VISIBLE,$WS_CHILD))
$Image1 = GUICtrlCreatePic(@SystemDir& "\oobe\html\mouse\images\pisa.jpg", 16, 24, 105, 97, BitOR($SS_NOTIFY,$WS_GROUP,$WS_CLIPSIBLINGS))
GUISetState()
SoundPlay(@WindowsDir & "\media\tada.wav",0)


While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg


                    Case $GUI_EVENT_CLOSE
                        GUIDelete($Form2)

                    _aka()



        Case $Button2
GUIDelete($Form2)   ;deleting <ABOUT> GUI
_aka()  ;creating 1`st GUI again. For func see below => Func _aka()

EndSwitch


WEnd

EndFunc;<==>_haqqda()

Func _aka()
$Form1 = GUICreate("MAIN GUI", 265, 137)
$Button1 = GUICtrlCreateButton("About", 24, 72, 73, 25, $WS_GROUP)
$nope = GUICtrlCreateButton("Exit", 168, 72, 73, 25, $WS_GROUP)
$Label1 = GUICtrlCreateLabel("This is a GUI 1`S LABEL", 72, 24, 120, 17)
$hfilemenu=GUICtrlCreateMenu("File")
$hfilemenu_fisrtitem=GUICtrlCreateMenuItem("About",$hfilemenu)
GUICtrlCreateMenuItem("",$hfilemenu)
$hfilemenu_itemEXIT=GUICtrlCreateMenuItem("Exit",$hfilemenu)
GUICtrlCreateMenuItem("",$hfilemenu)
GUISetState(@SW_SHOW)


While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
            Case $hfilemenu_fisrtitem
            _haqqda()
        Case $hfilemenu_itemEXIT
    ;confirm exit
            $hanswer=MsgBox(65,"Do You Want Exit?","Dou You Want Exit?",15) ; timeout=15 sec
            If $hanswer="1" Then    ; 1 <= mean OK. See the help file of Autoit for msgbox() You can find about it :)
                Exit
            EndIf

        Case $Button1

            _haqqda()
        Case $nope
            $hanswer=MsgBox(65,"Do You Want Exit?","Dou You Want Exit?",15) ; timeout=15 sec
            If $hanswer="1" Then    ; 1 <= mean OK. See the help file of Autoit for msgbox() You can find about it :)
                Exit
                EndIf




    EndSwitch
WEnd
EndFunc; <===> _aka()
[size="5"] [/size]
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...