Opt('GUIOnEventMode', 1)
GUICreate('afan Checkbox 例子', 150, 500)
GUISetOnEvent(-3, '_Exit')
Local $Checkbox[21]
$Checkbox[0] = GUICtrlCreateCheckbox('Checkbox0 - 总管', 10, 450, 120, 17)
GUICtrlSetOnEvent(-1, '_ZG')
For $i = 1 To 20
$Checkbox[$i] = GUICtrlCreateCheckbox('Checkbox' & $i, 10, 20 * $i, 100, 17)
Assign('_ _||' & $Checkbox[$i] & ':)', 1)
Next
$c = 0
GUISetState()
GUIRegisterMsg(0x0111, 'WM_COMMAND')
While 1
Sleep(1000)
WEnd
Func _Exit()
Exit
EndFunc ;==>_Exit
Func _ZG()
If GUICtrlRead($Checkbox[0]) = 1 Then
Local $state = 1
$c = 20
Else
Local $state = 4
$c = 0
EndIf
For $i = 1 To 20
GUICtrlSetState($Checkbox[$i], $state)
Next
EndFunc ;==>_ZG
Func WM_COMMAND($hWnd, $msg, $wParam)
#forceref $hWnd, $Msg
Local $nID = BitAND($wParam, 0xFFFF)
If IsDeclared('_ _||' & $nID & ':)') Then
If GUICtrlRead($nID) = 1 Then
$c += 1
Else
$c -= 1
EndIf
If $c > 0 Then
GUICtrlSetState($Checkbox[0], 1)
Else
GUICtrlSetState($Checkbox[0], 4)
EndIf
EndIf
EndFunc ;==>WM_COMMAND
|