Jump to content
stick3r

CheckBox strange behaviour

Recommended Posts

Hi, I have this script and I need to reset all checkboxes to UNCHECKED when button is pressed.

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

#Region ### START Koda GUI section ### Form=
Global $Form = GUICreate("Checklist", 190, 407, 1233, 178)
Global $text = ""
Global $CheckBox
GUICtrlCreateTab(1, 1, 190, 365)
GUICtrlCreateTabItem("TAB 1")
Global $InputCaseID1 = GUICtrlCreateInput($text, 80, 25, 80, 21)
Global $lblCaseID = GUICtrlCreateLabel("Case ID", 8, 30, 68, 18)
Global $CheckBox1 = GUICtrlCreateCheckbox("1111111", 8, 48, 110, 17)
Global $CheckBox2 = GUICtrlCreateCheckbox("2222222", 8, 72, 110, 17)
Global $CheckBox3 = GUICtrlCreateCheckbox("333333333", 8, 96, 110, 17)
Global $CheckBox4 = GUICtrlCreateCheckbox("444444444", 8, 120, 110, 17)
Global $CheckBox5 = GUICtrlCreateCheckbox("55555555", 8, 144, 110, 17)
Global $CheckBox6 = GUICtrlCreateCheckbox("666666666", 8, 168, 110, 17)
Global $CheckBox7 = GUICtrlCreateCheckbox("77777777", 8, 192, 150, 17)
Global $CheckBox8 = GUICtrlCreateCheckbox("888888888", 8, 216, 150, 17)
Global $CheckBox9 = GUICtrlCreateCheckbox("99999999", 8, 240, 110, 17)
Global $CheckBox10 = GUICtrlCreateCheckbox("45646", 8, 264, 110, 17)
Global $CheckBox11 = GUICtrlCreateCheckbox("4345634", 8, 288, 97, 17)
Global $CheckBox12 = GUICtrlCreateCheckbox("4563456", 8, 312, 97, 17)
Global $CheckBox13 = GUICtrlCreateCheckbox("456456", 8, 336, 97, 17)

GUICtrlCreateTabItem("TAB 2")
Global $InputCaseID2 = GUICtrlCreateInput("", 80, 25, 80, 21)
Global $lblCaseID = GUICtrlCreateLabel("Case ID", 8, 30, 68, 18)
Global $CheckBox14 = GUICtrlCreateCheckbox("AAAAAAA", 8, 48, 110, 17)
Global $CheckBox15 = GUICtrlCreateCheckbox("PPPPPPPPP", 8, 72, 110, 17)
Global $CheckBox16 = GUICtrlCreateCheckbox("BBBBBBBB", 8, 96, 110, 17)
Global $CheckBox17 = GUICtrlCreateCheckbox("CCCCCCCCCCCCC", 8, 120, 110, 17)
Global $CheckBox18 = GUICtrlCreateCheckbox("DDDDDDDDDDDDD", 8, 144, 110, 17)
Global $CheckBox19 = GUICtrlCreateCheckbox("EEEEEEEEEE", 8, 168, 110, 17)
Global $CheckBox20 = GUICtrlCreateCheckbox("FFFFFFFFFFF", 8, 192, 150, 17)
Global $CheckBox21 = GUICtrlCreateCheckbox("GGGGGGGGGG", 8, 216, 150, 17)
Global $CheckBox22 = GUICtrlCreateCheckbox("HHHHHHHHH", 8, 240, 110, 17)
Global $CheckBox23 = GUICtrlCreateCheckbox("IIIIIIIII", 8, 264, 110, 17)
Global $CheckBox24 = GUICtrlCreateCheckbox("JJJJJJJ", 8, 288, 97, 17)
Global $CheckBox25 = GUICtrlCreateCheckbox("KKKKKKKKKKK", 8, 312, 97, 17)
Global $CheckBox26 = GUICtrlCreateCheckbox("LLLLLLLLL", 8, 336, 97, 17)

GUICtrlCreateTabItem("")
Global $CheckBoxAlwaysOnTop = GUICtrlCreateCheckbox("Always on Top", 8, 380, 97, 17)
Global $btnReset = GUICtrlCreateButton("RESET", 104, 365, 75, 41)
GUISetState(@SW_SHOW)

