Jump to content

Recommended Posts

I'm a novice and I don't master loops, so I took the code that I adapted without really fully understanding it.
Here when I check on the box at the top right, I would like the boxes on the left to be automatically checked.

 

#requireadmin
#include <GuiButton.au3>
#include <GUIConstants.au3>
#include <WindowsConstants.au3>
Opt ("TrayIconDebug", 1)
Opt ("TrayAutoPause", 0)
Opt ("TrayOnEventMode", 1)
Opt ("ExpandEnvStrings", 1)
Opt ("WinDetectHiddenText", 1)
$Form1 = GUICreate ("++ Y 3 ++ ", 210, 185, 300, 37)


$Group1 = GUICtrlCreateGroup("Editeur simple", 16, 10, 177, 136)
GUICtrlSetBkColor(-1, 0xFFFF00)
GUICtrlSetFont(-1, 8, 800, 0, "Arial")
$Radio1A = GUICtrlCreateCheckbox("Notepad 2", 24, 29, 97, 17, 0x0006)
GUICtrlSetOnEvent( -1,"checkbox")
$Radio1B = GUICtrlCreateCheckbox("Notepad ++", 24, 48, 97, 17, 0x0006)
GUICtrlSetOnEvent( -1,"checkbox")
$Radio1C = GUICtrlCreateCheckbox("Libre office", 24, 67, 97, 17, 0x0006)
GUICtrlSetOnEvent( -1,"checkbox")
$Radio1D = GUICtrlCreateCheckbox("CherryTree", 24, 86, 97, 17, 0x0006)
GUICtrlSetOnEvent( -1,"checkbox")
$Radio1E = GUICtrlCreateCheckbox("Notion", 24, 105, 97, 17, 0x0006)
GUICtrlSetOnEvent( -1,"checkbox")
$Radio1F = GUICtrlCreateCheckbox("Scribus", 24, 124, 97, 17, 0x0006)
GUICtrlSetOnEvent( -1,"checkbox")

$Radio1Y = GUICtrlCreateCheckbox("", 172, 20, 97, 17, 0x0006)
GUICtrlSetOnEvent( -1,"allcheck1")

;=========================================================================================
$Button1 = GUICtrlCreateButton("INSTALL", 100, 150, 91, 25)
GUICtrlSetColor(-1, 0xFFFFFF)
GUICtrlSetBkColor (-1, 0xFF0000)
GUISetState()

;=========================================================================================

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;   La fonction "checkbox"      ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

Func allcheck1()
    If _Ischecked($Radio1Y) Then
         GUICtrlSetState($Radio1Y,$GUI_UNCHECKED)
         GUICtrlSetState($Radio1Y,$GUI_DISABLE)
        Local $i
        GUICtrlSetState($Radio1A,$GUI_CHECKED)
        GUICtrlSetState($Radio1B,$GUI_CHECKED)
        GUICtrlSetState($Radio1C,$GUI_CHECKED)
        GUICtrlSetState($Radio1D,$GUI_CHECKED)
        GUICtrlSetState($Radio1E,$GUI_CHECKED)
        GUICtrlSetState($Radio1F,$GUI_CHECKED)
        
       For $i = 1 to Ubound($Radio1Y) - 1
            $Radio1Y[$i] = "1"
        Next
             
    Else
   
        GUICtrlSetState($checkcommun,$GUI_ENABLE)
        GUICtrlSetState($Radio1A,$GUI_UNCHECKED)
        GUICtrlSetState($Radio1B,$GUI_UNCHECKED)
        GUICtrlSetState($Radio1C,$GUI_UNCHECKED)
        GUICtrlSetState($Radio1D,$GUI_UNCHECKED)
        GUICtrlSetState($Radio1E,$GUI_UNCHECKED)
        GUICtrlSetState($Radio1F,$GUI_UNCHECKED)
        
       
        For $i = 1 to Ubound($Radio1Y) - 1
            $Radio1Y[$i] = "0"
        Next
       
    EndIf  
EndFunc

;;;;;;;;;;;;;;;;
; Installation ;
;;;;;;;;;;;;;;;;

