Jump to content

GUICtrlCreateCheckbox y GUICtrlCreateProgress


Go to solution Solved by Andreik,

Recommended Posts

Posted

Good morning, I have a question when executing my script, the selected option is not synchronized with the identification that I put in it and the progress bar, the programs do install perfectly but Dropbox is installed, for example, and the identification tells me that it is being installed chrome

#include <GuiButton.au3>
#include <GUIConstants.au3>
#include <WindowsConstants.au3>

Opt("MustDeclareVars", 1)

Global $FileChrome = "Programas\Chrome64.exe /silent /install"
Global $FileAdobe = "Programas\AdobeDC.exe /sAll /sPB"
Global $FileDropbox = "Programas\Dropbox86.exe /S"
Global $FileOffice = "Programas\Office2013x64\setup.exe"
Global $FileIso = "Programas\UltraISO.exe /VERYSILENT"

;Variables
Global $Ini, $VPinc, $Checkbox1, $Checkbox2, $Checkbox3, $Checkbox4, $Checkbox5, $Checkbox6, $Progress1
Global $label1, $label2, $label3, $label4, $label5

$VPinc = GUICreate("Instalacion de Programas", 407, 355, -1, -1)
GUISetBkColor(0xFFFFFF)

$Ini = GUICtrlCreateButton("Instalar Programas", 100, 16, 200, 30)
GUICtrlSetFont(-1, 12, 800, 2, "Times New Roman")
GUICtrlSetCursor (-1, 0)

$Checkbox1 = GUICtrlCreateCheckbox("Google Chrome", 29, 74, 129, 20)
GUICtrlSetFont(-1, 11, 800, 2, "Times New Roman")

$Checkbox2 = GUICtrlCreateCheckbox("Adobe Acrobat DC", 29, 98, 145, 20)
GUICtrlSetFont(-1, 11, 800, 2, "Times New Roman")

$Checkbox3 = GUICtrlCreateCheckbox("Dropbox", 29, 122, 81, 20)
GUICtrlSetFont(-1, 11, 800, 2, "Times New Roman")

$Checkbox4 = GUICtrlCreateCheckbox("Microsoft Office 2013", 29, 146, 161, 20)
GUICtrlSetFont(-1, 11, 800, 2, "Times New Roman")

$Checkbox5 = GUICtrlCreateCheckbox("Ultra ISO", 29, 170, 89, 20)
GUICtrlSetFont(-1, 11, 800, 2, "Times New Roman")

$Checkbox6 = GUICtrlCreateCheckbox("Seleccionar Todo", 253, 67, 129, 20)
GUICtrlSetFont(-1, 11, 800, 2, "Times New Roman")

$Progress1 = GUICtrlCreateProgress(32, 288, 337, 25, $PBS_SMOOTH)
GUICtrlSetColor(-1, 0x008000)

GUICtrlCreateLabel("Precione ESC para Salir", 129, 328, 160, 22)
GUICtrlSetFont(-1, 11, 800, 2, "Times New Roman")

GUISetState()
Global $idMsg = 0

While 1
    $idMsg = GUIGetMsg()
    Switch $idMsg
        Case $GUI_EVENT_CLOSE
            Exit

        Case $Checkbox6
            _CheckAll()

        Case $Ini
        If _IsChecked($Checkbox1) Then RunWait(@ComSpec & " /c " & $FileChrome, "", @SW_HIDE, "")
            $label1 = GUICtrlCreateLabel("Instalando Google Chrome" , 90, 240, 224, 22, $SS_CENTER)
            GUICtrlSetFont($label1, 11, 800, 2, "Times New Roman")
             GUICtrlSetColor($label1, 0x008000)

            _SendMessage(GUICtrlGetHandle($Progress1), 20)
            GUICtrlSetData($Progress1, 20)

        If _IsChecked($Checkbox2) Then RunWait(@ComSpec & " /c " & $FileAdobe,"", @SW_HIDE,"")
            $label2 = GUICtrlCreateLabel("Instalando Adobe Acrobat DC", 90, 240, 224, 22, $SS_CENTER)
            GUICtrlSetFont($label2, 11, 800, 2, "Times New Roman")
             GUICtrlSetColor($label2, 0x008000)

            _SendMessage(GUICtrlGetHandle($Progress1), 40)
            GUICtrlSetData($Progress1, 40)

        If _IsChecked($Checkbox3) Then RunWait(@ComSpec & " /c "  & $FileDropbox, "", @SW_HIDE,"")
            $label3 = GUICtrlCreateLabel("Instalando Dropbox" , 90, 240, 224, 22, $SS_CENTER)
            GUICtrlSetFont($label3, 11, 800, 2, "Times New Roman")
             GUICtrlSetColor($label3, 0x008000)

            _SendMessage(GUICtrlGetHandle($Progress1), 60)
            GUICtrlSetData($Progress1, 60)

        If _IsChecked($Checkbox4) Then RunWait(@ComSpec & " /c " & $FileOffice, "", @SW_HIDE, "")
            $label4 = GUICtrlCreateLabel("Instalando Microsoft Office 2013" , 90, 240, 224, 22, $SS_CENTER)
            GUICtrlSetFont($label4, 11, 800, 2, "Times New Roman")
             GUICtrlSetColor($label4, 0x008000)

            _SendMessage(GUICtrlGetHandle($Progress1), 80)
            GUICtrlSetData($Progress1, 80)

        If _IsChecked($Checkbox5) Then RunWait(@ComSpec & " /c " & $FileIso, "", @SW_HIDE, "")
            $label5 = GUICtrlCreateLabel("Instalando Ultra ISO" , 90, 240, 224, 22, $SS_CENTER)
            GUICtrlSetFont($label5, 11, 800, 2, "Times New Roman")
             GUICtrlSetColor($label5, 0x008000)

            _SendMessage(GUICtrlGetHandle($Progress1), 100)
            GUICtrlSetData($Progress1, 100)

    GUISetState(@SW_SHOW)
    EndSwitch