#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $CheckBoxAlwaysOnTop
            _SetAlwaysOnTop()
        Case $btnReset
        For $i = 7 To 19 Step 1 ;Remove checked CheckBoxes
            GUICtrlSetState($CheckBox&$i, $GUI_UNCHECKED)
        Next
        For $i = 23 To 35 Step 1
            GUICtrlSetState($CheckBox&$i, $GUI_UNCHECKED)
        Next
        GUICtrlSetData($InputCaseID1, "")
        GUICtrlSetData($InputCaseID2, "")
    EndSwitch
WEnd

Func _SetAlwaysOnTop()
    If GUICtrlRead($CheckBoxAlwaysOnTop) = $GUI_CHECKED Then
        WinSetOnTop($Form, "", 1) ;On top
    Else
        WinSetOnTop($Form, "", 0) ;Not on top
    EndIf
EndFunc   ;==>_SetAlwaysOnTop

My question is:

Why this  For loop for GUICtrlSetState($CheckBox&$i, $GUI_UNCHECKED) does not work properly

I have $CheckBox1, $CheckBox2.......till $CheckBox26 and with For $i = 1 To 26 it does not work. It only unchecks few of them, but not all.

Later I have discovered that For $i = 7 To 19 removes  $CheckBox1 to  $CheckBox13 and For $i = 23 To 35 removes  $CheckBox14 to  $CheckBox26

Any idea why?

Share this post


Link to post
Share on other sites

stick3r,

AutoIt uses an array to store the ControlIDs of its controls (the value returned by the GUICtrlCreate* call) and these ControlIDs are actually the index number of the control in that array. If you look at the actual values returned, you will see that they are in numerical order of creation, as you can see if you add these lines to your script:

Global $CheckBox13 = GUICtrlCreateCheckbox("456456", 8, 336, 97, 17)

GUICtrlCreateTabItem("TAB 2")
Global $InputCaseID2 = GUICtrlCreateInput("", 80, 25, 80, 21)
Global $lblCaseID = GUICtrlCreateLabel("Case ID", 8, 30, 68, 18)
Global $CheckBox14 = GUICtrlCreateCheckbox("AAAAAAA", 8, 48, 110, 17)

MsgBox(0, "ControlIDs", "$Checkbox13: " & @TAB & $CheckBox13 & @CRLF & _
                                      "TAB2 goes here" & @CRLF & _
                                      "$InputCaseID2: " & @TAB & $InputCaseID2 & @CRLF & _
                                      "$lblCaseID:" & @TAB & $lblCaseID & @CRLF & _
                                      "$CheckBox14: " & @TAB & $CheckBox14)

Global $CheckBox15 = GUICtrlCreateCheckbox("PPPPPPPPP", 8, 72, 110, 17)

I would suggest using arrays to hold the returned ControlIDs - that way life is very easy:

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <MsgBoxConstants.au3>

; Create an array to hold the returned ControlIDs <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
Global $aCheckbox[27] ; Why 27? Because arrays start at 0