While 1
    $Msg = GuiGetMsg()
    Switch $Msg
        Case $GUI_EVENT_CLOSE
        Exit
        Case $button1
            If BitAND (GUICtrlRead($Radio1A), $GUI_CHECKED) = $GUI_CHECKED then
                RunWait(@ComSpec & ' /k ' & 'choco install -y notepad2')
   EndIf
            If BitAND (GUICtrlRead($Radio1B), $GUI_CHECKED) = $GUI_CHECKED Then
                RunWait(@ComSpec & ' /k ' & 'choco install -y notepadplusplus')
   EndIf
            If BitAND (GUICtrlRead($Radio1C), $GUI_CHECKED) = $GUI_CHECKED Then
                RunWait(@ComSpec & ' /k ' & 'choco install -y libreoffice-fresh')
   EndIf 
             If BitAND (GUICtrlRead($Radio1D), $GUI_CHECKED) = $GUI_CHECKED Then
                RunWait(@ComSpec & ' /k ' & 'choco install -y cherrytree')
   EndIf 
             If BitAND (GUICtrlRead($Radio1E), $GUI_CHECKED) = $GUI_CHECKED Then
                RunWait(@ComSpec & ' /k ' & 'choco install -y notion')
   EndIf 
              If BitAND (GUICtrlRead($Radio1F), $GUI_CHECKED) = $GUI_CHECKED Then
                RunWait(@ComSpec & ' /k ' & 'choco install -y scribus')
   EndIf    
  
   Exit

    EndSwitch
WEnd

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;       La fonction "Ischecked"     ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

Func _Ischecked($control)
    Return BitAND(GUICtrlRead($control), $GUI_CHECKED) = $GUI_CHECKED
EndFunc ;==>_IsChecked
Func _Ischecked2($control)
    Return BitAND(GUICtrlRead($control), $GUI_INDETERMINATE) = $GUI_INDETERMINATE
EndFunc ;==>_IsChecked
;==============================
; Installation auto du groupe ;
;==============================

;              If BitAND (GUICtrlRead($Radio1Z), $GUI_CHECKED) = $GUI_CHECKED Then
;                RunWait(@ComSpec & ' /k ' & 'choco install -y notepad2 notepadplusplus libreoffice-fresh cherrytree notion scribus')

 

++ Y 3 ++ _2.jpg

Link to post
Share on other sites
3 hours ago, SEUZARET said:

Here when I check on the box at the top right, I would like the boxes on the left to be automatically checked.

Try :

#RequireAdmin
#include <GuiButton.au3>
#include <GUIConstants.au3>
#include <WindowsConstants.au3>
Opt("TrayIconDebug", 1)
Opt("TrayAutoPause", 0)
Opt("TrayOnEventMode", 1)
Opt("ExpandEnvStrings", 1)
Opt("WinDetectHiddenText", 1)

Opt("MustDeclareVars", 1)

Global $hGUI = GUICreate("++ Y 3 ++ ", 210, 185, 300, 37)

Global $idGroup1 = GUICtrlCreateGroup("Editeur simple", 16, 10, 177, 136)
GUICtrlSetBkColor($idGroup1, 0xFFFF00)
GUICtrlSetFont($idGroup1, 8, 800, 0, "Arial")

Global $idCheck1A = GUICtrlCreateCheckbox("Notepad 2", 24, 29, 97, 17)
Global $idCheck1B = GUICtrlCreateCheckbox("Notepad ++", 24, 48, 97, 17)
Global $idCheck1C = GUICtrlCreateCheckbox("Libre office", 24, 67, 97, 17)
Global $idCheck1D = GUICtrlCreateCheckbox("CherryTree", 24, 86, 97, 17)
Global $idCheck1E = GUICtrlCreateCheckbox("Notion", 24, 105, 97, 17)
Global $idCheck1F = GUICtrlCreateCheckbox("Scribus", 24, 124, 97, 17)
Global $idCheck1Y = GUICtrlCreateCheckbox("", 172, 20, 17, 17)

Global $idButton1 = GUICtrlCreateButton("INSTALL", 100, 150, 91, 25)
GUICtrlSetColor($idButton1, 0xFFFFFF)
GUICtrlSetBkColor($idButton1, 0xFF0000)
GUISetState()

;;;;;;;;;;;;;;;;
; Installation ;
;;;;;;;;;;;;;;;;
Global $idMsg = 0

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

        Case $idCheck1Y
            _CheckAll()

        Case $idButton1
            If _IsChecked($idCheck1A) Then RunWait(@ComSpec & ' /k ' & 'choco install -y notepad2')
            If _IsChecked($idCheck1B) Then RunWait(@ComSpec & ' /k ' & 'choco install -y notepadplusplus')
            If _IsChecked($idCheck1C) Then RunWait(@ComSpec & ' /k ' & 'choco install -y libreoffice-fresh')
            If _IsChecked($idCheck1D) Then RunWait(@ComSpec & ' /k ' & 'choco install -y cherrytree')
            If _IsChecked($idCheck1E) Then RunWait(@ComSpec & ' /k ' & 'choco install -y notion')
            If _IsChecked($idCheck1F) Then RunWait(@ComSpec & ' /k ' & 'choco install -y scribus')

            GUIDelete($hGUI)
            Exit

    EndSwitch
