Jump to content
Sign in to follow this  
cvocvo

Button Problem with Multiple GUI's

Recommended Posts

cvocvo

I'm pretty confused as to why I can't get my buttons to work on a final GUI window.

Basically I have a long program that runs through and formats a drive. If the "Disk Detection: Partition Input" window shows it breaks the final window's buttons, FinalAnalyze(). But if the partition window doesn't show then the final analyze window works fine. The final analyze window also works fine on its own when you put it into its own app.

Here's the section of code I'm having problems with:

$FormPartitionSliderMain = GUICreate(" Disk Detection: Partition Input", 500, 350, 334, 140, $DS_MODALFRAME)
    $Label1 = GUICtrlCreateLabel("Partition Input", 35, 24, 273, 43)
    GUICtrlSetFont($Label1, 24, 400, 0, "Tahoma")
    $NextButton = GUICtrlCreateButton("Next", 400, 265, 80, 49, 0)
    GUICtrlSetOnEvent($NextButton, "NextButtonclick")
    $RecommendedPartitionInput = GUICtrlCreateButton("Use Recommended Settings", 240, 265, 150, 49)
    GUICtrlSetOnEvent($RecommendedPartitionInput, "RecommendedPartitionInput")
    $sMainInputNumber = $sNum
    $label = GUICtrlCreateLabel("Desired Shrink Space (" & $sMainInputNumber & "MB)", 320, 85, 200)
    $hMainInputNumber = GUICtrlCreateInput("", 320, 100, 60, 20)
    GUICtrlSetLimit(-1, 7)
    ;$label = GUICtrlCreateLabel("Enter a Number", 50, 60, 100, 20)
    $UPMainButton = GUICtrlCreateButton("Update", 380, 100, 60, 20)
    GUICtrlSetOnEvent($UPMainButton, "UPMainButtonclick")
    
    $shrinkname = "\shrink.jpg"
    $shrinkpath = @ScriptDir & $shrinkname
    $newpartitionname = "\newpartition.jpg"
    $newpartitionpath = @ScriptDir & $newpartitionname

    If $RadioC = 1 Then
        GUICtrlCreatePic($shrinkpath, 40, 80, 32, 32, BitOR($SS_NOTIFY,$WS_GROUP,$WS_CLIPSIBLINGS))
        GUICtrlCreateLabel("C:\", 15, 90)
        $FreeCSpace = Round(DriveSpaceFree("C:\"), 0)
        $TotalCSpace = Round(DriveSpaceTotal("C:\"), 0)
        $PercentCFree = $FreeCSpace * 100 / $TotalCSpace
        $PercentCFree = Round($PercentCFree, 1) & "%"
        GUICtrlCreateLabel($FreeCSpace & " of " & $TotalCSpace & "MB Free " & $PercentCFree, 80, 85)
        GUICtrlCreateLabel("Available Shrink Space: " & $sNum & "MB", 80, 100)
        If $DriveDPartition = 1 Then
            If $DriveEPartition = 1 Then
                $DriveD = GUICtrlCreatePic($newpartitionpath, 40, 145, 32, 32, BitOR($SS_NOTIFY,$WS_GROUP,$WS_CLIPSIBLINGS))
                GUICtrlCreateLabel("D:\", 15, 155)
                $sDriveDInput = $sNum - 1024
                $dlabel = GUICtrlCreateLabel("Desired Partition Size (" & $sDriveDInput & "MB)", 80, 155, 200)
            
                $DriveE = GUICtrlCreatePic($newpartitionpath, 40, 210, 32, 32, BitOR($SS_NOTIFY,$WS_GROUP,$WS_CLIPSIBLINGS))
                GUICtrlCreateLabel("E:\", 15, 220)
                $sDriveEInput = 1024
                $elabel = GUICtrlCreateLabel("Desired Partition Size (" & $sDriveEInput & "MB)", 80, 220, 200)
            Else
                $DriveD = GUICtrlCreatePic($newpartitionpath, 40, 145, 32, 32, BitOR($SS_NOTIFY,$WS_GROUP,$WS_CLIPSIBLINGS))
                GUICtrlCreateLabel("D:\", 15, 155)
                $sDriveDInput = $sNum
                $dlabel = GUICtrlCreateLabel("Desired Partition Size (" & $sDriveDInput & "MB)", 80, 155, 200)
            EndIf
        Else
            $DriveE = GUICtrlCreatePic($newpartitionpath, 40, 145, 32, 32, BitOR($SS_NOTIFY,$WS_GROUP,$WS_CLIPSIBLINGS))
            GUICtrlCreateLabel("E:\", 15, 155)
            $sDriveEInput = $sNum
            $dlabel = GUICtrlCreateLabel("Desired Partition Size (" & $sDriveEInput & "MB)", 80, 155, 200)
            GUICtrlSetLimit(-1, 7)
        EndIf
    ElseIf $RadioD = 1 Then
        GUICtrlCreatePic($shrinkpath, 40, 80, 32, 32, BitOR($SS_NOTIFY,$WS_GROUP,$WS_CLIPSIBLINGS))
        GUICtrlCreateLabel("D:\", 15, 90)
        $FreeDSpace = Round(DriveSpaceFree("D:\"), 0)
        $TotalDSpace = Round(DriveSpaceTotal("D:\"), 0)
        $PercentDFree = $FreeDSpace * 100 / $TotalDSpace
        $PercentDFree = Round($PercentDFree, 1) & "%)"
        GUICtrlCreateLabel("(" & $FreeDSpace & " of " & $TotalDSpace & "MB Free " & $PercentDFree, 80, 85)
        
        $DriveE = GUICtrlCreatePic($newpartitionpath, 40, 145, 32, 32, BitOR($SS_NOTIFY,$WS_GROUP,$WS_CLIPSIBLINGS))
        GUICtrlCreateLabel("E:\", 15, 155)
        $sDriveEInput = $sNum
        $dlabel = GUICtrlCreateLabel("Desired Partition Size (" & $sDriveEInput & "MB)", 80, 155, 200)
        GUICtrlSetLimit(-1, 7)
    
    ElseIF $RadioE = 1 Then
        GUICtrlCreatePic($shrinkpath, 40, 80, 32, 32, BitOR($SS_NOTIFY,$WS_GROUP,$WS_CLIPSIBLINGS))
        GUICtrlCreateLabel("E:\", 15, 90)
        $FreeESpace = Round(DriveSpaceFree("E:\"), 0)
        $TotalESpace = Round(DriveSpaceTotal("E:\"), 0)
        $PercentEFree = $FreeESpace * 100 / $TotalESpace
        $PercentEFree = Round($PercentEFree, 1) & "%)"
        GUICtrlCreateLabel("(" & $FreeESpace & " of " & $TotalESpace & "MB Free " & $PercentEFree, 80, 90)
        
        $DriveD = GUICtrlCreatePic($newpartitionpath, 40, 145, 32, 32, BitOR($SS_NOTIFY,$WS_GROUP,$WS_CLIPSIBLINGS))
        GUICtrlCreateLabel("D:\", 15, 155)
        $sDriveDInput = $sNum
        $dlabel = GUICtrlCreateLabel("Desired Partition Size (" & $sDriveDInput & "MB)", 80, 155, 200)
        GUICtrlSetLimit(-1, 7)
    EndIf
    GUISetState(@SW_SHOW)

    While 1
        _Input_Check($hMainInputNumber, False) ; False means limit to numbers
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE, $NextButton
                NextButton_PartitionInputMain()
                ExitLoop
            Case $GUI_EVENT_CLOSE, $RecommendedPartitionInput
                RecommendedPartitionInput()
            Case $GUI_EVENT_CLOSE, $UPMainButton
                UPMainButtonclick()
        EndSwitch
    WEnd
EndFunc
Func RecommendedPartitionInput()
    If $sNum > 1056 Then
        $sMainInputNumber = $sNum
        GUICtrlSetData($label, "Desired Shrink Space (" & $sMainInputNumber & "MB)")
        $sDriveDInput = $sNum - 1024
        GUICtrlSetData($dlabel, "Desired Partition Size (" & $sDriveDInput & "MB)")
        $sDriveEInput = 1024
        GUICtrlSetData($elabel, "Desired Partition Size (" & $sDriveEInput & "MB)")
        $UpdateCount = 0
        NextButton_PartitionInputMain()
    ElseIf $sNum > 544 Then
        $sMainInputNumber = $sNum
        GUICtrlSetData($label, "Desired Shrink Space (" & $sMainInputNumber & "MB)")
        $sDriveDInput = $sNum - 512
        GUICtrlSetData($dlabel, "Desired Partition Size (" & $sDriveDInput & "MB)")
        $sDriveEInput = 512
        GUICtrlSetData($elabel, "Desired Partition Size (" & $sDriveEInput & "MB)")
        $UpdateCount = 0
        NextButton_PartitionInputMain()
    Else
        MsgBox(0, "Error", "Your system does not meet the minimum drive shrink space specifications.")
        Exit
    EndIf
EndFunc
Func NextButton_PartitionInputMain()
    Local $AreYouSureLocalCount
    $bad = 0
    If $UpdateCount = 0 Then
        AreYouSure()
        $AreYouSureLocalCount = 1
    Else
        If GUICtrlRead($hMainInputNumber) = "" Then
            MsgBox(0, "Error", "You must input a number for the desired shrink partition size, or click the recommended settings button.")
            $bad = $bad + 1
        EndIf
        If GUICtrlRead($hMainInputNumber) = 0 Then
            MsgBox(0, "Error", "You must input a number for the desired shrink partition size, or click the recommended settings button.")
            $bad = $bad + 1
        EndIf
    EndIf
    If $bad = 0 Then
        If $AreYouSureLocalCount = 0 Then
            AreYouSure()
        EndIf
    EndIf
EndFunc
Func AreYouSure()
    If $RadioC = 1 Then
        If $DriveDPartition = 1 Then
            If $DriveEPartition = 1 Then
                $continue = MsgBox(4, "", "If the following information is correct, click 'YES' to continue, otherwise click 'NO'." & @CRLF _
                & "Desired C:\ Shrink Size: " & $sMainInputNumber & "MB" & @CRLF _
                & "Size of future D:\ partition: " & $sDriveDInput & "MB" & @CRLF _
                & "Size of future E:\ partition: " & $sDriveEInput & "MB")
            Else
                $continue = MsgBox(4, "", "If the following information is correct, click 'YES' to continue, otherwise click 'NO'." & @CRLF _
                & "Desired C:\ Shrink Size: " & $sMainInputNumber & "MB" & @CRLF _
                & "Size of future D:\ partition: " & $sDriveDInput & "MB")
            
            EndIf
        ElseIf $DriveEPartition = 1 Then
            $continue = MsgBox(4, "", "If the following information is correct, click 'YES' to continue, otherwise click 'NO'." & @CRLF _
            & "Desired C:\ Shrink Size: " & $sMainInputNumber & "MB" & @CRLF _
            & "Size of future E:\ partition: " & $sDriveEInput & "MB")
        EndIf
    ElseIf $RadioD = 1 Then
        If $DriveEPartition = 1 Then
            $continue = MsgBox(4, "", "If the following information is correct, click 'YES' to continue, otherwise click 'NO'." & @CRLF _
            & "Desired D:\ Shrink Size: " & $sMainInputNumber & "MB" & @CRLF _
            & "Size of future E:\ partition: " & $sDriveEInput & "MB")
        EndIf
    ElseIf $RadioE = 1 Then
        If $DriveDPartition = 1 Then
            $continue = MsgBox(4, "", "If the following information is correct, click 'YES' to continue, otherwise click 'NO'." & @CRLF _
            & "Desired E:\ Shrink Size: " & $sMainInputNumber & "MB" & @CRLF _
            & "Size of future D:\ partition: " & $sDriveEInput & "MB")
        EndIf
    EndIf
    If $continue = 6 Then
        GUIDelete()
        DoPartition()
    EndIf
EndFunc
Func UPMainButtonclick()
    $bad = 0
    $UpdateCount = $UpdateCount + 1
    If GUICtrlRead($hMainInputNumber) > $sNum Then
        MsgBox(0, "Error", "Desired shrink space may not exceed available shrink space")
        GUICtrlSetData($hMainInputNumber, $sNum)
        $sMainInputNumber = GUICtrlRead($hMainInputNumber)  
        GUICtrlSetData($label, "Desired Shrink Space (" & $sMainInputNumber & "MB)")
        $bad = $bad + 1
    EndIf
    If GUICtrlRead($hMainInputNumber) < 544 Then
        If $DriveEPartition = 1 Then
            If $DriveDPartition = 1 Then
                MsgBox(0, "Error", "You selected to create Drives D:\ and E:\ -- the minimum space required for D:\ is 32MB, E:\ is 512MB")
                $bad = $bad + 1
            EndIf
        EndIf
    EndIf
    If $bad = 0 Then
        If GUICtrlRead($hMainInputNumber) < 512 Then
            If $DriveEPartition = 1 Then
                MsgBox(0, "Error", "You selected to create Drive E:\ -- the minimum space required for Drive E:\ is 512MB, recommended 1024MB")
                $bad = $bad + 1
            EndIf
        EndIf
        If GUICtrlRead($hMainInputNumber) < 32 Then
            If $DriveDPartition = 1 Then
                MsgBox(0, "Error", "You selected to create Drive D:\ -- the minimum space required for Drive D:\ is 32MB")
                $bad = $bad + 1
            EndIf
        EndIf
    EndIf
    If $bad = 0 Then
        $sMainInputNumber = GUICtrlRead($hMainInputNumber)  
        GUICtrlSetData($label, "Desired Shrink Space (" & $sMainInputNumber & "MB)")
        If $DriveDPartition = 1 Then
            If $DriveEPartition = 1 Then
                $sDriveDInput = GUICtrlRead($hMainInputNumber) - 512
                GUICtrlSetData($dlabel, "Desired Shrink Space (" & $sDriveDInput & "MB)")
                $sDriveEInput = 512
                GUICtrlSetData($elabel, "Desired Shrink Space (" & $sDriveEInput & "MB)")
            EndIf
        ElseIf $DriveDPartition = 0 Then
            If $DriveEPartition = 1 Then
                $sDriveEInput = 512
                GUICtrlSetData($elabel, "Desired Shrink Space (" & $sDriveEInput & "MB)")
            EndIf
        EndIf
    EndIf
EndFunc
Func _Input_Check($hMainInputNumber, $fLetterFlag = True)
    ; Read input
    $sText = GUICtrlRead($hMainInputNumber)
    If $fLetterFlag Then
        ; Upper case the input and reset the content
        $sText = StringUpper($sText)
        GUICtrlSetData($hMainInputNumber, $sText)
    EndIf

    ; Check if there are any unwanted characters
    $sMsg = ""
    If $fLetterFlag Then
        ; And if so delete the non-letters
        If StringRegExp($sText, "[^A-Z]") Then GUICtrlSetData($hMainInputNumber, StringRegExpReplace($sText, "[^A-Z]", ""))
    Else
        ; And if so delete the non-numbers
        If StringRegExp($sText, "[^0-9]") Then GUICtrlSetData($hMainInputNumber, StringRegExpReplace($sText, "[^0-9]", ""))
    EndIf
EndFunc

Func DoPartition()
Opt("GUIOnEventMode", 1)
GUICreate(" Detection: Apply Partition Changes", 350, 100, -1, -1, $DS_MODALFRAME)
GUICtrlCreateLabel("Please wait while we apply the selected changes.", 10, 10, 330, 20)
GUICtrlCreateLabel("This make take upwards of 10-15 minutes depending upon hardware.", 10, 30, 330, 20)
$Status = GUICtrlCreateLabel("Status: Starting...", 10, 50, 330, 20)
GUISetState()
If $RadioC = 1 Then
    $ShrinkDrive = "C"
ElseIf $RadioD = 1 Then
    $ShrinkDrive = "D"
ElseIf $RadioE = 1 Then
    $ShrinkDrive = "E"
EndIf
;;;;Shrink Selected Partition
GUICtrlSetData($Status, "Status: Shrinking partition on drive " & $ShrinkDrive & ":\")
FileDelete(@tempdir & "\shrinkdrive.s")
$scriptwrite = FileOpen(@tempdir & "\shrinkdrive.s", 1)
FileWrite($scriptwrite,"select volume=" & $ShrinkDrive & @crlf)
FileWrite($scriptwrite,"shrink desired=" & $sMainInputNumber & @crlf)
FileWrite($scriptwrite,"Exit")
FileClose($scriptwrite)
$filename = "\shrinkdrive.s"
$fullpath = @tempdir & $filename
RunWait(@ComSpec & " /c diskpart /S " & $fullpath, "", @SW_HIDE, 0x02)
FileDelete(@tempdir & "\shrinkdrive.s")
;;;;Create Partitions
If $DriveDPartition = 1 Then
    If $DriveEPartition = 1 Then
        DoPartDnE()
        WinClose("Microsoft Windows", "Format disk")
        WinClose("Microsoft Windows", "Format disk")
        FormatD()
        WinClose("AutoPlay", "Local Disk (D:)")
        FormatE()
        WinClose("AutoPlay", "Local Disk (E:)")
    Else
        DoPartD()
        WinClose("Microsoft Windows", "Format disk")
        FormatD()
        WinClose("AutoPlay", "Local Disk (D:)")
    EndIf
ElseIf $DriveEPartition = 1 Then
    DoPartE()
    WinClose("Microsoft Windows", "Format disk")
    FormatE()
    WinClose("AutoPlay", "Local Disk (E:)")
EndIf
$FinalAnalyze = 1
GUIDelete()
Analyze()
EndFunc

Func FormatE()
    GUICtrlSetData($Status, "Status: Formatting partition on drive E:\")
    RunWait(@ComSpec & " /c format e: /FS:NTFS /Q /X /Y", "", @SW_HIDE)
EndFunc

Func FormatD()
    GUICtrlSetData($Status, "Status: Formatting partition on drive D:\")
    RunWait(@ComSpec & " /c format d: /FS:NTFS /Q /X /Y", "", @SW_HIDE)
EndFunc

Func DoPartDnE()
    GUICtrlSetData($Status, "Status: Creating partitions on drives D:\ and E:\")
    FileDelete(@tempdir & "\makeDnE.s")
    $scriptwrite = FileOpen(@tempdir & "\makeDnE.s", 1)
    FileWrite($scriptwrite,"select volume=" & $ShrinkDrive & @crlf)
    ;FileWrite($scriptwrite,"create partition extended" & @crlf)
    FileWrite($scriptwrite,"create partition logical size=" & $sDriveEInput & @crlf)
    FileWrite($scriptwrite,"assign letter=e:" & @crlf)
    FileWrite($scriptwrite,"create partition logical" & @crlf)
    FileWrite($scriptwrite,"assign letter=d:" & @crlf)
    FileWrite($scriptwrite,"Exit")
    FileClose($scriptwrite)
    $filename = "\makeDnE.s"
    $fullpath = @tempdir & $filename
    RunWait(@ComSpec & " /c diskpart /S " & $fullpath, "", @SW_HIDE, 0x02)
    FileDelete(@tempdir & "\makeDnE.s")
EndFunc

Func DoPartD()
    GUICtrlSetData($Status, "Status: Creating partition on drive D:\")
    FileDelete(@tempdir & "\makeD.s")
    $scriptwrite = FileOpen(@tempdir & "\makeD.s", 1)
    FileWrite($scriptwrite,"select volume=" & $ShrinkDrive & @crlf)
    ;FileWrite($scriptwrite,"create partition extended" & @crlf)
    FileWrite($scriptwrite,"create partition logical" & @crlf)
    FileWrite($scriptwrite,"assign letter=d:" & @crlf)
    FileWrite($scriptwrite,"Exit")
    FileClose($scriptwrite)
    $filename = "\makeD.s"
    $fullpath = @tempdir & $filename
    RunWait(@ComSpec & " /c diskpart /S " & $fullpath, "", @SW_HIDE, 0x02)
    FileDelete(@tempdir & "\makeD.s")
EndFunc

Func DoPartE()
    GUICtrlSetData($Status, "Status: Creating partition on drive E:\")
    FileDelete(@tempdir & "\makeE.s")
    $scriptwrite = FileOpen(@tempdir & "\makeE.s", 1)
    FileWrite($scriptwrite,"select volume=" & $ShrinkDrive & @crlf)
    ;FileWrite($scriptwrite,"create partition extended" & @crlf)
    FileWrite($scriptwrite,"create partition logical" & @crlf)
    FileWrite($scriptwrite,"assign letter=e:" & @crlf)
    FileWrite($scriptwrite,"Exit")
    FileClose($scriptwrite)
    $filename = "\makeE.s"
    $fullpath = @tempdir & $filename
    RunWait(@ComSpec & " /c diskpart /S " & $fullpath, "", @SW_HIDE, 0x02)
    FileDelete(@tempdir & "\makeE.s")
EndFunc

Func FinalAnalyze()
Opt("WinTitleMatchMode", 2)
Opt("GUIOnEventMode", 1)
Sleep(3000)
WinClose("AutoPlay", "Local Disk (D:)")
WinClose("AutoPlay", "Local Disk (E:)")
WinClose("Microsoft Windows", "Format disk")
WinClose("Microsoft Windows", "Format disk")

Local $localbad = 0, $allgood = 0
$FormPassFail = GUICreate(" Disk Detection: Final Results", 500, 350, 334, 140, $DS_MODALFRAME)
$Label1 = GUICtrlCreateLabel("Final Results", 35, 24, 273, 43)
GUICtrlSetFont($Label1, 24, 400, 0, "Tahoma")
$folderloc = @ScriptDir
$goodname = "\good.jpg"
$goodpath = $folderloc & $goodname
$badname = "\bad.jpg"
$badpath = $folderloc & $badname
If $CState = "Good" Then
    If $DState = "Good" Then
        If $Estate = "Good" Then
            $allgood = 1
            GUICtrlCreatePic($goodpath, 40, 80, 32, 32, BitOR($SS_NOTIFY,$WS_GROUP,$WS_CLIPSIBLINGS))
            GUICtrlCreateLabel("All drives are ready.", 80, 90, 410, 17)
        EndIf
    EndIf
EndIf
If $allgood = 0 Then
    If $CState = "Good" Then
        GUICtrlCreatePic($goodpath, 40, 80, 32, 32, BitOR($SS_NOTIFY,$WS_GROUP,$WS_CLIPSIBLINGS))
        GUICtrlCreateLabel("Drive C is ready.", 80, 100, 410, 17)
    ElseIf $CState = "Bad" Then
        $localbad = $localbad + 1
        GUICtrlCreatePic($badpath, 40, 80, 32, 32, BitOR($SS_NOTIFY,$WS_GROUP,$WS_CLIPSIBLINGS))
        GUICtrlCreateLabel("Drive C is not ready.", 80, 90, 410, 17)
        GUICtrlCreateLabel("Requirements: Drive C must be a fixed disk and contain the Windows installation.", 80, 115, 410, 17)
    EndIf
    If $DState = "Good" Then
        GUICtrlCreatePic($goodpath, 40, 145, 32, 32, BitOR($SS_NOTIFY,$WS_GROUP,$WS_CLIPSIBLINGS))
        GUICtrlCreateLabel("Drive D is ready.", 80, 155, 410, 17)
    ElseIf $DState = "Bad" Then
        $localbad = $localbad + 1
        GUICtrlCreatePic($badpath, 40, 145, 32, 32, BitOR($SS_NOTIFY,$WS_GROUP,$WS_CLIPSIBLINGS))
        GUICtrlCreateLabel("Drive D is not ready.", 80, 145, 410, 17)
        GUICtrlCreateLabel("Requirements: Drive D must be a fixed disk or ramdisk and be user writable.", 80, 170, 410, 17)
    EndIf
    If $EState = "Good" Then
        GUICtrlCreatePic($goodpath, 40, 210, 32, 32, BitOR($SS_NOTIFY,$WS_GROUP,$WS_CLIPSIBLINGS))
        GUICtrlCreateLabel("Drive E is ready.", 80, 220, 410, 17)
    ElseIf $EState = "Bad" Then
        $localbad = $localbad + 1
        GUICtrlCreatePic($badpath, 40, 210, 32, 32, BitOR($SS_NOTIFY,$WS_GROUP,$WS_CLIPSIBLINGS))
        GUICtrlCreateLabel("Drive E is not ready.", 80, 210, 410, 17)
        GUICtrlCreateLabel("Requirements: Drive E must be a fixed disk and be user writable for temporary files.", 80, 235, 410, 17)
    EndIf
EndIf
$EndButton = GUICtrlCreateButton("Finish", 376, 265, 105, 49, 0)
;GUICtrlSetOnEvent($EndButton, "EndButtonclick")
If $localbad <> 0 Then
    $ReChooseFixesButton = GUICtrlCreateButton("Try Again", 250, 265, 105, 49, 0)
    ;GUICtrlSetOnEvent($ReChooseFixesButton, "ReChooseFixes")
;Else
;   $ReChooseFixesButton = "" 
;EndIf
;While 1
;   Switch GUIGetMsg()
;       Case $GUI_EVENT_CLOSE, $EndButton
;           Exit
;           EndButtonclick()
;       Case $GUI_EVENT_CLOSE, $ReChooseFixesButton
;           Exit
;           ReChooseFixes()
;   EndSwitch
;WEnd
GUISetState(@SW_SHOW)
;Sleep(360000)
EndFunc
Func EndButtonclick()
    MsgBox(0, "Success", "All of your drives are ready.  Disk Detection will now exit")
    Exit
EndFunc
Func ReChooseFixes()
    ChooseFixes()
EndFunc

As you can see at the end, I've tried various loops and sleeps and different iterations of those things, but I haven't found a solution yet. I've also tried using both settings for "GUIOnEventMode".

If anyone has any input on this, I'm stumped. Again, I think it has to do with the *necessary loop in the partition window, but I can't put my finger on it.

Also if it helps, here is a working version of the final window that I put into its own app to prove that it works on its own.

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <GUITreeView.au3>
#include <Date.au3>


$CState = "Good"
$DState = "Good"
$EState = "Good"

FinalAnalyze()
Sleep(30000)

Func FinalAnalyze()
Opt("WinTitleMatchMode", 2)
Opt("GUIOnEventMode", 1)

Local $localbad = 0, $allgood = 0
$FormPassFail = GUICreate(" Disk Detection: Final Results", 500, 350, 334, 140, $DS_MODALFRAME)
$Label1 = GUICtrlCreateLabel("Final Results", 35, 24, 273, 43)
GUICtrlSetFont($Label1, 24, 400, 0, "Tahoma")
$folderloc = @ScriptDir
$goodname = "\good.jpg"
$goodpath = $folderloc & $goodname
$badname = "\bad.jpg"
$badpath = $folderloc & $badname
If $CState = "Good" Then
    If $DState = "Good" Then
        If $Estate = "Good" Then
            $allgood = 1
            GUICtrlCreatePic($goodpath, 40, 80, 32, 32, BitOR($SS_NOTIFY,$WS_GROUP,$WS_CLIPSIBLINGS))
            GUICtrlCreateLabel("All drives are ready.", 80, 90, 410, 17)
        EndIf
    EndIf
EndIf
If $allgood = 0 Then
    If $CState = "Good" Then
        GUICtrlCreatePic($goodpath, 40, 80, 32, 32, BitOR($SS_NOTIFY,$WS_GROUP,$WS_CLIPSIBLINGS))
        GUICtrlCreateLabel("Drive C is ready.", 80, 100, 410, 17)
    ElseIf $CState = "Bad" Then
        $localbad = $localbad + 1
        GUICtrlCreatePic($badpath, 40, 80, 32, 32, BitOR($SS_NOTIFY,$WS_GROUP,$WS_CLIPSIBLINGS))
        GUICtrlCreateLabel("Drive C is not ready.", 80, 90, 410, 17)
        GUICtrlCreateLabel("Requirements: Drive C must be a fixed disk and contain the Windows installation.", 80, 115, 410, 17)
    EndIf
    If $DState = "Good" Then
        GUICtrlCreatePic($goodpath, 40, 145, 32, 32, BitOR($SS_NOTIFY,$WS_GROUP,$WS_CLIPSIBLINGS))
        GUICtrlCreateLabel("Drive D is ready.", 80, 155, 410, 17)
    ElseIf $DState = "Bad" Then
        $localbad = $localbad + 1
        GUICtrlCreatePic($badpath, 40, 145, 32, 32, BitOR($SS_NOTIFY,$WS_GROUP,$WS_CLIPSIBLINGS))
        GUICtrlCreateLabel("Drive D is not ready.", 80, 145, 410, 17)
        GUICtrlCreateLabel("Requirements: Drive D must be a fixed disk or ramdisk and be user writable.", 80, 170, 410, 17)
    EndIf
    If $EState = "Good" Then
        GUICtrlCreatePic($goodpath, 40, 210, 32, 32, BitOR($SS_NOTIFY,$WS_GROUP,$WS_CLIPSIBLINGS))
        GUICtrlCreateLabel("Drive E is ready.", 80, 220, 410, 17)
    ElseIf $EState = "Bad" Then
        $localbad = $localbad + 1
        GUICtrlCreatePic($badpath, 40, 210, 32, 32, BitOR($SS_NOTIFY,$WS_GROUP,$WS_CLIPSIBLINGS))
        GUICtrlCreateLabel("Drive E is not ready.", 80, 210, 410, 17)
        GUICtrlCreateLabel("Requirements: Drive E must be a fixed disk and be user writable for temporary files.", 80, 235, 410, 17)
    EndIf
EndIf
$EndButton = GUICtrlCreateButton("Finish", 376, 265, 105, 49, 0)
GUICtrlSetOnEvent($EndButton, "EndButtonclick")
If $localbad <> 0 Then
    $ReChooseFixesButton = GUICtrlCreateButton("Try Again", 250, 265, 105, 49, 0)
    GUICtrlSetOnEvent($ReChooseFixesButton, "ReChooseFixes")
;Else
;   $ReChooseFixesButton = ""
EndIf
GUISetState(@SW_SHOW)
;While 1
;   Switch GUIGetMsg()
;       Case $GUI_EVENT_CLOSE, $EndButton
;           EndButtonclick()
;       Case $GUI_EVENT_CLOSE, $ReChooseFixesButton
;           ReChooseFixes()
;   EndSwitch
;WEnd
EndFunc
Func EndButtonclick()
    MsgBox(0, "Success", "All of your drives are ready.  Disk Detection will now exit")
    Exit
EndFunc
Func ReChooseFixes()
    ChooseFixes()
EndFunc

Share this post


Link to post
Share on other sites
Melba23

cvocvo,

I see Opt("GUIOnEventMode", 1) lines and Switch GUIGetMsg() lines in your code. Are you changing mode in the same script? If so, I would imagine that is where the problem lies. :P

You should stick with the one mode unless there are exceptional circumstances - and then alarm bells should be sounding asking why the circumstances are exceptional and whether it would not be more sensible to recast the code.

So my advice, rewrite your script to use only one mode. If you still have problems then come back. :mellow:

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

 

Share this post


Link to post
Share on other sites
PsaltyDS

GUIGetMsg() needs to be used with the advanced flag (and not with GuiOnEventMode at all!) if you have multiple GUIs active at once. Otherwise, it only sees the messages from the last GUI. You could use GuiSwitch() to determine which GUI is polled by GuiGetMsg(), but that's a little crazy to keep track of. Either use the advanced flag and watch the window handle in [1] to know which window the message came from, or switch your ENTIRE script to event mode.

:mellow:

Edit: Been Melba toasted. Also didn't notice GuiOnEventMode was mixed in there.

Edited by PsaltyDS

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites
cvocvo

So for all intensive purposes, I really just need to rewrite the Partition Input GUI function?

The rest of my script is currently using GUIOnEventMode, so I just really need to convert this chunk of code to something else:

While 1
        _Input_Check($hMainInputNumber, False) ; False means limit to numbers
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE, $NextButton
                NextButton_PartitionInputMain()
                ExitLoop
            Case $GUI_EVENT_CLOSE, $RecommendedPartitionInput
                RecommendedPartitionInput()
            Case $GUI_EVENT_CLOSE, $UPMainButton
                UPMainButtonclick()
        EndSwitch
    WEnd

The _Input_Check has to be in a loop because it's constantly looking at the input box to make sure that the characters are only what I specify. The rest of it doesn't need to be a loop, just needs to retain button functionality.

I don't think it'd be hard to change GUIGetMsg() into GUIOnEventMode because I've been using the later all along. But, how would I retain button functionality so they don't get ignored by an infinite loop but still maintain a loop to keep the _Input_Check?

Edit: Also, I'm only using one visible GUI at a time.

Edited by cvocvo

Share this post


Link to post
Share on other sites
PsaltyDS

Just change the loop to:

While 1
        _Input_Check($hMainInputNumber, False) ; False means limit to numbers
        Sleep(10)
    WEnd

Then put GuiCtrlSetOnEvent(-1, "_ButtonHit") after the creation of each button, and this:

Func _ButtonHit()
        Switch @GUI_CTRLID
            Case $NextButton
                NextButton_PartitionInputMain()
            Case $RecommendedPartitionInput
                RecommendedPartitionInput()
            Case $UPMainButton
                UPMainButtonclick()
        EndSwitch
EndFunc

I didn't understand why you had $GUI_EVENT_CLOSE in there, so you'll need a GuiSetOnEvent($GUI_EVENT_CLOSE, "_GuiClose") function too.

:mellow:


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites
cvocvo

I changed my code to try and implement your solution, but it doesn't seem to work. I *believe* that it gets stuck in the loop:

While 1
        _Input_Check($hMainInputNumber, False) ; False means limit to numbers
        Sleep(10)
    WEnd

My buttons look like this:

$UPMainButton = GUICtrlCreateButton("Update", 380, 100, 60, 20)
    GuiCtrlSetOnEvent(-1, "_ButtonHit")
    $NextButton = GUICtrlCreateButton("Next", 400, 265, 80, 49, 0)
    GuiCtrlSetOnEvent(-1, "_ButtonHit")
    $RecommendedPartitionInput = GUICtrlCreateButton("Use Recommended Settings", 240, 265, 150, 49)
    GuiCtrlSetOnEvent(-1, "_ButtonHit")

I set Opt("GUIOnEventMode", 1) instead of 0, so that should be fine; I also made $NextButton, $RecommendedPartitionInput, and $UPMainButton global variables so that shouldn't be a problem.

I know the loop is running because the check to disallow typing letters into the input box is working. My theory is the loop is not allowing any of the button clicks to be heard.

Ideas?

Edit: I also tried using this loop in-conjunction with GUICtrlSetOnEvent(-1, "_ButtonHit")

While 1
        _Input_Check($hMainInputNumber, False) ; False means limit to numbers
        $msg = GUIGetMsg()
        If $msg = $NextButton Then
            NextButton_PartitionInputMain()
        ElseIf $msg = $RecommendedPartitionInput Then
            RecommendedPartitionInput()
        ElseIf $msg = $UPMainButton Then
            UPMainButtonclick()
        EndIf
    WEnd

-->Just also realized that was pointless.

I'm also looking at the GUISetOnEvent help page example and I don't know why the proposed solution wouldn't work -- It's pretty similar code.

Edit2: Well I don't have a solution to the problem but I do have a bad workaround. Basically, the work around is to leave the Partition Input function with it's GUIGetMsg() buttons, and then use a MsgBox() on the final window to let people decide what they want to do. Not exactly elegant or what I want..but functional for the moment.

Edited by cvocvo

Share this post


Link to post
Share on other sites
PsaltyDS

In general, when you are using event mode, there is supposed to be a short loop somewhere that the script sits in while there is no other tasking. I thought that loop might be the right place for it, but didn't look through the long script that far, so maybe not. The only real point is to handle all events with very quick functions and get back to the "home" loop as quickly as possible. The home loop kicks off the real work as the event handlers set or clear global flags, for instance.

For example, if you click a "RUN" button on a GUI, all the handler does is set Global $f_RUN = True, and return. The home loop sees If $f_RUN Then, and kicks off the function that does the real work. Since the hard work doesn't happen inside the event handling function, other events are not blocked in the mean time.

:blink:

Edited by PsaltyDS

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

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  

×