|
_CheckboxOpt_udf.au3;==========================================================================================
; 说明: 对Checkbox复选框进行多种功能操作:
; 1,返回选中的索引;2,按关键字匹配并选中;3,全选/全不选/反选
; 4,可对单控件实现切换全选/全不选or反选(可自定义文本)|单控件单功能(如仅反选)
; 语法: _CheckboxOpt(复选框数组名[, 控件ID或'操作选项'[, 全不选或反选的标志[, '全选|全不选|反选(显示文本)']]])
; 参数: 复选框数组名 - 必须的参数(如 $Checkbox ),同时复选框变量必须为数组;
; 控件ID或'操作选项' - 这是个多选择的参数,值为'xh' (默认)将返回选中的索引,后面的参数随之无效;下同
; 值为'pp' 时将作为匹配并选中含指定文本的复选框功能,之后的 $sy 参数值则代表指定文本;
; 值为 'qx'时全选|'qbx' 时全不选|'fx' 时反选;
; 值为控件ID时,则完成单控件切换全选/全不选(反选),单控件单功能(如仅全选)的功能。
; 全不选或反选的标志 - 此参数因前一位参数的不同而具不同意义,当前个参数为'pp'时,它的值将作为指定文本;
; 而当前个参数为控件ID时,其作为切换 1 = “全不选” 或 2 = “反选” 或 0 = 不切换的开关。
; '全选|全不选|反选' - 在控件上显示的文本,可以修改,但同时界面的相关控件文本也要包含于其中。
; 作者: Afan -- http://www.autoitx.com/?fromuid=7644923
;==========================================================================================
Func _CheckboxOpt($CbName, $OptorID = 'xh', $sy = 1, $nnn = '全选|全不选|反选')
Local $gm, $Yxz = '', $nr, $n1, $n2, $n3, $nfg, $ppsl = 0, $rdtxt
If $OptorID = 'xh' Then
For $i = 0 To UBound($CbName) - 1
If GUICtrlRead($CbName[$i]) = 1 Then $Yxz &= $i & '|'
Next
Return StringTrimRight($Yxz, 1)
ElseIf $OptorID = 'pp' Then
For $i = 0 To UBound($CbName) - 1
$rdtxt = GUICtrlRead($CbName[$i], 1)
If $rdtxt <> '0' Then
If StringInStr($rdtxt, $sy) <> 0 Then
GUICtrlSetState($CbName[$i], $GUI_CHECKED)
$ppsl += 1
EndIf
EndIf
Next
If $ppsl = 0 Then MsgBox(0, '匹配结果', '没有匹配的项目')
Return $ppsl
ElseIf $OptorID = 'qx' Then
qxuanf($CbName, 'qx')
Return
ElseIf $OptorID = 'qbx' Then
qxuanf($CbName, 'qbx')
Return
ElseIf $OptorID = 'fx' Then
qxuanf($CbName, 'fx')
Return
EndIf
$nr = GUICtrlRead($OptorID)
$nfg = StringSplit($nnn, '|')
If @error = 1 And $nfg[1] = '' Then
Exit (MsgBox(0, 0, '$nnn 参数设置错误'))
Else
$n1 = $nfg[1]
$n2 = $nfg[2]
$n3 = $nfg[3]
EndIf
If $sy = 1 Then $gm = $n2
If $sy = 2 Then $gm = $n3
If $nr <> $n1 And $nr <> $n2 And $nr <> $n3 Then Exit (MsgBox(48, '问题', '此控件文本名不在函数中,请核实。'))
If $nr = $n1 Then
qxuanf($CbName, 'qx')
If $sy <> 0 Then GUICtrlSetData($OptorID, $gm)
ElseIf $nr = $n2 Then
qxuanf($CbName, 'qbx')
If $sy <> 0 Then GUICtrlSetData($OptorID, $n1)
ElseIf $nr = $n3 Then
qxuanf($CbName, 'fx')
If $sy <> 0 Then GUICtrlSetData($OptorID, $n1)
EndIf
EndFunc ;==>_CheckboxOpt
Func qxuanf($CbName, $bj)
If $bj = 'qbx' Then $xuanz = $GUI_UNCHECKED
If $bj = 'qx' Then $xuanz = $GUI_CHECKED
For $i = 0 To UBound($CbName) - 1
If $bj = 'qx' Or $bj = 'qbx' Then
GUICtrlSetState($CbName[$i], $xuanz)
ElseIf $bj = 'fx' Then
If GUICtrlRead($CbName[$i]) = 1 Then
GUICtrlSetState($CbName[$i], $GUI_UNCHECKED)
ElseIf GUICtrlRead($CbName[$i]) = 4 Then
GUICtrlSetState($CbName[$i], $GUI_CHECKED)
EndIf
EndIf
Next
EndFunc ;==>qxuanf
软件安装器列子源码#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include '_CheckboxOpt_udf.au3'
#Region ### START Koda GUI section ### Form=C:\Documents and Settings\Administrator\桌面\选择安装程序111.kxf
$Form1 = GUICreate("XXXX", 243, 343, 192, 124)
Dim $Checkbox[6]
$B = GUICtrlCreateButton("开始安装(&O)", 72, 216, 97, 25)
$Checkbox[1] = GUICtrlCreateCheckbox("XXXXXX1", 16, 32, 97, 17)
$Checkbox[2] = GUICtrlCreateCheckbox("XXXXXX2", 16, 56, 97, 17)
$Checkbox[3] = GUICtrlCreateCheckbox("XXXXXX3", 16, 80, 97, 17)
$Checkbox[4] = GUICtrlCreateCheckbox("XXXXXX4", 16, 104, 97, 17)
$Checkbox[5] = GUICtrlCreateCheckbox("XXXXXX5", 16, 128, 113, 17)
$Button5 = GUICtrlCreateButton("全选", 24, 176, 57, 25)
$Button6 = GUICtrlCreateButton("反选", 152, 176, 57, 25)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
$ck = 0
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case -3
Exit
Case $b
For $i = 1 To 5
If GUICtrlRead(Eval('Checkbox' & $i)) = 1 Then
$ck = $i
Call('_Go')
EndIf
Next
Case $GUI_EVENT_CLOSE
Exit
Case $Button5 ;例子4,单控件切换全选/反选
_CheckboxOpt($Checkbox, $Button5, 2)
Case $Button6 ;例子5,单控件单功能(如仅反选,取决于按钮上的文字)
_CheckboxOpt($Checkbox, $Button6, 0)
EndSwitch
WEnd
Func _Go()
Switch $ck
Case 1
RunWait("XXXXXXXXXXX1.exe")
Case 2
RunWait("XXXXXXXXXX2.exe")
Case 3
RunWait("XXXXXXXXX3.exe")
Case 4
RunWait("XXXXXXXXXXXXXX4.exe")
Case 5
RunWait("XXXXXXXXXXXXXX5.exe")
EndSwitch
EndFunc
|
|