Jump to content
Sign in to follow this  
leomoon

Multi GUI Problem

Recommended Posts

leomoon

Hi, I've made a multi GUI script. The first GUI has a bunch of checkmarks with a button. When you press the button, it will check what is selected and it will run the second GUI which will be used to copy files depending on what was selected in the first GUI. Now the first GUI functions properly but the controls (close button) on the second one won't respond to anything.

Does anybody know what I'm doing wrong?

#include <ButtonConstants.au3>
#include <ProgressConstants.au3>
#include <StaticConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

Opt("GUIOnEventMode", 1)

Global $mainWin, $copyWin, $officeCbox, $itunesCbox, $norton360Cbox, $nortonIS, $pureCbox, $winXp01Cbox, $winXp02Cbox, $winXp03Cbox, $startBtn, $numberOfFiles, $tasks = 0

_mainWin()

Func _mainWin()
    $mainWin = GUICreate("Test Copy", 266, 138)
    GUISetOnEvent($GUI_EVENT_CLOSE, "_onClose")
    $officeCbox = GUICtrlCreateCheckbox("Office 2010", 8, 8, 121, 17)
    GUICtrlSetOnEvent(-1, "_onBtn")
    $itunesCbox = GUICtrlCreateCheckbox("iTunes", 8, 24, 121, 17)
    GUICtrlSetOnEvent(-1, "_onBtn")
    $norton360Cbox = GUICtrlCreateCheckbox("Norton 360", 8, 40, 121, 17)
    GUICtrlSetOnEvent(-1, "_onBtn")
    $nortonIS = GUICtrlCreateCheckbox("Norton Internet S", 8, 56, 121, 17)
    GUICtrlSetOnEvent(-1, "_onBtn")
    $pureCbox = GUICtrlCreateCheckbox("Kaspersky Pure", 136, 8, 121, 17)
    GUICtrlSetOnEvent(-1, "_onBtn")
    $winXp01Cbox = GUICtrlCreateCheckbox("Win XP 01", 136, 24, 121, 17)
    GUICtrlSetOnEvent(-1, "_onBtn")
    $winXp02Cbox = GUICtrlCreateCheckbox("Win XP 02", 136, 40, 121, 17)
    GUICtrlSetOnEvent(-1, "_onBtn")
    $winXp03Cbox = GUICtrlCreateCheckbox("Win XP 03", 136, 56, 121, 17)
    GUICtrlSetOnEvent(-1, "_onBtn")
    $startBtn = GUICtrlCreateButton("Start Test Copy", 8, 80, 249, 49, $WS_GROUP)
    GUICtrlSetOnEvent(-1, "_onBtn")
    GUISetState()

    While 1
        Sleep(10)
    WEnd
EndFunc

Func _copyWin()
    $copyWin = GUICreate("QuickTweak: Copying... ", 370, 97)
    GUISetOnEvent($GUI_EVENT_CLOSE, "_onClose")
    $infoLbl = GUICtrlCreateLabel("Copying Office..."&@LF&'Please Wait...', 8, 5, 360, 54, $SS_CENTER)
    GUICtrlSetFont(-1, 14, 400, 0, "Tahoma")
    $progressBar = GUICtrlCreateProgress(8, 55, 353, 33)
    GUISetState()

    Sleep(1000)
    GUICtrlSetData($progressBar, 10)
    ;finished copying first file
    Sleep(1000)
    GUICtrlSetData($progressBar, 20)
    ;finished copying 2nd file
    Sleep(1000)
    GUICtrlSetData($progressBar, 50)
    ;finished copying 3rd file
    Sleep(1000)
    GUICtrlSetData($progressBar, 100)
    ;finished copying 4th file
    Sleep(1000)
    GUICtrlSetData($infoLbl, "Please Wait...")
    Sleep(1000)
    Exit
EndFunc

Func _onClose()
    Switch @GUI_WinHandle
        Case $mainWin
            Exit
        Case $copyWin
            Exit
;~          $confirmExit = MsgBox(8228,"Oops!","Are you sure you want to delete all the copied files and exit the program?")
;~          If $confirmExit = 6 Then
;~              GUISetState(@SW_HIDE, $confirmExit)
;~              GUISetState(@SW_HIDE, $copyWin)
;~              MsgBox(0, "Done", "All files deleted. Program will exit now.")
;~              Exit
;~          EndIf
    EndSwitch
EndFunc

Func _onBtn()
    Switch @GUI_CTRLID
        Case $startBtn
            If GUICtrlRead($officeCbox) = 1 Then
                $tasks &= "01" & @LF
                $numberOfFiles = $numberOfFiles + 1
            EndIf
            If GUICtrlRead($itunesCbox) = 1 Then
                $tasks &= "02" & @LF
                $numberOfFiles = $numberOfFiles + 1
            EndIf
            If GUICtrlRead($norton360Cbox) = 1 Then
                $tasks &= "03" & @LF
                $numberOfFiles = $numberOfFiles + 1
            EndIf
            If GUICtrlRead($nortonIS) = 1 Then
                $tasks &= "04" & @LF
                $numberOfFiles = $numberOfFiles + 1
            EndIf
            If GUICtrlRead($pureCbox) = 1 Then
                $tasks &= "05" & @LF
                $numberOfFiles = $numberOfFiles + 1
            EndIf
            If GUICtrlRead($winXp01Cbox) = 1 Then
                $tasks &= "06" & @LF
                $numberOfFiles = $numberOfFiles + 1
            EndIf
            If GUICtrlRead($winXp02Cbox) = 1 Then
                $tasks &= "07" & @LF
                $numberOfFiles = $numberOfFiles + 1
            EndIf
            If GUICtrlRead($winXp03Cbox) = 1 Then
                $tasks &= "08" & @LF
                $numberOfFiles = $numberOfFiles + 1
            EndIf
            If $tasks = "" Then
                MsgBox(8240, 'Oops!', "Nothing selected!")
            Else
                $proceed = MsgBox(36,'Proceed...', 'Are you sure?')
                GUISetState(@SW_HIDE, $mainWin)
                _copyWin()
            EndIf
    EndSwitch
EndFunc

Share this post


Link to post
Share on other sites
Melba23

leomoon,

The [X] button on your second GUI is working fine. Remember that AutoIt waits until a function is finished before actioning the next in the queue - so you must wait for _copyWin() to end before the _onClose() function called by pressing the [X] is run (which in fact it never is as you exit directly from _copyWin :) ).

Take a look at the Managing Multiple GUIs and Interrupting a running function tutorials in the Wiki for more information. ;)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.