WEnd

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;   La fonction "_CheckAll"     ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Func _CheckAll()
    If _IsChecked($idCheck1Y) Then
        GUICtrlSetState($idCheck1A, $GUI_CHECKED)
        GUICtrlSetState($idCheck1B, $GUI_CHECKED)
        GUICtrlSetState($idCheck1C, $GUI_CHECKED)
        GUICtrlSetState($idCheck1D, $GUI_CHECKED)
        GUICtrlSetState($idCheck1E, $GUI_CHECKED)
        GUICtrlSetState($idCheck1F, $GUI_CHECKED)
    Else
        GUICtrlSetState($idCheck1A, $GUI_UNCHECKED)
        GUICtrlSetState($idCheck1B, $GUI_UNCHECKED)
        GUICtrlSetState($idCheck1C, $GUI_UNCHECKED)
        GUICtrlSetState($idCheck1D, $GUI_UNCHECKED)
        GUICtrlSetState($idCheck1E, $GUI_UNCHECKED)
        GUICtrlSetState($idCheck1F, $GUI_UNCHECKED)
    EndIf
EndFunc   ;==>_CheckAll

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;       La fonction "_IsChecked"    ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Func _IsChecked($idControlID)
    Return BitAND(GUICtrlRead($idControlID), $GUI_CHECKED) = $GUI_CHECKED
EndFunc   ;==>_IsChecked

;==============================
; Installation auto du groupe ;
;==============================
;              If BitAND (GUICtrlRead($idCheck1Z), $GUI_CHECKED) = $GUI_CHECKED Then
;                RunWait(@ComSpec & ' /k ' & 'choco install -y notepad2 notepadplusplus libreoffice-fresh cherrytree notion scribus')

 

Edited by Musashi
edit script

Musashi-C64.png

"In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move."

Link to post
Share on other sites

Little optimization:

 

orig

Case $idButton1
            If BitAND(GUICtrlRead($idCheck1A), $GUI_CHECKED) = $GUI_CHECKED Then
                RunWait(@ComSpec & ' /k ' & 'choco install -y notepad2')
            EndIf
            If BitAND(GUICtrlRead($idCheck1B), $GUI_CHECKED) = $GUI_CHECKED Then
                RunWait(@ComSpec & ' /k ' & 'choco install -y notepadplusplus')
            EndIf
            If BitAND(GUICtrlRead($idCheck1C), $GUI_CHECKED) = $GUI_CHECKED Then
                RunWait(@ComSpec & ' /k ' & 'choco install -y libreoffice-fresh')
            EndIf
            If BitAND(GUICtrlRead($idCheck1D), $GUI_CHECKED) = $GUI_CHECKED Then
                RunWait(@ComSpec & ' /k ' & 'choco install -y cherrytree')
            EndIf
            If BitAND(GUICtrlRead($idCheck1E), $GUI_CHECKED) = $GUI_CHECKED Then
                RunWait(@ComSpec & ' /k ' & 'choco install -y notion')
            EndIf
            If BitAND(GUICtrlRead($idCheck1F), $GUI_CHECKED) = $GUI_CHECKED Then
                RunWait(@ComSpec & ' /k ' & 'choco install -y scribus')
            EndIf

            GUIDelete($hGUI)
            Exit

 

optimized:

Case $idButton1
            If _IsChecked($idCheck1A) Then RunWait(@ComSpec & ' /k ' & 'choco install -y notepad2')
            If _IsChecked($idCheck1B) Then RunWait(@ComSpec & ' /k ' & 'choco install -y notepadplusplus')
            If _IsChecked($idCheck1C) Then RunWait(@ComSpec & ' /k ' & 'choco install -y libreoffice-fresh')
            If _IsChecked($idCheck1D) Then RunWait(@ComSpec & ' /k ' & 'choco install -y cherrytree')
            If _IsChecked($idCheck1E) Then RunWait(@ComSpec & ' /k ' & 'choco install -y notion')
            If _IsChecked($idCheck1F) Then RunWait(@ComSpec & ' /k ' & 'choco install -y scribus')

            GUIDelete($hGUI)
            Exit

 

Link to post
Share on other sites
18 minutes ago, Zedna said:

Little optimization:

You are right, of course. I just wanted to stay as close as possible to the original code, but once the function is there, one should use it ;). I have edited my script accordingly.

Musashi-C64.png

"In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move."

Link to post
Share on other sites

FYI. 

BitAND(GUICtrlRead($idCheck1A), $GUI_CHECKED) = $GUI_CHECKED

is obsolete.  As described in help file of GUICtrlRead :

Quote
Checkbox The checked state ($GUI_CHECKED or $GUI_UNCHECKED)

so a plain :

If GUICtrlRead($idCheck1A) = $GUI_CHECKED Then

is all that you need ;)

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

    No registered users viewing this page.

×
×
  • Create New...