WEnd

Func _CheckAll()
    If _IsChecked($Checkbox6) Then
        GUICtrlSetState($Checkbox1, $GUI_CHECKED)
        GUICtrlSetState($Checkbox2, $GUI_CHECKED)
        GUICtrlSetState($Checkbox3, $GUI_CHECKED)
        GUICtrlSetState($Checkbox4, $GUI_CHECKED)
        GUICtrlSetState($Checkbox5, $GUI_CHECKED)
    Else
        GUICtrlSetState($Checkbox1, $GUI_UNCHECKED)
        GUICtrlSetState($Checkbox2, $GUI_UNCHECKED)
        GUICtrlSetState($Checkbox3, $GUI_UNCHECKED)
        GUICtrlSetState($Checkbox4, $GUI_UNCHECKED)
        GUICtrlSetState($Checkbox5, $GUI_UNCHECKED)
    EndIf
EndFunc


Func _IsChecked($idControlID)
        Return BitAND(GUICtrlRead($idControlID), $GUI_CHECKED) = $GUI_CHECKED
        EndFunc

 

  • Solution
Posted (edited)

These IFs are wrong.

If _IsChecked($Checkbox1) Then RunWait(@ComSpec & " /c " & $FileChrome, "", @SW_HIDE, "")

This is a single line if statement, so the code below will run no matter if the condition is true or false. I think this is what you want:

If _IsChecked($Checkbox1) Then 
                RunWait(@ComSpec & " /c " & $FileChrome, "", @SW_HIDE, "")
                $label1 = GUICtrlCreateLabel("Instalando Google Chrome" , 90, 240, 224, 22, $SS_CENTER)
                GUICtrlSetFont($label1, 11, 800, 2, "Times New Roman")
                 GUICtrlSetColor($label1, 0x008000)

                _SendMessage(GUICtrlGetHandle($Progress1), 20)
                GUICtrlSetData($Progress1, 20)
            EndIf

And do this for each IF statement.

Also the whole interface is a mess. Why would you create a label for each app to notify which the app is installing? Just create a label and change the text accordingly.

Also the program won't exit if you press ESC because you can't process the message until all installs are done.

Here is a version that fix some of these issues:

#include <GUIConstants.au3>

Global $sFileChrome = "Programas\Chrome64.exe /silent /install"
Global $sFileAdobe = "Programas\AdobeDC.exe /sAll /sPB"
Global $sFileDropbox = "Programas\Dropbox86.exe /S"
Global $sFileOffice = "Programas\Office2013x64\setup.exe"
Global $sFileIso = "Programas\UltraISO.exe /VERYSILENT"

Global $cCheckbox1, $cCheckbox2, $cCheckbox3, $cCheckbox4, $cCheckbox5, $cCheckbox6

$hMain = GUICreate("Instalacion de Programas", 407, 355)
GUISetBkColor(0xFFFFFF, $hMain)

$cIni = GUICtrlCreateButton("Instalar Programas", 100, 16, 200, 30)
GUICtrlSetFont($cIni, 12, 800, 2, "Times New Roman")
GUICtrlSetCursor($cIni, 0)

$cCheckbox1 = GUICtrlCreateCheckbox("Google Chrome", 29, 74, 129, 20)
GUICtrlSetFont($cCheckbox1, 11, 800, 2, "Times New Roman")

