Jump to content

Recommended Posts

Posted (edited)

Hi all,

I have an array set up in a treeview

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GuiTreeView.au3>
#include <Array.au3>
#include <StaticConstants.au3>

Global $hGUI, $sFile, $hTVItemSelected, $cTV, $bCheck, $bUncheck, $bRun, $aItems[25][3]

#Region GUI
$hGUI = GUICreate("Windows Setup", 500, 500)
;$sFile = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE" & "\Wow6432Node" & "\AutoIt v3\AutoIt", "InstallDir") & "\icons\Varex.ico"
;GUISetIcon($sFile)
GUISetBkColor(0x333333)
#EndRegion

#Region Treeview
$hTVItemSelected = False
$cTV = GUICtrlCreateTreeView(10, 10, 265, 265, BitOR($TVS_CHECKBOXES, $TVS_LINESATROOT, $TVS_HASLINES, $TVS_HASBUTTONS), $WS_EX_CLIENTEDGE)
$bCheck = GUICtrlCreateButton("Check All", 30, 285, 100, 30)
$bUncheck = GUICtrlCreateButton("Uncheck All", 155, 285, 100, 30)
$bRun = GUICtrlCreateButton("Run", 95, 325, 100, 30)
$aItems[0][2]  = GUICtrlCreateTreeViewItem("Update Windows",                    $cTV)
$aItems[1][2]  = GUICtrlCreateTreeViewItem("Install Programs",                  $cTV)
$aItems[2][2]  = GUICtrlCreateTreeViewItem("Office",                            $aItems[1][2])
$aItems[3][2]  = GUICtrlCreateTreeViewItem("Ninite",                            $aItems[1][2])
$aItems[4][2]  = GUICtrlCreateTreeViewItem("UltraVNC",                          $aItems[1][2])
$aItems[5][2]  = GUICtrlCreateTreeViewItem("BGinfo",                            $aItems[1][2])
$aItems[6][2]  = GUICtrlCreateTreeViewItem("Computer Settings",                 $cTV)
$aItems[7][2]  = GUICtrlCreateTreeViewItem("Add 'anyuser'",                     $aItems[6][2])
$aItems[8][2]  = GUICtrlCreateTreeViewItem("Admin Access",                      $aItems[7][2])
$aItems[9][2]  = GUICtrlCreateTreeViewItem("Auto Login",                        $aItems[7][2])
$aItems[10][2] = GUICtrlCreateTreeViewItem("Enable Remote Desktop",             $aItems[6][2])
$aItems[11][2] = GUICtrlCreateTreeViewItem("Edit Group Policy",                 $aItems[6][2])
$aItems[12][2] = GUICtrlCreateTreeViewItem("Enable .NET 3.5",                   $aItems[6][2])
$aItems[14][2] = GUICtrlCreateTreeViewItem("Disable TCP/IPv6",                  $aItems[6][2])
$aItems[15][2] = GUICtrlCreateTreeViewItem("Change Power Options",              $aItems[6][2])
$aItems[16][2] = GUICtrlCreateTreeViewItem("Set Time",                          $aItems[6][2])
$aItems[17][2] = GUICtrlCreateTreeViewItem("Show Hidden Files",                 $aItems[6][2])
$aItems[18][2] = GUICtrlCreateTreeViewItem("Allow VNC Firewall Ports",          $aItems[6][2])
$aItems[19][2] = GUICtrlCreateTreeViewItem("Change Windows Search Settings",    $aItems[6][2])
$aItems[20][2] = GUICtrlCreateTreeViewItem("Disable OneDrive",                  $aItems[6][2])
$aItems[21][2] = GUICtrlCreateTreeViewItem("Join Domain",                       $cTV)
$aItems[22][2] = GUICtrlCreateTreeViewItem("102",                               $aItems[21][2])
$aItems[23][2] = GUICtrlCreateTreeViewItem("EVL",                               $aItems[21][2])
$aItems[24][2] = GUICtrlCreateTreeViewItem("FPVL",                              $aItems[21][2])
#EndRegion


GUISetState()

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $bCheck
            GUICtrlSetState($aItems, $GUI_CHECKED)
        Case $bUncheck
            GUICtrlSetState($aItems, $GUI_UNCHECKED)
    EndSwitch
WEnd

I'm having issues with 2 things atm

