[已解决]复选框没有选中如何有个提示
本帖最后由 dnvplj 于 2015-6-11 21:55 编辑请问各位朋友:如果没有选中复选框,在按“自动安装”按钮时如何做到有个提示,如,您没有选中任何想要安装的软件。说明,该代码是一位前辈给我的,我做了修改,但这位前辈现无法联系上了,所以现无法注明原作者。#include <GUIConstants.au3>
#include <ProgressConstants.au3>
#include <WindowsConstants.au3>
#include <StaticConstants.au3>
$soft_ini = FileOpen("Soft.ini", 0)
If $soft_ini = -1 Then
MsgBox(16, "错误", '请检查配置文件' & @ScriptDir & '\"Soft.ini"是否存在!')
EndIf
FileClose($soft_ini)
Const $N = 13, $s = 4
Dim $softname[$N], $softPath[$N], $soft[$N], $radio[$s], $InstallPath
For $i = 0 To $N - 1
$softname[$i] = IniRead("soft.ini", $i, "softname", "空")
$softPath[$i] = IniRead("soft.ini", $i, "softpath", "空")
Next
$form = GUICreate("", 630, 420, -1, -1)
$Label1 = GUICtrlCreateLabel("软件 - 安装助理", 22, 33, 300, 26)
$Group1 = GUICtrlCreateGroup("", 22, 80, 588, 256)
$soft = GUICtrlCreateCheckbox($softname, 60, 110, 150, 20)
$soft = GUICtrlCreateCheckbox($softname, 60, 166, 150, 20)
$soft = GUICtrlCreateCheckbox($softname, 60, 216, 150, 20)
$soft = GUICtrlCreateCheckbox($softname, 60, 266, 150, 20)
$soft = GUICtrlCreateCheckbox($softname, 243, 110, 150, 20)
$soft = GUICtrlCreateCheckbox($softname, 243, 166, 150, 20)
$soft = GUICtrlCreateCheckbox($softname, 243, 216, 150, 20)
$soft = GUICtrlCreateCheckbox($softname, 243, 266, 150, 20)
$soft = GUICtrlCreateCheckbox($softname, 426, 110, 150, 20)
$soft = GUICtrlCreateCheckbox($softname, 426, 166, 150, 20)
$soft = GUICtrlCreateCheckbox($softname, 426, 216, 150, 20)
$soft = GUICtrlCreateCheckbox($softname, 426, 266, 150, 20)
$setA = IniRead("soft.ini", "select", "A", "")
$chooseA = IniRead("soft.ini", "select", "ChooseA", "")
$setB = IniRead("soft.ini", "select", "B", "")
$chooseB = IniRead("soft.ini", "select", "ChooseB", "")
$radio = GUICtrlCreateRadio($setA & "(&A)", 140, 327, 60, 17)
$radio = GUICtrlCreateRadio($setB & "(&B)", 210, 327, 61, 17)
$Button3 = GUICtrlCreateButton("自动安装", 406, 360, 82, 33)
$Button4 = GUICtrlCreateButton("退出", 498, 360, 82, 33)
GUISetState(@SW_SHOW)
While 1
$nMsg = GUIGetMsg()
Select
Case $nMsg = $GUI_EVENT_CLOSE
AdlibUnRegister()
ExitLoop
Case $nMsg = $radio And BitAND(GUICtrlRead($radio), $GUI_CHECKED) = $GUI_CHECKED
$all = all()
Case $nMsg = $radio And BitAND(GUICtrlRead($radio), $GUI_CHECKED) = $GUI_CHECKED
$none = none()
Case $nMsg = $Button3
$AZ = AZ()
Case $nMsg = $Button4
Exit
EndSelect
WEnd
Func all()
AdlibUnRegister()
For $i = 0 To $N - 1
If $softname[$i] And $softPath[$i] <> "" Then
GUICtrlSetState($soft[$i], $GUI_CHECKED)
Else
GUICtrlSetState($soft[$i], $GUI_UNCHECKED)
EndIf
Next
EndFunc ;==>all
Func none()
AdlibUnRegister()
For $i = 0 To $N - 1
If $softname[$i] And $softPath[$i] <> "" Then
GUICtrlSetState($soft[$i], $GUI_UNCHECKED)
Else
GUICtrlSetState($soft[$i], $GUI_UNCHECKED)
EndIf
Next
EndFunc ;==>none
Func AZ()
AdlibUnRegister()
For $i = 0 To $N - 1
If $softPath[$i] <> "" And GUICtrlRead($soft[$i]) = $GUI_CHECKED Then
RunWait(@ScriptDir & "\" & $softPath[$i] & " " & $InstallPath)
EndIf
Next
If Not $softPath Then MsgBox(48, '温馨提示:', '您所选软件:现以安装完成,是否退?')
EndFunc ;==>AZ
附:配置文件
#include <GUIConstants.au3>
#include <ProgressConstants.au3>
#include <WindowsConstants.au3>
#include <StaticConstants.au3>
Local $aSoft = IniReadSection('soft.ini', 'SOFT')
If @error Then Exit MsgBox(16, 'Err', '配置文件不存在,本程序无法继续运行!', 5)
$form = GUICreate("", 630, 420, -1, -1)
$Label1 = GUICtrlCreateLabel("软件 - 安装助理", 22, 33, 300, 26)
$Group1 = GUICtrlCreateGroup("", 22, 80, 588, 256)
Global Const $N = $aSoft
Global $aChecked[$N + 1]
Global $aChBox[$N + 1] ;复选框总数
Global $iN = 4 ;每行显示的 复选框 数量
Global $iH = 140, $iV = 50 ;垂直、水平,间距
For $i = 0 To $N - 1
$aChBox[$i + 1] = GUICtrlCreateCheckbox($aSoft[$i + 1], $iH * Mod($i, $iN) + 50, $iV * Floor($i / $iN) + 100, 120, 20)
Next
$radio1 = GUICtrlCreateRadio("全选", 50, 327, 45, 17)
$radio2 = GUICtrlCreateRadio('反选', 110, 327, 45, 17)
$Button3 = GUICtrlCreateButton("自动安装", 406, 360, 82, 33)
$Button4 = GUICtrlCreateButton("退出", 498, 360, 82, 33)
GUISetState(@SW_SHOW)
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
ExitLoop
Case $aChBox To $aChBox[$N]
If GUICtrlRead($nMsg) = $GUI_CHECKED Then
$aChecked[$nMsg - $aChBox + 1] = 1
$aChecked += 1
Else
$aChecked[$nMsg - $aChBox + 1] = 0
$aChecked -= 1
EndIf
Case $radio1
_all_none()
Case $radio2
_inverse()
Case $Button3
_AZ()
Case $Button4
ExitLoop
EndSwitch
WEnd
Func _all_none()
Select
Case $aChecked < $N
For $i = 1 To $N
$aChecked[$i] = 1
GUICtrlSetState($aChBox[$i], $GUI_CHECKED)
Next
$aChecked = $N
Case $aChecked == $N
For $i = 1 To $N
$aChecked[$i] = 0
GUICtrlSetState($aChBox[$i], $GUI_UNCHECKED)
Next
$aChecked = 0
EndSelect
EndFunc ;==>_all_none
Func _inverse()
For $i = 1 To $N
If $aChecked[$i] Then
GUICtrlSetState($aChBox[$i], $GUI_UNCHECKED)
$aChecked[$i] = 0
$aChecked -= 1
Else
$aChecked[$i] = 1
$aChecked += 1
GUICtrlSetState($aChBox[$i], $GUI_CHECKED)
EndIf
Next
EndFunc ;==>_inverse
Func _AZ()
If $aChecked < 1 Then Return MsgBox(16, '操作错误', '当前选中了0个软件.', 0, $form)
For $i = 1 To $N
If $aChecked[$i] And FileExists(@ScriptDir & "\" & $aSoft[$i]) Then
RunWait(@ScriptDir & "\" & $aSoft[$i])
EndIf
Next
; If Not $softPath Then MsgBox(48, '温馨提示:', '您所选软件:现以安装完成,是否退?')
EndFunc ;==>_AZ
ini
腾讯QQ轻聊版6.7版="soft\1.exe"
迷你PDF阅读器版="soft\2.exe"
Office2003四合一="soft\3.exe"
迅雷极速版v1.0版="soft\4.exe"
Flash Player17版="soft\5.exe"
腾讯QQ轻聊版6.8版="soft\6.exe"
Office2007四合一="soft\7.exe"
迅雷极速版v2.0版="soft\8.exe" 回复 3# Alam
感谢楼上朋友的回复,复制2楼的代码,用3楼的配置文件,按“全选”,在点“自动安装”,什么反映都没有(软件放到了Soft文件夹了);别外,“If Not $softPath Then MsgBox(48, '温馨提示:', '您所选软件:现以安装完成,是否退?')”一运行代码出错。 回复 4# dnvplj
没有反映,应该是路径不对.要保证有此EXE文件,并且路径正确.
尝试去掉配置文件中的括住路径的"双引号", 比如:
迅雷极速版v2.0版=soft\8.exe 腾讯QQ轻聊版6.7版=soft\1.exe
点“自动安装”后,主程序直接退出了。 回复 5# Alam
腾讯QQ轻聊版6.7版=soft\1.exe
点“自动安装”后,主程序直接退出了。 回复 7# dnvplj
自己尝试调试吧. 比如这样查看路径是否正确. For $i = 1 To $N
ConsoleWrite($i & @TAB & $aSoft[$i] & @CRLF)
If $aChecked[$i] And FileExists(@ScriptDir & "\" & $aSoft[$i]) Then
MsgBox(0, 'path', @ScriptDir & "\" & $aSoft[$i]))
RunWait(@ScriptDir & "\" & $aSoft[$i])
EndIf
Next
页:
[1]