#Region ### START Koda GUI section ### Form=
    Global $Form = GUICreate("Checklist", 190, 407, 1233, 178)
    Global $text = ""
    Global $aCheckbox
    GUICtrlCreateTab(1, 1, 190, 365)
    GUICtrlCreateTabItem("TAB 1")
    Global $InputCaseID1 = GUICtrlCreateInput($text, 80, 25, 80, 21)
    Global $lblCaseID = GUICtrlCreateLabel("Case ID", 8, 30, 68, 18)
    ; Store the ControlIDs as the controls are created <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    $aCheckbox[1] = GUICtrlCreateCheckbox("1111111", 8, 48, 110, 17)
    $aCheckbox[2] = GUICtrlCreateCheckbox("2222222", 8, 72, 110, 17)
    $aCheckbox[3] = GUICtrlCreateCheckbox("333333333", 8, 96, 110, 17)
    $aCheckbox[4] = GUICtrlCreateCheckbox("444444444", 8, 120, 110, 17)
    $aCheckbox[5] = GUICtrlCreateCheckbox("55555555", 8, 144, 110, 17)
    $aCheckbox[6] = GUICtrlCreateCheckbox("666666666", 8, 168, 110, 17)
    $aCheckbox[7] = GUICtrlCreateCheckbox("77777777", 8, 192, 150, 17)
    $aCheckbox[8] = GUICtrlCreateCheckbox("888888888", 8, 216, 150, 17)
    $aCheckbox[9] = GUICtrlCreateCheckbox("99999999", 8, 240, 110, 17)
    $aCheckbox[10] = GUICtrlCreateCheckbox("45646", 8, 264, 110, 17)
    $aCheckbox[11] = GUICtrlCreateCheckbox("4345634", 8, 288, 97, 17)
    $aCheckbox[12] = GUICtrlCreateCheckbox("4563456", 8, 312, 97, 17)
    $aCheckbox[13] = GUICtrlCreateCheckbox("456456", 8, 336, 97, 17)

    GUICtrlCreateTabItem("TAB 2")
    Global $InputCaseID2 = GUICtrlCreateInput("", 80, 25, 80, 21)
    Global $lblCaseID = GUICtrlCreateLabel("Case ID", 8, 30, 68, 18)
    $aCheckbox[14] = GUICtrlCreateCheckbox("AAAAAAA", 8, 48, 110, 17)
    $aCheckbox[15] = GUICtrlCreateCheckbox("PPPPPPPPP", 8, 72, 110, 17)
    $aCheckbox[16] = GUICtrlCreateCheckbox("BBBBBBBB", 8, 96, 110, 17)
    $aCheckbox[17] = GUICtrlCreateCheckbox("CCCCCCCCCCCCC", 8, 120, 110, 17)
    $aCheckbox[18] = GUICtrlCreateCheckbox("DDDDDDDDDDDDD", 8, 144, 110, 17)
    $aCheckbox[19] = GUICtrlCreateCheckbox("EEEEEEEEEE", 8, 168, 110, 17)
    $aCheckbox[20] = GUICtrlCreateCheckbox("FFFFFFFFFFF", 8, 192, 150, 17)
    $aCheckbox[21] = GUICtrlCreateCheckbox("GGGGGGGGGG", 8, 216, 150, 17)
    $aCheckbox[22] = GUICtrlCreateCheckbox("HHHHHHHHH", 8, 240, 110, 17)
    $aCheckbox[23] = GUICtrlCreateCheckbox("IIIIIIIII", 8, 264, 110, 17)
    $aCheckbox[24] = GUICtrlCreateCheckbox("JJJJJJJ", 8, 288, 97, 17)
    $aCheckbox[25] = GUICtrlCreateCheckbox("KKKKKKKKKKK", 8, 312, 97, 17)
    $aCheckbox[26] = GUICtrlCreateCheckbox("LLLLLLLLL", 8, 336, 97, 17)

    GUICtrlCreateTabItem("")
    Global $aCheckboxAlwaysOnTop = GUICtrlCreateCheckbox("Always on Top", 8, 380, 97, 17)
    Global $btnReset = GUICtrlCreateButton("RESET", 104, 365, 75, 41)
    GUISetState(@SW_SHOW)

#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $aCheckboxAlwaysOnTop
            _SetAlwaysOnTop()
        Case $btnReset
            ; Now you can loop through them in a single loop <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
            For $i = 1 To 26 ;Remove checked CheckBoxes
                GUICtrlSetState($aCheckbox[$i], $GUI_UNCHECKED)
            Next
            GUICtrlSetData($InputCaseID1, "")
            GUICtrlSetData($InputCaseID2, "")
    EndSwitch
WEnd

Func _SetAlwaysOnTop()
    If GUICtrlRead($aCheckboxAlwaysOnTop) = $GUI_CHECKED Then
        WinSetOnTop($Form, "", 1) ;On top
    Else
        WinSetOnTop($Form, "", 0) ;Not on top
    EndIf
EndFunc   ;==>_SetAlwaysOnTop

