Jump to content
Sign in to follow this  
operationx

Returning Control Back to Parent Window

Recommended Posts

operationx

I've been working on a movie inventory script that is giving me some trouble. After clicking the "Add Movie" button a child window appears and allows you to enter movie information. However, after closing the "Add Movie" child window and returning back to the main screen all functionality is lost on the parent window. My full code is below, its my first script so any advice is welcome! ;)

#include <GUIConstants.au3>
#include <GUIConstantsEx.au3>
#include <SQLite.au3>
#include <SQLite.dll.au3>

;window creation
$parentWindow = GUICreate("Movie Database", 600, 450); will create a dialog box that when displayed is centered
Opt("GUICoordMode",1)
$Button_1 = GUICtrlCreateButton ("Add Movie",  170, 10, 70)
$Button_2 = GUICtrlCreateButton ( "Delete Movie",  250, -1)
$movielist=GUICtrlCreateList ("Current Movies", 10,10,150,425)
GUICtrlCreateLabel("Movie Title:", 170, 45, 70) 
$movieName = GUICtrlCreateInput("", 245, 40, 200, 20)
GUICtrlCreateLabel("Release Date:", 170, 70, 70) 
$movieRelease = GUICtrlCreateInput("", 245, 65, 200, 20)
GUICtrlCreateLabel("Genre:", 170, 95, 70) 
$movieGenre = GUICtrlCreateInput("", 245, 90, 200, 20)
GUICtrlCreateLabel("Director:", 170, 120, 70) 
$movieDirector = GUICtrlCreateInput("", 245, 115, 200, 20)
GUICtrlCreateLabel("IMDB Link:", 170, 145, 70) 
$movieIMDB = GUICtrlCreateInput("", 245, 140, 200, 20)
GUICtrlCreateLabel("Actor1:", 170, 170, 70) 
$movieActor1 = GUICtrlCreateInput("", 245, 165, 200, 20)
GUICtrlCreateLabel("Actor2:", 170, 195, 70) 
$movieActor2 = GUICtrlCreateInput("", 245, 190, 200, 20)
GUICtrlCreateLabel("Actor3:", 170, 220, 70) 
$movieActor3 = GUICtrlCreateInput("", 245, 215, 200, 20)
GUICtrlCreateLabel("Actor4:", 170, 245, 70) 
$movieActor4 = GUICtrlCreateInput("", 245, 240, 200, 20)
GUICtrlCreateLabel("Actor5:", 170, 270, 70) 
$movieActor5 = GUICtrlCreateInput("", 245, 265, 200, 20)
GUICtrlCreateLabel("Cover Art:", 170, 295, 70) 
$movieArt = GUICtrlCreateInput("", 245, 290, 200, 20)
GUICtrlCreateLabel("Serial Number:", 170, 320, 70) 
$movieID = GUICtrlCreateInput("", 245, 315, 200, 20)
GUICtrlCreateLabel("Description:", 170, 345, 70) 
$movieDescription = GUICtrlCreateEdit("", 245, 340, 280, 100)

Func listMovies()
    Local $hQuery, $aRow, $aNames
    _SQLite_Startup ()
    _SQLite_Open ("database.db")
    _SQlite_Query (-1, "SELECT mTitle,mTitle FROM invMovies ORDER BY mTitle;", $hQuery)
        While _SQLite_FetchData ($hQuery, $aRow) = $SQLITE_OK; Read Out the next Row
        GUICtrlSetData($movielist,$aRow[0])
        WEnd
    _SQLite_Close ()
    _SQLite_Shutdown ()
    Return
EndFunc

Func checkTitle()
    $displayTitle = GUICtrlRead($movielist)
    Return ($displayTitle)
EndFunc

