Snippets ( Checkboxes ): Difference between revisions

From AutoIt Wiki
Jump to navigation Jump to search
m (+Snippets Category (+ normalize top))
No edit summary
 
(2 intermediate revisions by 2 users not shown)
Line 4: Line 4:
{{Snippet Credit Header}}
{{Snippet Credit Header}}


===== <blockquote style="background-color:white; padding:1em; border:2px solid #8FBC8F">''' Are all items checked? ~ Author - [http://www.autoitscript.com/forum/user/35302-guinness/ guinness] '''</blockquote> =====
== Are All Items Checked? ==


<syntaxhighlight lang="autoit">
{{Snippet Header
| AuthorURL = 35302-guinness
| AuthorName = guinness
}}
 
<syntaxhighlight lang = "autoit">
#include <GUIConstantsEx.au3>
#include <GUIConstantsEx.au3>
#include <GUIListView.au3>
#include <GUIListView.au3>
Line 14: Line 19:


Func Example()
Func Example()
     Local $hGUI = GUICreate("", 400, 300, -1, -1, BitOR($GUI_SS_DEFAULT_GUI, $WS_MAXIMIZEBOX, $WS_SIZEBOX))
     Local Const $hGUI = GUICreate("", 400, 300, -1, -1, BitOR($GUI_SS_DEFAULT_GUI, $WS_MAXIMIZEBOX, $WS_SIZEBOX))
     Local $iListView = GUICtrlCreateListView("", 0, 0, 400, 270)
     Local $iListView = GUICtrlCreateListView("", 0, 0, 400, 270)
     Local $hListView = GUICtrlGetHandle($iListView)
     Local Const $hListView = GUICtrlGetHandle($iListView)
     _GUICtrlListView_SetExtendedListViewStyle($hListView, BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_CHECKBOXES))
     _GUICtrlListView_SetExtendedListViewStyle($hListView, BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_CHECKBOXES))
     GUICtrlSetResizing(-1, $GUI_DOCKBORDERS)
     GUICtrlSetResizing(-1, $GUI_DOCKBORDERS)
Line 23: Line 28:
     GUICtrlSetResizing(-1, $GUI_DOCKRIGHT + $GUI_DOCKSIZE + $GUI_DOCKBOTTOM)
     GUICtrlSetResizing(-1, $GUI_DOCKRIGHT + $GUI_DOCKSIZE + $GUI_DOCKBOTTOM)


     GUISetState(@SW_SHOW, $hGUI)
     GUISetState(@SW_SHOWNORMAL, $hGUI)


     __ListViewFill($hListView, Random(1, 5, 1), Random(2, 15, 1), 1) ; Randomly fill data in a ListView.
     __ListViewFill($hListView, Random(1, 5, 1), Random(2, 15, 1), 1) ; Randomly fill data in a ListView.
Line 34: Line 39:
             Case $iAllSelected
             Case $iAllSelected
                 MsgBox(4096, "", "If all items are checked this will Return True: " & _GUICtrlListView_AllChecked($hListView))
                 MsgBox(4096, "", "If all items are checked this will Return True: " & _GUICtrlListView_AllChecked($hListView))
         EndSwitch
         EndSwitch
     WEnd
     WEnd
     Return GUIDelete($hGUI)
     Return GUIDelete($hGUI)
EndFunc  ;==>Example
EndFunc  ;==>Example


Func _GUICtrlListView_AllChecked($hListView)
Func _GUICtrlListView_AllChecked(Const $hListView)
     Local $iChecked = 0, $iCount = _GUICtrlListView_GetItemCount($hListView)
     Local $iChecked = 0
 
Local Const $iCount = _GUICtrlListView_GetItemCount($hListView)
 
     For $i = 0 To $iCount - 1
     For $i = 0 To $iCount - 1
         If _GUICtrlListView_GetItemChecked($hListView, $i) Then
         If _GUICtrlListView_GetItemChecked($hListView, $i) Then
Line 47: Line 55:
         EndIf
         EndIf
     Next
     Next
     Return $iChecked = $iCount ; Returns True - all items are checked or False - some are checked.
     Return $iChecked = $iCount ; Returns True - all items are checked or False - some are checked.
