复选框如何全选和取消
本帖最后由 dnvplj 于 2015-9-5 10:15 编辑请问各位朋友,下面的代码如何作到“全选、取消、安装”,请指教。#include <GUIConstants.au3>
#include <WindowsConstants.au3>
#include <StaticConstants.au3>
#include <ButtonConstants.au3>
#include <GuiListView.au3>
Global $N = 14, $gua_softname[$N], $gua_softPath[$N], $gua_ListView
$gu_Form1 = _
GUICreate('', 620, 430, -1, -1)
$gu_button1 = _
GUICtrlCreateButton('安装(&E)', 500, 200, 75, 25)
$gu_button2 = _
GUICtrlCreateButton('全选(&Q)', 500, 250, 75, 25)
$gu_button3 = _
GUICtrlCreateButton('不选(&B)', 500, 300, 75, 25)
$gu_nListView = _
GUICtrlCreateListView('', 16, 60, 420, 310, _
BitOR($GUI_SS_DEFAULT_LISTVIEW, $WS_HSCROLL, $WS_VSCROLL), _
BitOR($WS_EX_CLIENTEDGE, $LVS_EX_GRIDLINES, $LVS_EX_CHECKBOXES))
_Main()
Exit
Func _Main()
_GUICtrlListView_AddColumn($gu_nListView, "序号", 50)
_GUICtrlListView_AddColumn($gu_nListView, "软件名称", 170)
_IniFile()
GUISetState(@SW_SHOW, $gu_Form1)
While 1
Switch GUIGetMsg()
Case $GUI_EVENT_CLOSE
Exit
Case $gu_button2
For $i = 1 To $N
GUICtrlSetState($gua_ListView[$i], $GUI_CHECKED)
Next
Case $gu_button3
For $i = 1 To $N
GUICtrlSetState($gua_ListView[$i], $GUI_UNCHECKED)
Next
Case $gu_button1
yunxing()
EndSwitch
WEnd
EndFunc ;==>_Main
Func _IniFile()
If FileExists(@ScriptDir & '\Soft.ini') Then
Else
MsgBox(16, "错误", '请检查配置文件' & '是否存在!')
Exit
EndIf
For $i = 1 To $N - 1
$gua_softname[$i] = IniRead(@ScriptDir & "\soft.ini", $i, "softname", "空")
$gua_softPath[$i] = IniRead(@ScriptDir & "\soft.ini", $i, "softpath", "空")
$gua_ListView[$N] = GUICtrlCreateListViewItem(" " & $i & '|' & $gua_softname[$i], $gu_nListView)
Next
EndFunc ;==>_IniFile
Func yunxing()
For $i = 1 To $N
If GUICtrlRead($gua_ListView[$i], 1) = 1 Then
ShellExecuteWait($gua_ListView[$i])
EndIf
Next
EndFunc ;==>yunxing
二、配置文件
softname=软件1
softpath="soft\1.exe"
softname=软件2
softpath="soft\2.exe"
softname=软件3
softpath="soft\3.exe" 給你一個現成的代碼研究一下#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <WinAPI.au3>
$Form1 = Guicreate("Client PC 自動化安裝程式", 340, 120, -1, -1)
$Button1 = GuiCtrlCreateButton("全選", 10, 95, 60, 20)
$Button2 = GuiCtrlCreateButton("取消全選", 130, 95, 60, 20)
$Button3 = GuiCtrlCreateButton("執行", 250, 95, 60, 20)
$Checkbox1 = GUICtrlCreateCheckbox("Office2003", 10, 10, 120, 20)
$Checkbox2 = GUICtrlCreateCheckbox("還原軟件", 10, 40, 120, 20)
$Checkbox3 = GUICtrlCreateCheckbox("AdbeRdr810", 10, 70, 120, 20)
$Checkbox4 = GUICtrlCreateCheckbox("Java", 130, 10, 120, 20)
$Checkbox5 = GUICtrlCreateCheckbox("7-Zip", 130, 40, 120, 20)
$Checkbox6 = GUICtrlCreateCheckbox("ERP", 130, 70, 120, 20)
$Checkbox7 = GUICtrlCreateCheckbox("VNC監視器", 250, 10, 120, 20)
$Checkbox8 = GUICtrlCreateCheckbox("Xn View", 250, 40, 120, 20)
$Checkbox9 = GUICtrlCreateCheckbox("IE7", 250, 70, 120, 20)
GuiSetState(@SW_SHOW)
HotKeySet("{ESC}", "_Exit") ;按Esc結束程式
Func _Exit()
Exit 0
EndFunc
While 1
$Msg = GUIGetMsg()
Switch $Msg
Case $GUI_EVENT_CLOSE
Exit
Case $Button1 ;設定Checkbox 1~11 全選
GUICtrlSetState($Checkbox1,$GUI_CHECKED)
GUICtrlSetState($Checkbox2,$GUI_CHECKED)
GUICtrlSetState($Checkbox3,$GUI_CHECKED)
GUICtrlSetState($Checkbox4,$GUI_CHECKED)
GUICtrlSetState($Checkbox5,$GUI_CHECKED)
GUICtrlSetState($Checkbox6,$GUI_CHECKED)
GUICtrlSetState($Checkbox7,$GUI_CHECKED)
GUICtrlSetState($Checkbox8,$GUI_CHECKED)
GUICtrlSetState($Checkbox9,$GUI_CHECKED)
Case $Button2 ;設定Checkbox 1~11 取消全選
GUICtrlSetState($Checkbox1,$GUI_UNCHECKED)
GUICtrlSetState($Checkbox2,$GUI_UNCHECKED)
GUICtrlSetState($Checkbox3,$GUI_UNCHECKED)
GUICtrlSetState($Checkbox4,$GUI_UNCHECKED)
GUICtrlSetState($Checkbox5,$GUI_UNCHECKED)
GUICtrlSetState($Checkbox6,$GUI_UNCHECKED)
GUICtrlSetState($Checkbox7,$GUI_UNCHECKED)
GUICtrlSetState($Checkbox8,$GUI_UNCHECKED)
GUICtrlSetState($Checkbox9,$GUI_UNCHECKED)
Case $Button3
If BitAND(GUICtrlRead($Checkbox1),$gui_checked) Then
RunWait("各軟體Auto\5.安裝Office2003.exe",@ScriptDir)
EndIf
If BitAND(GUICtrlRead($Checkbox2),$gui_checked) Then
RunWait("各軟體Auto\2.安裝還原軟件.exe",@ScriptDir)
EndIf
If BitAND(GUICtrlRead($Checkbox3),$gui_checked) Then
RunWait("各軟體Auto\3.安裝AdbeRdr810.exe",@ScriptDir)
EndIf
If BitAND(GUICtrlRead($Checkbox4),$gui_checked) Then
RunWait("各軟體Auto\4.安裝Java.exe",@ScriptDir)
EndIf
If BitAND(GUICtrlRead($Checkbox5),$gui_checked) Then
RunWait("各軟體Auto\1.安裝7-Zip.exe",@ScriptDir)
EndIf
If BitAND(GUICtrlRead($Checkbox6),$gui_checked) Then
RunWait("各軟體Auto\6.安裝ERP.exe",@ScriptDir)
EndIf
If BitAND(GUICtrlRead($Checkbox7),$gui_checked) Then
RunWait("各軟體Auto\7.安裝VNC監視器.exe",@ScriptDir)
EndIf
If BitAND(GUICtrlRead($Checkbox8),$gui_checked) Then
RunWait("各軟體Auto\8.安裝Xn View.exe",@ScriptDir)
EndIf
If BitAND(GUICtrlRead($Checkbox9),$gui_checked) Then
RunWait("各軟體Auto\9.安裝IE7.exe",@ScriptDir)
EndIf
MsgBox(0,"Auto Install Script","Auto Client Install 自動安裝、設定完畢" &@LF& " 請立即重新開機完成安裝程序")
EndSwitch
Wend 給你一個現成的代碼研究一下#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <WinAPI.au3>
$Form1 = Guicreate("Client PC 自動化安裝程式", 340, 120, -1, -1)
$Button1 = GuiCtrlCreateButton("全選", 10, 95, 60, 20)
$Button2 = GuiCtrlCreateButton("取消全選", 130, 95, 60, 20)
$Button3 = GuiCtrlCreateButton("執行", 250, 95, 60, 20)
$Checkbox1 = GUICtrlCreateCheckbox("Office2003", 10, 10, 120, 20)
$Checkbox2 = GUICtrlCreateCheckbox("還原軟件", 10, 40, 120, 20)
$Checkbox3 = GUICtrlCreateCheckbox("AdbeRdr810", 10, 70, 120, 20)
$Checkbox4 = GUICtrlCreateCheckbox("Java", 130, 10, 120, 20)
$Checkbox5 = GUICtrlCreateCheckbox("7-Zip", 130, 40, 120, 20)
$Checkbox6 = GUICtrlCreateCheckbox("ERP", 130, 70, 120, 20)
$Checkbox7 = GUICtrlCreateCheckbox("VNC監視器", 250, 10, 120, 20)
$Checkbox8 = GUICtrlCreateCheckbox("Xn View", 250, 40, 120, 20)
$Checkbox9 = GUICtrlCreateCheckbox("IE7", 250, 70, 120, 20)
GuiSetState(@SW_SHOW)
HotKeySet("{ESC}", "_Exit") ;按Esc結束程式
Func _Exit()
Exit 0
EndFunc
While 1
$Msg = GUIGetMsg()
Switch $Msg
Case $GUI_EVENT_CLOSE
Exit
Case $Button1 ;設定Checkbox 1~11 全選
GUICtrlSetState($Checkbox1,$GUI_CHECKED)
GUICtrlSetState($Checkbox2,$GUI_CHECKED)
GUICtrlSetState($Checkbox3,$GUI_CHECKED)
GUICtrlSetState($Checkbox4,$GUI_CHECKED)
GUICtrlSetState($Checkbox5,$GUI_CHECKED)
GUICtrlSetState($Checkbox6,$GUI_CHECKED)
GUICtrlSetState($Checkbox7,$GUI_CHECKED)
GUICtrlSetState($Checkbox8,$GUI_CHECKED)
GUICtrlSetState($Checkbox9,$GUI_CHECKED)
Case $Button2 ;設定Checkbox 1~11 取消全選
GUICtrlSetState($Checkbox1,$GUI_UNCHECKED)
GUICtrlSetState($Checkbox2,$GUI_UNCHECKED)
GUICtrlSetState($Checkbox3,$GUI_UNCHECKED)
GUICtrlSetState($Checkbox4,$GUI_UNCHECKED)
GUICtrlSetState($Checkbox5,$GUI_UNCHECKED)
GUICtrlSetState($Checkbox6,$GUI_UNCHECKED)
GUICtrlSetState($Checkbox7,$GUI_UNCHECKED)
GUICtrlSetState($Checkbox8,$GUI_UNCHECKED)
GUICtrlSetState($Checkbox9,$GUI_UNCHECKED)
Case $Button3
If BitAND(GUICtrlRead($Checkbox1),$gui_checked) Then
RunWait("各軟體Auto\5.安裝Office2003.exe",@ScriptDir)
EndIf
If BitAND(GUICtrlRead($Checkbox2),$gui_checked) Then
RunWait("各軟體Auto\2.安裝還原軟件.exe",@ScriptDir)
EndIf
If BitAND(GUICtrlRead($Checkbox3),$gui_checked) Then
RunWait("各軟體Auto\3.安裝AdbeRdr810.exe",@ScriptDir)
EndIf
If BitAND(GUICtrlRead($Checkbox4),$gui_checked) Then
RunWait("各軟體Auto\4.安裝Java.exe",@ScriptDir)
EndIf
If BitAND(GUICtrlRead($Checkbox5),$gui_checked) Then
RunWait("各軟體Auto\1.安裝7-Zip.exe",@ScriptDir)
EndIf
If BitAND(GUICtrlRead($Checkbox6),$gui_checked) Then
RunWait("各軟體Auto\6.安裝ERP.exe",@ScriptDir)
EndIf
If BitAND(GUICtrlRead($Checkbox7),$gui_checked) Then
RunWait("各軟體Auto\7.安裝VNC監視器.exe",@ScriptDir)
EndIf
If BitAND(GUICtrlRead($Checkbox8),$gui_checked) Then
RunWait("各軟體Auto\8.安裝Xn View.exe",@ScriptDir)
EndIf
If BitAND(GUICtrlRead($Checkbox9),$gui_checked) Then
RunWait("各軟體Auto\9.安裝IE7.exe",@ScriptDir)
EndIf
MsgBox(0,"Auto Install Script","Auto Client Install 自動安裝、設定完畢" &@LF& " 請立即重新開機完成安裝程序")
EndSwitch
Wend 感谢楼上朋友的回复,我研究研究。 GUICtrlSetState($Checkbox10, $GUI_CHECKED)
GUICtrlSetState($Checkbox11, $GUI_UNCHECKED) 感谢楼上朋友的回复
页:
[1]