Func movieLookup($mTitle)
    Local $aRow
    _SQLite_Startup ()
    _SQLite_Open ("database.db")
    _SQLite_QuerySingleRow (-1, "SELECT mTitle,* FROM invMovies WHERE mTitle = '"&$mTitle&"' LIMIT 1;", $aRow)
    GUICtrlSetData($movieName,$aRow[2])
    GUICtrlSetData($movieRelease,$aRow[3])
    GUICtrlSetData($movieGenre,$aRow[4])
    GUICtrlSetData($movieDirector,$aRow[5])
    GUICtrlSetData($movieIMDB,$aRow[7])
    GUICtrlSetData($movieActor1,$aRow[8])
    GUICtrlSetData($movieActor2,$aRow[9])
    GUICtrlSetData($movieActor3,$aRow[10])
    GUICtrlSetData($movieActor4,$aRow[11])
    GUICtrlSetData($movieActor5,$aRow[12])
    GUICtrlSetData($movieArt,$aRow[13])
    GUICtrlSetData($movieID,$aRow[1])
    GUICtrlSetData($movieDescription,$aRow[6])
    _SQLite_Close ()
    _SQLite_Shutdown ()
    Return
EndFunc

Func addMovie()
    $addMovieWindow = GUICreate("Add Movie", 600, 400, -1, -1, -1, -1, $parentWindow)
;create user input boxes!
    $Button_1 = GUICtrlCreateButton ("Save Movie",  10, 10, 75)
    GUICtrlCreateLabel("Movie Title:", 10, 45, 70) 
    $movieName = GUICtrlCreateInput("", 85, 40, 200, 20)
    GUICtrlCreateLabel("Release Date:", 10, 70, 70) 
    $movieRelease = GUICtrlCreateInput("", 85, 65, 200, 20)
    GUICtrlCreateLabel("Genre:", 10, 95, 70) 
    $movieGenre = GUICtrlCreateInput("", 85, 90, 200, 20)
    GUICtrlCreateLabel("Director:", 10, 120, 70) 
    $movieDirector = GUICtrlCreateInput("", 85, 115, 200, 20)
    GUICtrlCreateLabel("Description:", 305, 45, 70) 
    $movieDescription = GUICtrlCreateEdit("", 305, 65, 280, 100)
    GUICtrlCreateLabel("IMDB Link:", 10, 145, 70) 
    $movieIMDB = GUICtrlCreateInput("", 85, 140, 200, 20)
    GUICtrlCreateLabel("Actor1:", 10, 170, 70) 
    $movieActor1 = GUICtrlCreateInput("", 85, 165, 200, 20)
    GUICtrlCreateLabel("Actor2:", 10, 195, 70) 
    $movieActor2 = GUICtrlCreateInput("", 85, 190, 200, 20)
    GUICtrlCreateLabel("Actor3:", 10, 220, 70) 
    $movieActor3 = GUICtrlCreateInput("", 85, 215, 200, 20)
    GUICtrlCreateLabel("Actor4:", 10, 245, 70) 
    $movieActor4 = GUICtrlCreateInput("", 85, 240, 200, 20)
    GUICtrlCreateLabel("Actor5:", 10, 270, 70) 
    $movieActor5 = GUICtrlCreateInput("", 85, 265, 200, 20)
    GUICtrlCreateLabel("Cover Art:", 10, 295, 70) 
    $movieArt = GUICtrlCreateInput("", 85, 290, 200, 20)
    GUICtrlCreateLabel("Serial Number:", 10, 320, 70) 
    $movieID = GUICtrlCreateInput("UNIQUE # REQUIRED", 85, 315, 200, 20)
    GUICtrlCreateLabel("All fields ARE REQUIRED! If information is unavaliable type NULL", 150, 350, 400) 
    GUISetState (@SW_SHOW)