EndFunc  ;==>_GUICtrlListView_AllChecked
EndFunc  ;==>_GUICtrlListView_AllChecked


Func __ListViewFill($hListView, $iColumns, $iRows, $iCheckboxes = 0) ; Randomly fill data in a ListView.
Func __ListViewFill(Const $hListView, Const $iColumns, Const $iRows, Const $iCheckboxes = 0) ; Randomly fill data in a ListView.
     For $A = 0 To $iColumns - 1
     For $A = 0 To $iColumns - 1
         _GUICtrlListView_InsertColumn($hListView, $A, "Column " & $A + 1, 50)
         _GUICtrlListView_InsertColumn($hListView, $A, "Column " & $A + 1, 50)
         _GUICtrlListView_SetColumnWidth($hListView, $A - 1, -2)
         _GUICtrlListView_SetColumnWidth($hListView, $A - 1, -2)
     Next
     Next
     For $A = 0 To $iRows - 1
     For $A = 0 To $iRows - 1
         _GUICtrlListView_AddItem($hListView, Chr(Random(65, 90, 1)) & " - Row " & $A + 1 & ": Col 1", $A)
         _GUICtrlListView_AddItem($hListView, Chr(Random(65, 90, 1)) & " - Row " & $A + 1 & ": Col 1", $A)
        If Random(0, 1, 1) And $iCheckboxes Then
 
If Random(0, 1, 1) And $iCheckboxes Then
             _GUICtrlListView_SetItemChecked($hListView, $A)
             _GUICtrlListView_SetItemChecked($hListView, $A)
         EndIf
         EndIf
         For $B = 1 To $iColumns
         For $B = 1 To $iColumns
             _GUICtrlListView_AddSubItem($hListView, $A, "Row " & $A + 1 & ": Col " & $B + 1, $B)
             _GUICtrlListView_AddSubItem($hListView, $A, "Row " & $A + 1 & ": Col " & $B + 1, $B)
Line 65: Line 77:
     Next
     Next