1- my while statement is not checking or unchecking any boxes (i think it may have something to do with how I am calling the array in GUICtrlSetState($aItems, $GUI_CHECKED) but I can't seem to figure out the correct syntax

2- I want to be able to run functions based on which boxes are selected.

Edited by Em4gdn1m
Posted

Try this :

Case $bCheck
      For $i = 0 To UBound($aItems) - 1
        GUICtrlSetState($aItems[$i][2], $GUI_CHECKED)
      Next
    Case $bUncheck
      For $i = 0 To UBound($aItems) - 1
        GUICtrlSetState($aItems[$i][2], $GUI_UNCHECKED)
      Next

As for the verifying which item is check or not, use the same for loop with  BitAND(GUICtrlRead($aItem[$i][2]),$GUI_CHECKED)

Posted
7 minutes ago, Nine said:

Try this :

Case $bCheck
      For $i = 0 To UBound($aItems) - 1
        GUICtrlSetState($aItems[$i][2], $GUI_CHECKED)
      Next
    Case $bUncheck
      For $i = 0 To UBound($aItems) - 1
        GUICtrlSetState($aItems[$i][2], $GUI_UNCHECKED)
      Next

As for the verifying which item is check or not, use the same for loop with  BitAND(GUICtrlRead($aItem[$i][2]),$GUI_CHECKED)

Your code works perfectly for checking and unchecking items, but I am confused about the BitAND part running other functions

for instance if "Change Power Options" is selected, I want to run my _PowerOptions function etc.

Posted (edited)

Read help file.  GuiCtrlRead may return multiple state values for a treeview item, you cannot just equal to "checked", as it may has other states.  BitAnd is there to tell you if the state bit of "checked" is on or off. So something like this should work :

For $i = 0 To UBound($aItems) - 1
  if BitAnd(GUICtrlRead($aItems[$i][2]), $GUI_CHECKED) then
    ; Install the stuff here
  endif
Next

 

Edited by Nine
Posted
5 minutes ago, Nine said:

Read help file.  GuiCtrlRead may return multiple state values for a treeview item, you cannot just equal to "checked", as it may has other states.  BitAnd is there to tell you if the state bit of "checked" is on or off. So something like this should work :

For $i = 0 To UBound($aItems) - 1
  if BitAnd(GUICtrlRead($aItems[$i][2]), $GUI_CHECKED) then
    ; Install the stuff here
  endif
Next

 

I think I'm confused as to how this is determining which checkboxes to run

if i did

For $i = 0 To UBound($aItems) - 1
  If BitAnd(GUICtrlRead($aItems[$i][2]), $GUI_CHECKED) then
    _PowerOptions
  EndIf
Next

Func _PowerOptions ()
$MonitorTimeoutAC = "POWERCFG -change -monitor-timeout-ac 0"
$MonitorTimeoutDC = "POWERCFG -change -monitor-timeout-dc 0"
$DiskTimeoutAC =  "POWERCFG -change -disk-timeout-ac 0"
$DiskTimeoutDC =  "POWERCFG -change -disk-timeout-dc 0"
$StandbyTimeoutAC = "POWERCFG -change -standby-timeout-ac 0"
$StandbyTimeoutDC = "POWERCFG -change -standby-timeout-dc 0"
$HibernateTimeoutAC = "POWERCFG -change -hibernate-timeout-ac 0"
$HibernateTimeoutDC = "POWERCFG -change -hibernate-timeout-dc 0"

Run(@ComSpec & " /c " & $MonitorTimeoutAC, "", @SW_HIDE)
Run(@ComSpec & " /c " & $MonitorTimeoutDC, "", @SW_HIDE)
Run(@ComSpec & " /c " & $DiskTimeoutAC, "", @SW_HIDE)
Run(@ComSpec & " /c " & $DiskTimeoutDC, "", @SW_HIDE)
Run(@ComSpec & " /c " & $StandbyTimeoutAC, "", @SW_HIDE)
Run(@ComSpec & " /c " & $StandbyTimeoutDC, "", @SW_HIDE)
Run(@ComSpec & " /c " & $HibernateTimeoutAC, "", @SW_HIDE)
Run(@ComSpec & " /c " & $HibernateTimeoutDC, "", @SW_HIDE)
EndFunc

it looks like it will run the _PowerOptions function if any array items are checked...

Posted

That won't work obviously, because the user may have selected multiple instances of software to install.  What I would to do personally, I would increase the second dimension of the array to determine what function to execute if selected.

For $i = 0 To UBound($aItems) - 1
  if BitAnd(GUICtrlRead($aItems[$i][2]), $GUI_CHECKED) then
    call ($aItems[$i][3]) ; where [3] contains the "function" to execute 
  endif
Next

 

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
×
×
  • Create New...