Please ask if you have any questions.

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

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

  • Similar Content

    • By ozymandius257
      I'm trying to check the status of the checkbox for sharing a folder that you see when you right-click on a  folder, go to the sharing tab, then click on Advanced Sharing.

      The check box is labelled Share this folder, and looking at it using AutoIt window info, I get the following information..
      >>>> Control <<<<
      Class:    Button
      Instance:    1
      ClassnameNN:    Button1
      Name:    
      Advanced (Class):    [CLASS:Button; INSTANCE:1]
      ID:    1020
      Text:    &Share this folder
      Position:    15, 16
      Size:    306, 13
      ControlClick Coords:    57, 4
      Style:    0x50010003
      ExStyle:    0x00000004
      Handle:    0x0000000000420A52
      I'm using the following code..
      If ControlCommand("Sharing","","[CLASS:Button; INSTANCE:1]","IsChecked","") = 0 Then
          MsgBox(0, "", "not checked")
      Else
          MsgBox(0, "", "checked")
      EndIf
      But this insists the check box isn't checked when it is.  I have also tried ControlCommand("Sharing","","[ID:1020]","IsChecked","") and ControlCommand("Sharing","","Share this folder","IsChecked","") and ControlCommand("Sharing","","&Share this folder","IsChecked",""), with no joy.
       
      Any ideas?
    • By OneSolution
      Hi guys! I have these checkbox that I'm trying to click on. They have the same inner-text string but a different ID. Sometime there can be as many as 4 checkbox
      with the same string but the ID is always different. I tried a few methods down below but I'm unable to make any real results. Any suggestions or solutions I would
      appreciate it very much.
      <ul><li class="cx-list-item-wrapper" data-day="Aug 2 2018 07:27:37 GMT-0700 (Pacific Daylight Time)"><div class=""><div class="cx-list-item-container"><div class="cx-list-item cx-item-icon-2 pointer-cursor"><div class="cx-item-contents cx-item-time col-md-2"><!-- react-text: 675 -->Morning<!-- /react-text --><!-- react-text: 676 -->&nbsp;<!-- /react-text --></div><div class="cx-item-contents col-md-1"><!-- react-text: 678 -->OTHER<!-- /react-text --><!-- react-text: 679 -- >&nbsp;<!-- /react-text --></div><div class="cx-item-contents col-md-2"><!-- react-text: 681 -->8:30 AM<!-- /react-text --><!-- react-text: 682 -->&nbsp;<!-- /react-text --></div><div class="cx-item-contents col-md-2"><!-- react-text: 684 -->10:30 AM<!-- /react-text --><!-- react-text: 685 -->&nbsp;<!-- /react-text -- ></div><div class="cx-item-contents col-md-1"><!-- react-text: 687 -->SRV<!-- /react-text --><!-- react-text: 688 -->&nbsp;<!-- /react-text --></div></div></div><div class="pull-right cx-listitem-chk"><div><input id="cx_checkbox1" class="cx-fa-chk cx-selfschedule-chk" value="on" type="checkbox"><label for="cx_checkbox1"></label></div></div></div></li><li class="cx-list-item-wrapper" data-day="Aug 2 2018 07:27:37 GMT-0700 (Pacific Daylight Time)"><div class=""><div class="cx-list-item-container"><div class="cx-list-item cx-item-icon-2 pointer-cursor"><div class="cx-item-contents cx-item-time col-md-1"><!-- react-text: 698 -- >Morning<!-- /react-text --><!-- react-text: 699 -->&nbsp;<!-- /react-text --></div><div class="cx-item-contents col-md-1"><!-- react-text: 701 -->OTHER<!-- /react- text --><!-- react-text: 702 -->&nbsp;<!-- /react-text --></div><div class="cx-item-contents col-md-2"><!-- react-text: 704 -->8:30 AM<!-- /react-text --><!-- react-text: 705 -->&nbsp;<!-- /react-text --></div><div class="cx-item-contents col-md-2"><!-- react-text: 707 -->2:30 PM<!-- /react-text --><!-- react-text: 708 -- >&nbsp;<!-- /react-text --></div><div class="cx-item-contents col-md-1"><!-- react-text: 710 -->SRV<!-- /react-text --><!-- react-text: 711 -->&nbsp;<!-- /react-text --></div></div></div><div class="pull-right cx-listitem-chk"><div><input id="cx_checkbox2" class="cx-fa-chk cx-selfschedule-chk" value="on" type="checkbox"><label for="cx_checkbox2"></label></div></div></div></li></ul> I tried the _IETagNameGetCollection() but it only check the box but doesn't fire the event! And I'm unable to submit that without a click action.
      Func _Box1() $oInputs = _IETagNameGetCollection($oIE, "input") For $oInput In $oInputs If $oInput.id == "cx_checkbox1" Then $oInput.checked = true Next Sleep(10) ToolTip('box1') EndFunc ;==>_Box1 I also tried click by text.The boxes do get check by a click but the problem with that is it will select every box that has the same string. I'm allowed only to check 1 box selection at a time per day for the submit button to work.  Any preference to select only the second box and bypass the other?
      Func _Morning() For $a In _IETagNameGetCollection($oIE, "div") If StringInStr(_IEPropertyGet($a, "innerText"), "Morning") Then _IEAction($a, "click") EndIf Next Sleep(10) ToolTip('Morning selected') EndFunc ;==>Morning The last method I tried was _IEGetObjById(). It doesn't click or respond to the checkbox.
      Func _Click1() $oChk = _IEGetObjById($oIE, "cx_checkbox1") _IEAction($oChk, 'click') Sleep(20) ToolTip('box1') EndFunc ;==>_Click1  
    • By rudi
      Hello,
       
      for some script I need to investigate the states checked/unchecked, hidden/shown, enabled/disabled to several checkbox controls.
       
      Any suggestions to this script to retrieve the information in a better way?
      ; Autoit Version 3.3.14.2 ; GuiCtrlCheckState.au3 #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> $CtrlW = 100 $CtrlH = 30 $GuiW = 250 $GuiH = 300 GUICreate("Test Checkbox Status", $GuiW, $GuiH) $Ctrl = GUICtrlCreateCheckbox("Checkbox", 10, 10, $CtrlW, $CtrlH) Opt("Guicoordmode", 2) $BtnDisable = GUICtrlCreateButton("Disable", -1, 10) $BtnEnable = GUICtrlCreateButton("Enable", -1, 1) $BtnHide = GUICtrlCreateButton("Hide", 10, -$CtrlH * 2 - 1) $BtnUnHide = GUICtrlCreateButton("Show (Unhide)", -1, 1) $BtnCheckChecked = GUICtrlCreateButton("IsChecked", -$CtrlW * 2 - 10, 40) $BtnCheckEnabled = GUICtrlCreateButton("IsEnabled", -1, 1) $BtnCheckHidden = GUICtrlCreateButton("IsHidden", -1, 1) GUISetState() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $BtnDisable GUICtrlSetState($Ctrl, $gui_disable) Case $BtnEnable GUICtrlSetState($Ctrl, $GUI_Enable) Case $BtnHide GUICtrlSetState($Ctrl, $GUI_Hide) Case $BtnUnHide GUICtrlSetState($Ctrl, $GUI_show) Case $BtnCheckChecked If CheckState($Ctrl, $GUI_CHECKED) Then ConsoleWrite("Checked" & @CRLF) Else ConsoleWrite("not checked" & @CRLF) EndIf Case $BtnCheckEnabled If CheckState($Ctrl, $GUI_Enable) Then ConsoleWrite("enabled" & @CRLF) Else ConsoleWrite("disabled" & @CRLF) EndIf Case $BtnCheckHidden If CheckState($Ctrl, $GUI_Hide) Then ConsoleWrite("Hidden" & @CRLF) Else ConsoleWrite("not hidden" & @CRLF) EndIf EndSwitch WEnd Func CheckState($_CtrlID, $_State = $GUI_CHECKED) ConsoleWrite("---------------------" & @CRLF) ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $_State to check = ' & $_State & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console Local $_Read = GUICtrlRead($_CtrlID) ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $_Read (GuiCtrlRead) = ' & $_Read & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console Local $_StateFound = GUICtrlGetState($_CtrlID) ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $_StateFound (GuiCtrlGetState) = ' & $_StateFound & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console If $_StateFound = -1 Then MsgBox(48, "Control-ID not defined", "Control-ID invalid") Return False ElseIf BitAND($_StateFound, $_State) = $_State Then Return True ElseIf BitAND($_Read, $_State) = $_State Then Return True Else Return False EndIf EndFunc ;==>CheckState Regards, Rudi.
    • By gillesg
      Hello,
      I am struggling in merging GUITreeViewEx, Shelltristate and enhancing to handle a third state that means : some items under are selected.
      I have difficulties handling expand order and key Space (especially when node is collapsed).
      Here the zip with UDF and and example.
       
      The problem I might need some advice to handle : 
      1- When load Treeview, have a correct settings of the checkbox for a tristate tree
      2 - Handle keyboard used for walking in tree
           Chicken is checked and  Steak is unchecked
          When walking with arrow to Meat, it gets unchecked
      3 - When node is collapsed and checked thru keyboard (space)
         the middle state is possible which should not
      Here is joined an animated gif showing the 3 problems
       
      Thanks for your advices
       
       
       
       
       
       
       
       
       
       
       

      GUITreeview3Ex.zip
    • By Jibberish
      Hello,
      I have used this forum to get help many times. I thought it was time to (hopefully) help others.
      I created a script that reads a text file with a list of videos, displays the videos in a GUI with checkboxes next to the names, and displays the selected videos. This will become a part of a larger script I am creating to test a video player. The tough part for me was creating the GUI and Dynamic list of videos. I had a lot of trouble finding samples to help me, but finally found one  written by Melba23. The link is in the code, so he gets credit for helping! I also have not used arrays much and they are very picky about looping through the arrays without getting the dreaded error " Array variable has incorrect number of subscripts or subscript dimension range exceeded."  However diligence paid off!
      To run this code, take the video names commented below and create a videos.txt file in your script execution directory. You can put however many video names in this list. Thus the dynamic features of the code.
      Cheers!
      Jibberish
      #include <MsgBoxConstants.au3> #include <StringConstants.au3> #include <array.au3> #include <File.au3> #include <GUIConstantsEx.au3> Local $sMediaFile = @ScriptDir & "\videos.txt" ;~ Videos in videos.txt are: ;~ bbb_1080_60s.mp4 ;~ bbb_1080_60s_1.mp4 ;~ bbb_1080_60s_2.mp4 ;~ tos_4K_60s_HEVC.mp4 ;~ tos_4K_60s_HEVC_1.mp4 ;~ tos_4K_60s_HEVC_2.mp4 ;~ ;~ Additional videos can be added to this list. The functions are Dynamic. Dim $aMediaManifest Local $aArrayFile Local $aVideos Local $sVideoName Local $i ; MAIN ; Put the Video File Names into an Array _FileReadToArray($sMediaFile, $aArrayFile) Local $iVideoCount = UBound($aArrayFile) -1 ; Get the number of videos - 1 to prevent errors _ArrayDelete($aArrayFile, 0) ;Counter just gets in the way ; Move backwards through the array deleting the blank lines For $i = $iVideoCount - 1 To 0 Step -1 If $aArrayFile[$i] = "" Then _ArrayDelete($aArrayFile, $i) EndIf Next $aVideos = DisplayVideos($aArrayFile) $iVideoCount = UBound($aArrayFile) -1 _ArrayDisplay($aVideos) ; Display the checked videos ;~ End of MAIN ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ; ; GUI to display Videos in checkboxes ; ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Func DisplayVideos($aArrayFile) Local $iTop = -1 Local $iLeft = -1 Local $iWidth Local $iHeight = $iVideoCount * 30 Local $iL = 10 Local $iT = 10 Local $iRow = 0 Local $aVideo Local $iA = 0, $iB = 0 Local $sFill = "" $iMMCount = UBound($aArrayFile) $iMMNewCount = $iMMCount - 1 Local $aGUICheckbox[$iMMCount] Local $aCheckedVideos[$iMMCount] ; Put the Video File Names into an Array $hGUI = GUICreate("Video Checkbox", $iLeft, $iTop, $iWidth, $iHeight) GUICtrlCreateLabel("Videos", 180, $iT) $iT = $iT + 30 ; This is a great example of using arrays to create GUI check boxes or radio buttons For $i = 0 To $iMMNewCount Step 1 $sMP4Text = $aArrayFile[$i] $aGUICheckbox[$i] = GUICtrlCreateCheckbox($sMP4Text, 30, $iT) $iT += 30 Next $idClose1 = GUICtrlCreateButton("Start", $iL, $iT) GUISetState(@SW_SHOW) ; This section reads the checkboxes and puts the video names in an array in their original position ; in case this is important (as it is to me) ; This was the toughest part to code, and I found no samples online until I saw Melba23's sample here: ; https://www.autoitscript.com/forum/topic/119843-dynamic-gui-problem/#comment-832672 ; I got this working with only a little modification. THANK YOU MELBA23 While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $idClose1 For $i = 0 To $iMMNewCount Step 1 Switch GUICtrlRead($aGUICheckbox[$i]) Case $GUI_CHECKED $aCheckedVideos[$i] = $aArrayFile[$i] Case $GUI_UNCHECKED EndSwitch Next ExitLoop EndSwitch WEnd GUIDelete($hGUI) Return $aCheckedVideos EndFunc ;==>DisplayVideos  
×
×
  • Create New...