EndFunc  ;==>__ListViewFill
EndFunc  ;==>__ListViewFill
</syntaxhighlight><br>
</syntaxhighlight>
[[#top|Return To Contents]]
 
[[#top | Return To Contents]]
 
== _IsChecked ==


===== <blockquote style="background-color:white; padding:1em; border:2px solid #8FBC8F">''' _IsChecked() ~ Author - [http://www.autoitscript.com/forum/user/6483-zedna/ Zedna] ~ Modified - [http://www.autoitscript.com/forum/user/35302-guinness/ guinness] '''</blockquote> =====
{{Snippet Header
| AuthorURL = 6483-zedna
| AuthorName = Zedna
| ModifierURL = 35302-guinness
| ModifierName = guinness
}}


<syntaxhighlight lang="autoit">
<syntaxhighlight lang = "autoit">
#include <GUIConstantsEx.au3>
#include <GUIConstantsEx.au3>


Line 76: Line 96:


Func Example()
Func Example()
     Local $aState[2] = [$GUI_CHECKED, $GUI_UNCHECKED]
     Local Const $aState[2] = [$GUI_CHECKED, $GUI_UNCHECKED]
     GUICreate('')
     GUICreate('')
     Local $iCheckbox = GUICtrlCreateCheckbox('Checkbox Example', 10, 10, 120, 20)
     Local Const $iCheckbox = GUICtrlCreateCheckbox("Checkbox Example", 10, 10, 120, 20)
     GUICtrlSetState($iCheckbox, $aState[Random(0, 1, 1)]) ; Randomise whether or not the checkbox is checked.
     GUICtrlSetState($iCheckbox, $aState[Random(0, 1, 1)]) ; Randomise whether or not the checkbox is checked.
     GUISetState(@SW_SHOW)
     GUISetState(@SW_SHOWNORMAL)


     ; Check the state of the checkbox.
     ; Check the state of the checkbox.
     MsgBox(4096, '', 'Is the checkbox checked: ' & _IsChecked($iCheckbox))
     MsgBox(4096, '', "Is the checkbox checked: " & _IsChecked($iCheckbox))


     While 1
     While 1
Line 93: Line 113:
EndFunc  ;==>Example
EndFunc  ;==>Example


Func _IsChecked($iControlID)
Func _IsChecked(Const $iControlID)
     Return BitAND(GUICtrlRead($iControlID), $GUI_CHECKED) = $GUI_CHECKED
     Return BitAND(GUICtrlRead($iControlID), $GUI_CHECKED) = $GUI_CHECKED
EndFunc  ;==>_IsChecked
EndFunc  ;==>_IsChecked
</syntaxhighlight>
</syntaxhighlight>
<br>
[[#top|Return To Contents]]


===== <blockquote style="background-color:white; padding:1em; border:2px solid #8FBC8F">''' Listview with Checkboxes ~ Author - [http://www.autoitscript.com/forum/user/6483-zedna/ Zedna] '''</blockquote> =====
[[#top | Return To Contents]]
 
== Listview With Checkboxes ==
 
{{Snippet Header
| AuthorURL = 6483-zedna
| AuthorName = Zedna
}}


<syntaxhighlight lang="autoit">
<syntaxhighlight lang = "autoit">
#include <GUIConstantsEx.au3>
#include <GUIConstantsEx.au3>
#include <GUIListView.au3>
#include <GUIListView.au3>
Line 110: Line 135:


Func Example()
Func Example()
     Local $hGUI = GUICreate("", 400, 300, -1, -1, BitOR($GUI_SS_DEFAULT_GUI, $WS_MAXIMIZEBOX, $WS_SIZEBOX))
     Local Const $hGUI = GUICreate("", 400, 300, -1, -1, BitOR($GUI_SS_DEFAULT_GUI, $WS_MAXIMIZEBOX, $WS_SIZEBOX))
     Local $iListView = GUICtrlCreateListView("", 0, 0, 400, 270)
     Local Const $iListView = GUICtrlCreateListView("", 0, 0, 400, 270)
     Local $hListView = GUICtrlGetHandle($iListView)
     Local Const $hListView = GUICtrlGetHandle($iListView)
     _GUICtrlListView_SetExtendedListViewStyle($hListView, BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_CHECKBOXES))
     _GUICtrlListView_SetExtendedListViewStyle($hListView, BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_CHECKBOXES))
     GUICtrlSetResizing(-1, $GUI_DOCKBORDERS)
     GUICtrlSetResizing(-1, $GUI_DOCKBORDERS)
Line 119: Line 144:
     GUICtrlSetResizing(-1, $GUI_DOCKRIGHT + $GUI_DOCKSIZE + $GUI_DOCKBOTTOM)
     GUICtrlSetResizing(-1, $GUI_DOCKRIGHT + $GUI_DOCKSIZE + $GUI_DOCKBOTTOM)


     GUISetState(@SW_SHOW, $hGUI)
     GUISetState(@SW_SHOWNORMAL, $hGUI)


     __ListViewFill($hListView, Random(1, 5, 1), Random(2, 15, 1), 1) ; Randomly fill data in a ListView.
     __ListViewFill($hListView, Random(1, 5, 1), Random(2, 15, 1), 1) ; Randomly fill data in a ListView.
Line 137: Line 162:
                 _GUICtrlListView_SetCheckedStates($hListView, 1)
                 _GUICtrlListView_SetCheckedStates($hListView, 1)
                 MsgBox(4096, "", "All items were checked.")
                 MsgBox(4096, "", "All items were checked.")
         EndSwitch
         EndSwitch
     WEnd
     WEnd
     Return GUIDelete($hGUI)
     Return GUIDelete($hGUI)
EndFunc  ;==>Example
EndFunc  ;==>Example


;~ $iType: 0 - UnCheck all, 1 - Check all & 2 - Invert selection.
;~ $iType: 0 - UnCheck all, 1 - Check all & 2 - Invert selection.
Func _GUICtrlListView_SetCheckedStates($hListView, $iType) ; By Zedna, Modified by guinness.
Func _GUICtrlListView_SetCheckedStates(Const $hListView, Const $iType) ; By Zedna, Modified by guinness.
     Local $fState = False, $iCount = _GUICtrlListView_GetItemCount($hListView)
     Local $fState = False
    If $iType < 0 Or $iType > 2 Then
 
Local Const $iCount = _GUICtrlListView_GetItemCount($hListView)
 
If $iType < 0 Or $iType > 2 Then
         Return SetError(1, 0, 0)
         Return SetError(1, 0, 0)
     EndIf
     EndIf
     If $iType Then
     If $iType Then
         $fState = True
         $fState = True
     EndIf
     EndIf
     For $i = 0 To $iCount - 1
     For $i = 0 To $iCount - 1
         If $iType = 2 Then
         If $iType = 2 Then
             $fState = Not _GUICtrlListView_GetItemChecked($hListView, $i) ; Invert checked state with $iType 2.
             $fState = Not _GUICtrlListView_GetItemChecked($hListView, $i) ; Invert checked state with $iType 2.
         EndIf
         EndIf
         _GUICtrlListView_SetItemChecked($hListView, $i, $fState)
         _GUICtrlListView_SetItemChecked($hListView, $i, $fState)
     Next
     Next
EndFunc  ;==>_GUICtrlListView_SetCheckedStates
EndFunc  ;==>_GUICtrlListView_SetCheckedStates


Func __ListViewFill($hListView, $iColumns, $iRows, $iCheckboxes = 0) ; Randomly fill data in a ListView.
Func __ListViewFill(Const $hListView, Const $iColumns, Const $iRows, Const $iCheckboxes = 0) ; Randomly fill data in a ListView.
     For $A = 0 To $iColumns - 1
     For $A = 0 To $iColumns - 1
         _GUICtrlListView_InsertColumn($hListView, $A, "Column " & $A + 1, 50)
         _GUICtrlListView_InsertColumn($hListView, $A, "Column " & $A + 1, 50)
         _GUICtrlListView_SetColumnWidth($hListView, $A - 1, -2)
         _GUICtrlListView_SetColumnWidth($hListView, $A - 1, -2)
     Next
     Next
     For $A = 0 To $iRows - 1
     For $A = 0 To $iRows - 1
         _GUICtrlListView_AddItem($hListView, Chr(Random(65, 90, 1)) & " - Row " & $A + 1 & ": Col 1", $A)
         _GUICtrlListView_AddItem($hListView, Chr(Random(65, 90, 1)) & " - Row " & $A + 1 & ": Col 1", $A)
        If Random(0, 1, 1) And $iCheckboxes Then
 
If Random(0, 1, 1) And $iCheckboxes Then
             _GUICtrlListView_SetItemChecked($hListView, $A)
             _GUICtrlListView_SetItemChecked($hListView, $A)
         EndIf
         EndIf
         For $B = 1 To $iColumns
         For $B = 1 To $iColumns
             _GUICtrlListView_AddSubItem($hListView, $A, "Row " & $A + 1 & ": Col " & $B + 1, $B)
             _GUICtrlListView_AddSubItem($hListView, $A, "Row " & $A + 1 & ": Col " & $B + 1, $B)
Line 176: Line 210:
EndFunc  ;==>__ListViewFill
EndFunc  ;==>__ListViewFill
</syntaxhighlight>
</syntaxhighlight>
<br>
[[#top|Return To Contents]]


===== <blockquote style="background-color:white; padding:1em; border:2px solid #8FBC8F">''' Transparent Radio Button ~ Authors - [http://www.autoitscript.com/forum/user/4920-valuater/ Valuater] '''</blockquote> =====
[[#top | Return To Contents]]
 
== Transparent Radio Button ==
 
{{Snippet Header
| AuthorURL = 4920-valuater
| AuthorName = Valuater
}}


<syntaxhighlight lang="autoit">
<syntaxhighlight lang = "autoit">
#include <GUIConstantsEx.au3>
#include <GUIConstantsEx.au3>
#include <ListBoxConstants.au3>
#include <ListBoxConstants.au3>
#include <GUIConstants.au3>
#include <GUIConstants.au3>


MsgBox(0x0,"", @AutoItVersion)
MsgBox(0x0, "", @AutoItVersion)


GUICreate("Transparency", 265,295, @DesktopWidth/2-160, @DesktopHeight/2-90, -1, 0x00000218)
GUICreate("Transparency", 265, 295, @DesktopWidth/2-160, @DesktopHeight/2-90, -1, 0x00000218)
GUISetState(@SW_SHOW)
GUISetState(@SW_SHOWNORMAL)


Global $BI = GUICtrlCreatePic ("C:\Temp\Backgrnd.jpg", 0, 0, 265, 295)
Global $BI = GUICtrlCreatePic("C:\Temp\Backgrnd.jpg", 0, 0, 265, 295)
GUICtrlSetState( -1, $GUI_DISABLE)
GUICtrlSetState(-1, $GUI_DISABLE)


;^) Make a group.
;^) Make a group.
Global $Group = GUICtrlCreateGroup ("", 10, 10, 100, 170)
Global Const $Group = GUICtrlCreateGroup("", 10, 10, 100, 170)


;^) Radio buttons.
;^) Radio buttons.
Global $radio1, $radio2, $radio3, $radio4, $radio5, $radio6, $radio7
Global Const $radio1 = _GUICtrlCreateRadio("Radio 1", 20, 30, 80, 15, $GUI_BKCOLOR_TRANSPARENT, 0x00ff00) ; Green
$radio1 = _GUICtrlCreateRadio ("Radio 1", 20, 30, 80, 15, $GUI_BKCOLOR_TRANSPARENT, 0x00ff00) ; Green
Global Const $radio2 = _GUICtrlCreateRadio("Radio 2", 20, 50, 80, 15, $GUI_BKCOLOR_TRANSPARENT, 0xFFFFFF) ; White
$radio2 = _GUICtrlCreateRadio ("Radio 2", 20, 50, 80, 15, $GUI_BKCOLOR_TRANSPARENT, 0xFFFFFF) ; White
Global Const $radio3 = _GUICtrlCreateRadio("Radio 3", 20, 70, 80, 15, $GUI_BKCOLOR_TRANSPARENT, 0xff0000) ; Red
$radio3 = _GUICtrlCreateRadio ("Radio 3", 20, 70, 80, 15, $GUI_BKCOLOR_TRANSPARENT, 0xff0000) ; Red
Global Const $radio4 = _GUICtrlCreateRadio("Radio 4", 20, 90, 80, 15, $GUI_BKCOLOR_TRANSPARENT)
$radio4 = _GUICtrlCreateRadio ("Radio 4", 20, 90, 80, 15, $GUI_BKCOLOR_TRANSPARENT)
Global Const $radio5 = _GUICtrlCreateRadio("Radio 5", 20, 110, 80, 15, $GUI_BKCOLOR_TRANSPARENT)
$radio5 = _GUICtrlCreateRadio ("Radio 5", 20, 110, 80, 15, $GUI_BKCOLOR_TRANSPARENT)
Global Const $radio6 = _GUICtrlCreateRadio("Radio 6", 20, 130, 80, 15, $GUI_BKCOLOR_TRANSPARENT)
$radio6 = _GUICtrlCreateRadio ("Radio 6", 20, 130, 80, 15, $GUI_BKCOLOR_TRANSPARENT)
Global Const $radio7 = _GUICtrlCreateRadio("Radio 7", 20, 150, 80, 15, $GUI_BKCOLOR_TRANSPARENT)
$radio7 = _GUICtrlCreateRadio ("Radio 7", 20, 150, 80, 15, $GUI_BKCOLOR_TRANSPARENT)




;^) Buttons
;^) Buttonsf
Global $Butt1, $Butt2, $Butt3, $Butt4
Global Const $Butt1 = GUICtrlCreateButton("One", 10, 263, 50, 20)
$Butt1 = GUICtrlCreateButton ("One", 10, 263, 50, 20)
Global Const $Butt2 = GUICtrlCreateButton("Two", 75, 263, 50, 20)
$Butt2 = GUICtrlCreateButton ("Two", 75, 263, 50, 20)
Global Const $Butt3 = GUICtrlCreateButton("Three", 140, 263, 50, 20)
$Butt3 = GUICtrlCreateButton ("Three", 140, 263, 50, 20)
Global Const $Butt4 = GUICtrlCreateButton("Four", 205, 263, 50, 20)
$Butt4 = GUICtrlCreateButton ("Four", 205, 263, 50, 20)


;^) List with label
;^) List with label
GUICtrlCreateLabel("List", 130, 10, 80, 15)
GUICtrlCreateLabel("List", 130, 10, 80, 15)
GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
$List=GUICtrlCreateList ("", 120, 25, 135, 227,$LBS_NoIntegralHeight)
Global Const $List = GUICtrlCreateList("", 120, 25, 135, 227,$LBS_NoIntegralHeight)


;^) GUI is done
;^) GUI is done
Line 224: Line 261:
Wend
Wend