;Run the GUI until the dialog is closed
        While 2
            $msg2 = GUIGetMsg()
                Select
                    Case $msg2 = $Button_1
                        $dbmovieName = GUICtrlRead($movieName)
                        $dbmovieRelease = GUICtrlRead($movieRelease)
                        $dbmovieGenre = GUICtrlRead($movieGenre)
                        $dbmovieDirector = GUICtrlRead($movieDirector)
                        $dbmovieDescription = GUICtrlRead($movieDescription)
                        $dbmovieIMDB = GUICtrlRead($movieIMDB)
                        $dbmovieActor1 = GUICtrlRead($movieActor1)
                        $dbmovieActor2 = GUICtrlRead($movieActor2)
                        $dbmovieActor3 = GUICtrlRead($movieActor3)
                        $dbmovieActor4 = GUICtrlRead($movieActor4)
                        $dbmovieActor5 = GUICtrlRead($movieActor5)
                        $dbmovieArt = GUICtrlRead($movieArt)
                        $dbmovieID = GUICtrlRead($movieID)
                        Local $hQuery, $aRow, $aNames
                        _SQLite_Startup ()
                        _SQLite_Open ("database.db")
                        $SQL = "INSERT INTO invMovies VALUES ('"& $dbmovieID &"','"& $dbmovieName &"','"& $dbmovieRelease &"','"& $dbmovieGenre &"','"& $dbmovieDirector &"','"& $dbmovieDescription &"','"& $dbmovieIMDB &"','"& $dbmovieActor1 &"','"& $dbmovieActor2 &"','"& $dbmovieActor3 &"','"& $dbmovieActor4 &"','"& $dbmovieActor5 &"','"& $dbmovieArt&"','null','null');"
                        if not _SQLite_Exec (-1, $sql) = $SQLITE_OK Then MsgBox(16, "SQLite Error", _SQLite_ErrMsg ())
                        _SQLite_Close()
                        _SQLite_Shutdown()
                        MsgBox(0, 'Movie Saved', 'Thank you! Your movie has been added to the library.')
                    Case $msg2 = $GUI_EVENT_CLOSE
                    ;Destroy the child GUI including the controls
                        GUIDelete($addMovieWindow)
                        Return
                EndSelect
        Wend
Exit            
EndFunc


;the magic starts HERE!!
listMovies()
$secondSelection = "null"
GUISetState(@SW_SHOW); Run the GUI until the dialog is closed
While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            MsgBox(64, "Close Window", "Movie Database window will now close.")
        ;Switch to the parent window
            GUISwitch($parentWindow)
        ;Destroy the parent GUI including the controls
            GUIDelete($parentWindow)
        ;Exit the script
            Exit
        Case $msg = $Button_1
            addMovie()
        Case $msg = $Button_2
            if checkTitle() <> "Current Movies" Then
                MsgBox(36,'Confirm Delete','Are you sure you want to delete: '&checkTitle()&'?')
            EndIf
            
    EndSelect
        
        
;outside of case selection!!!!!!!!!!!!!!!!!!!!!!!!  
    $firstSelection = checkTitle()
    while $firstSelection <> $secondSelection
        if $firstSelection <> "Current Movies" Then
            movieLookup($firstSelection)
            $secondSelection = $firstSelection
        EndIf
        ExitLoop
    WEnd
    
Wend

Share this post


Link to post
Share on other sites
Richard Robertson

Have you tried WinActivate?

Share this post


Link to post
Share on other sites
youknowwho4eva

func controls()
While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            MsgBox(64, "Close Window", "Movie Database window will now close.")
     ;Switch to the parent window
            GUISwitch($parentWindow)
     ;Destroy the parent GUI including the controls
            GUIDelete($parentWindow)
     ;Exit the script
            Exit
        Case $msg = $Button_1
            addMovie()
call ("controls")
        Case $msg = $Button_2
            if checkTitle() <> "Current Movies" Then
                MsgBox(36,'Confirm Delete','Are you sure you want to delete: '&checkTitle()&'?')
            EndIf
Call ("controls")
            
    EndSelect
        
        
;outside of case selection!!!!!!!!!!!!!!!!!!!!!!!!  
    $firstSelection = checkTitle()
    while $firstSelection <> $secondSelection
        if $firstSelection <> "Current Movies" Then
            movieLookup($firstSelection)
            $secondSelection = $firstSelection
        EndIf
        ExitLoop
    WEnd
    
Wend

Try replacing your while with this.

Edited by youknowwho4eva

Giggity

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  

×