$cCheckbox2 = GUICtrlCreateCheckbox("Adobe Acrobat DC", 29, 98, 145, 20)
GUICtrlSetFont($cCheckbox2, 11, 800, 2, "Times New Roman")

$cCheckbox3 = GUICtrlCreateCheckbox("Dropbox", 29, 122, 81, 20)
GUICtrlSetFont($cCheckbox3, 11, 800, 2, "Times New Roman")

$cCheckbox4 = GUICtrlCreateCheckbox("Microsoft Office 2013", 29, 146, 161, 20)
GUICtrlSetFont($cCheckbox4, 11, 800, 2, "Times New Roman")

$cCheckbox5 = GUICtrlCreateCheckbox("Ultra ISO", 29, 170, 89, 20)
GUICtrlSetFont($cCheckbox5, 11, 800, 2, "Times New Roman")

$cCheckbox6 = GUICtrlCreateCheckbox("Seleccionar Todo", 253, 67, 129, 20)
GUICtrlSetFont($cCheckbox6, 11, 800, 2, "Times New Roman")

$cProgress = GUICtrlCreateProgress(32, 288, 337, 25, $PBS_SMOOTH)
GUICtrlSetColor($cProgress, 0x008000)

$cESC = GUICtrlCreateLabel("Precione ESC para Salir", 129, 328, 160, 22)
GUICtrlSetFont($cESC, 11, 800, 2, "Times New Roman")

$cCurrentApp = GUICtrlCreateLabel("" , 90, 240, 224, 22, $SS_CENTER)
GUICtrlSetFont($cCurrentApp, 11, 800, 2, "Times New Roman")
GUICtrlSetColor($cCurrentApp, 0x008000)

GUISetState(@SW_SHOW, $hMain)

While True
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit

        Case $cCheckbox6
            _CheckAll()

        Case $cIni
            AdlibRegister('CheckGUIMsg', 100)

            If _IsChecked($cCheckbox1) Then
                GUICtrlSetData($cCurrentApp, "Instalando Google Chrome")
                RunWait(@ComSpec & " /c " & $sFileChrome, "", @SW_HIDE, "")
            EndIf
            GUICtrlSetData($cProgress, 20)

            If _IsChecked($cCheckbox2) Then
                GUICtrlSetData($cCurrentApp, "Instalando Adobe Acrobat DC")
                RunWait(@ComSpec & " /c " & $sFileAdobe,"", @SW_HIDE, "")
            EndIf
            GUICtrlSetData($cProgress, 40)
            
            If _IsChecked($cCheckbox3) Then
                GUICtrlSetData($cCurrentApp, "Instalando Dropbox")
                RunWait(@ComSpec & " /c "  & $sFileDropbox, "", @SW_HIDE, "")
            EndIf
            GUICtrlSetData($cProgress, 60)

            If _IsChecked($cCheckbox4) Then
                GUICtrlSetData($cCurrentApp, "Instalando Microsoft Office 2013")
                RunWait(@ComSpec & " /c " & $sFileOffice, "", @SW_HIDE, "")
            EndIf
            GUICtrlSetData($cProgress, 80)

            If _IsChecked($cCheckbox5) Then
                GUICtrlSetData($cCurrentApp, "Instalando Ultra ISO")
                RunWait(@ComSpec & " /c " & $sFileIso, "", @SW_HIDE, "")
            EndIf
            GUICtrlSetData($cProgress, 100)
            GUICtrlSetData($cCurrentApp, "")

            AdlibUnRegister('CheckGUIMsg')
    EndSwitch
WEnd

Func CheckGUIMsg()
    If GUIGetMsg() = $GUI_EVENT_CLOSE Then Exit
EndFunc

Func _CheckAll()
    If _IsChecked($cCheckbox6) Then
        GUICtrlSetState($cCheckbox1, $GUI_CHECKED)
        GUICtrlSetState($cCheckbox2, $GUI_CHECKED)
        GUICtrlSetState($cCheckbox3, $GUI_CHECKED)
        GUICtrlSetState($cCheckbox4, $GUI_CHECKED)
        GUICtrlSetState($cCheckbox5, $GUI_CHECKED)
    Else
        GUICtrlSetState($cCheckbox1, $GUI_UNCHECKED)
        GUICtrlSetState($cCheckbox2, $GUI_UNCHECKED)
        GUICtrlSetState($cCheckbox3, $GUI_UNCHECKED)
        GUICtrlSetState($cCheckbox4, $GUI_UNCHECKED)
        GUICtrlSetState($cCheckbox5, $GUI_UNCHECKED)
    EndIf
EndFunc


Func _IsChecked($idControlID)
    Return BitAND(GUICtrlRead($idControlID), $GUI_CHECKED) = $GUI_CHECKED
EndFunc

 

Edited by Andreik

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...