Func _GUICtrlCreateRadio( $rText, $rLeft, $rTop, $rLength, $rHieght, $rBackColor = "" , $rTextColor = "" )
Func _GUICtrlCreateRadio(Const $rText, Const $rLeft, Const $rTop, Const $rLength, Const $rHeight, Const $rBackColor = "", Const $rTextColor = "")
     Local $PCRadio = GUICtrlCreateRadio("", $rLeft, $rTop, 12, 12)
     Local Const $PCRadio = GUICtrlCreateRadio("", $rLeft, $rTop, 12, 12)
    Local $PCLabel = GUICtrlCreateLabel($rText, $rLeft + 15, $rTop, $rLength - 15, $rHieght)
 
GUICtrlCreateLabel($rText, $rLeft + 15, $rTop, $rLength - 15, $rHeight)
 
     If $rTextColor <> "" Then GUICtrlSetColor(-1, $rTextColor)
     If $rTextColor <> "" Then GUICtrlSetColor(-1, $rTextColor)
     If $rBackColor <> "" Then GUICtrlSetBkColor(-1, $rBackColor)
     If $rBackColor <> "" Then GUICtrlSetBkColor(-1, $rBackColor)
     Return $PCRadio
     Return $PCRadio
EndFunc
EndFunc
</syntaxhighlight>
</syntaxhighlight>
<br>
 
[[#top|Return To Contents]]
[[#top | Return To Contents]]

Latest revision as of 17:41, 21 April 2013


Please always credit an author in your script if you use their code. It is only polite.


Are All Items Checked?

Author: guinness








#include <GUIConstantsEx.au3>
#include <GUIListView.au3>
#include <WindowsConstants.au3>

Example()

Func Example()
    Local Const $hGUI = GUICreate("", 400, 300, -1, -1, BitOR($GUI_SS_DEFAULT_GUI, $WS_MAXIMIZEBOX, $WS_SIZEBOX))
    Local $iListView = GUICtrlCreateListView("", 0, 0, 400, 270)
    Local Const $hListView = GUICtrlGetHandle($iListView)
    _GUICtrlListView_SetExtendedListViewStyle($hListView, BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_CHECKBOXES))
    GUICtrlSetResizing(-1, $GUI_DOCKBORDERS)

    Local $iAllSelected = GUICtrlCreateButton("All Selected?", 400 - 90, 275, 85, 22.5)
    GUICtrlSetResizing(-1, $GUI_DOCKRIGHT + $GUI_DOCKSIZE + $GUI_DOCKBOTTOM)

    GUISetState(@SW_SHOWNORMAL, $hGUI)

    __ListViewFill($hListView, Random(1, 5, 1), Random(2, 15, 1), 1) ; Randomly fill data in a ListView.

    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ExitLoop

            Case $iAllSelected
                MsgBox(4096, "", "If all items are checked this will Return True: " & _GUICtrlListView_AllChecked($hListView))
        EndSwitch
    WEnd

    Return GUIDelete($hGUI)
EndFunc   ;==>Example

Func _GUICtrlListView_AllChecked(Const $hListView)
    Local $iChecked = 0

	Local Const $iCount = _GUICtrlListView_GetItemCount($hListView)

    For $i = 0 To $iCount - 1
        If _GUICtrlListView_GetItemChecked($hListView, $i) Then
            $iChecked += 1
        EndIf
    Next

    Return $iChecked = $iCount ; Returns True - all items are checked or False - some are checked.
EndFunc   ;==>_GUICtrlListView_AllChecked

Func __ListViewFill(Const $hListView, Const $iColumns, Const $iRows, Const $iCheckboxes = 0) ; Randomly fill data in a ListView.
    For $A = 0 To $iColumns - 1
        _GUICtrlListView_InsertColumn($hListView, $A, "Column " & $A + 1, 50)
        _GUICtrlListView_SetColumnWidth($hListView, $A - 1, -2)
    Next

    For $A = 0 To $iRows - 1
        _GUICtrlListView_AddItem($hListView, Chr(Random(65, 90, 1)) & " - Row " & $A + 1 & ": Col 1", $A)

		If Random(0, 1, 1) And $iCheckboxes Then
            _GUICtrlListView_SetItemChecked($hListView, $A)
        EndIf

        For $B = 1 To $iColumns
            _GUICtrlListView_AddSubItem($hListView, $A, "Row " & $A + 1 & ": Col " & $B + 1, $B)
        Next
    Next
EndFunc   ;==>__ListViewFill

Return To Contents

_IsChecked

Author: Zedna




Modified: guinness





#include <GUIConstantsEx.au3>

Example()

Func Example()
    Local Const $aState[2] = [$GUI_CHECKED, $GUI_UNCHECKED]
    GUICreate('')
    Local Const $iCheckbox = GUICtrlCreateCheckbox("Checkbox Example", 10, 10, 120, 20)
    GUICtrlSetState($iCheckbox, $aState[Random(0, 1, 1)]) ; Randomise whether or not the checkbox is checked.
    GUISetState(@SW_SHOWNORMAL)

    ; Check the state of the checkbox.
    MsgBox(4096, '', "Is the checkbox checked: " & _IsChecked($iCheckbox))

    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ExitLoop
        EndSwitch
    WEnd
EndFunc   ;==>Example

Func _IsChecked(Const $iControlID)
    Return BitAND(GUICtrlRead($iControlID), $GUI_CHECKED) = $GUI_CHECKED
EndFunc   ;==>_IsChecked

Return To Contents

Listview With Checkboxes

Author: Zedna








#include <GUIConstantsEx.au3>
#include <GUIListView.au3>
#include <WindowsConstants.au3>

Example()

Func Example()
    Local Const $hGUI = GUICreate("", 400, 300, -1, -1, BitOR($GUI_SS_DEFAULT_GUI, $WS_MAXIMIZEBOX, $WS_SIZEBOX))
    Local Const $iListView = GUICtrlCreateListView("", 0, 0, 400, 270)
    Local Const $hListView = GUICtrlGetHandle($iListView)
    _GUICtrlListView_SetExtendedListViewStyle($hListView, BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_CHECKBOXES))
    GUICtrlSetResizing(-1, $GUI_DOCKBORDERS)

    Local $iSelectionState = GUICtrlCreateButton("Change State", 400 - 90, 275, 85, 22.5)
    GUICtrlSetResizing(-1, $GUI_DOCKRIGHT + $GUI_DOCKSIZE + $GUI_DOCKBOTTOM)

    GUISetState(@SW_SHOWNORMAL, $hGUI)

    __ListViewFill($hListView, Random(1, 5, 1), Random(2, 15, 1), 1) ; Randomly fill data in a ListView.

    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ExitLoop

            Case $iSelectionState
                _GUICtrlListView_SetCheckedStates($hListView, 2)
                MsgBox(4096, "", "All items were inverted, so if an item was checked before it was unchecked afterwards.")

                _GUICtrlListView_SetCheckedStates($hListView, 0)
                MsgBox(4096, "", "All items were unchecked.")

                _GUICtrlListView_SetCheckedStates($hListView, 1)
                MsgBox(4096, "", "All items were checked.")
        EndSwitch
    WEnd

    Return GUIDelete($hGUI)
EndFunc   ;==>Example

;~ $iType: 0 - UnCheck all, 1 - Check all & 2 - Invert selection.
Func _GUICtrlListView_SetCheckedStates(Const $hListView, Const $iType) ; By Zedna, Modified by guinness.
    Local $fState = False

	Local Const $iCount = _GUICtrlListView_GetItemCount($hListView)

	If $iType < 0 Or $iType > 2 Then
        Return SetError(1, 0, 0)
    EndIf

    If $iType Then
        $fState = True
    EndIf

    For $i = 0 To $iCount - 1
        If $iType = 2 Then
            $fState = Not _GUICtrlListView_GetItemChecked($hListView, $i) ; Invert checked state with $iType 2.
        EndIf

        _GUICtrlListView_SetItemChecked($hListView, $i, $fState)
    Next
EndFunc   ;==>_GUICtrlListView_SetCheckedStates

Func __ListViewFill(Const $hListView, Const $iColumns, Const $iRows, Const $iCheckboxes = 0) ; Randomly fill data in a ListView.
    For $A = 0 To $iColumns - 1
        _GUICtrlListView_InsertColumn($hListView, $A, "Column " & $A + 1, 50)
        _GUICtrlListView_SetColumnWidth($hListView, $A - 1, -2)
    Next

    For $A = 0 To $iRows - 1
        _GUICtrlListView_AddItem($hListView, Chr(Random(65, 90, 1)) & " - Row " & $A + 1 & ": Col 1", $A)

		If Random(0, 1, 1) And $iCheckboxes Then
            _GUICtrlListView_SetItemChecked($hListView, $A)
        EndIf

        For $B = 1 To $iColumns
            _GUICtrlListView_AddSubItem($hListView, $A, "Row " & $A + 1 & ": Col " & $B + 1, $B)
        Next
    Next
EndFunc   ;==>__ListViewFill

Return To Contents

Transparent Radio Button

Author: Valuater








#include <GUIConstantsEx.au3>
#include <ListBoxConstants.au3>
#include <GUIConstants.au3>

MsgBox(0x0, "", @AutoItVersion)

GUICreate("Transparency", 265, 295, @DesktopWidth/2-160, @DesktopHeight/2-90, -1, 0x00000218)
GUISetState(@SW_SHOWNORMAL)

Global $BI = GUICtrlCreatePic("C:\Temp\Backgrnd.jpg", 0, 0, 265, 295)
GUICtrlSetState(-1, $GUI_DISABLE)

;^) Make a group.
Global Const $Group = GUICtrlCreateGroup("", 10, 10, 100, 170)

;^) Radio buttons.
Global Const $radio1 = _GUICtrlCreateRadio("Radio 1", 20, 30, 80, 15, $GUI_BKCOLOR_TRANSPARENT, 0x00ff00) ; Green
Global Const $radio2 = _GUICtrlCreateRadio("Radio 2", 20, 50, 80, 15, $GUI_BKCOLOR_TRANSPARENT, 0xFFFFFF) ; White
Global Const $radio3 = _GUICtrlCreateRadio("Radio 3", 20, 70, 80, 15, $GUI_BKCOLOR_TRANSPARENT, 0xff0000) ; Red
Global Const $radio4 = _GUICtrlCreateRadio("Radio 4", 20, 90, 80, 15, $GUI_BKCOLOR_TRANSPARENT)
Global Const $radio5 = _GUICtrlCreateRadio("Radio 5", 20, 110, 80, 15, $GUI_BKCOLOR_TRANSPARENT)
Global Const $radio6 = _GUICtrlCreateRadio("Radio 6", 20, 130, 80, 15, $GUI_BKCOLOR_TRANSPARENT)
Global Const $radio7 = _GUICtrlCreateRadio("Radio 7", 20, 150, 80, 15, $GUI_BKCOLOR_TRANSPARENT)


;^) Buttonsf
Global Const $Butt1 = GUICtrlCreateButton("One", 10, 263, 50, 20)
Global Const $Butt2 = GUICtrlCreateButton("Two", 75, 263, 50, 20)
Global Const $Butt3 = GUICtrlCreateButton("Three", 140, 263, 50, 20)
Global Const $Butt4 = GUICtrlCreateButton("Four", 205, 263, 50, 20)

;^) List with label
GUICtrlCreateLabel("List", 130, 10, 80, 15)
GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
Global Const $List = GUICtrlCreateList("", 120, 25, 135, 227,$LBS_NoIntegralHeight)

;^) GUI is done
While GUIGetMsg() <> -3
Wend

Func _GUICtrlCreateRadio(Const $rText, Const $rLeft, Const $rTop, Const $rLength, Const $rHeight, Const $rBackColor = "", Const $rTextColor = "")
    Local Const $PCRadio = GUICtrlCreateRadio("", $rLeft, $rTop, 12, 12)

	GUICtrlCreateLabel($rText, $rLeft + 15, $rTop, $rLength - 15, $rHeight)

    If $rTextColor <> "" Then GUICtrlSetColor(-1, $rTextColor)

    If $rBackColor <> "" Then GUICtrlSetBkColor(-1, $rBackColor)

    Return $PCRadio
EndFunc

Return To Contents