找回密码
 加入
搜索
查看: 4313|回复: 7

[AU3基础] [已解决]复选框没有选中如何有个提示

[复制链接]
发表于 2015-6-10 21:25:06 | 显示全部楼层 |阅读模式
本帖最后由 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[1] = GUICtrlCreateCheckbox($softname[1], 60, 110, 150, 20)
$soft[2] = GUICtrlCreateCheckbox($softname[2], 60, 166, 150, 20)
$soft[3] = GUICtrlCreateCheckbox($softname[3], 60, 216, 150, 20)
$soft[4] = GUICtrlCreateCheckbox($softname[4], 60, 266, 150, 20)

$soft[5] = GUICtrlCreateCheckbox($softname[5], 243, 110, 150, 20)
$soft[6] = GUICtrlCreateCheckbox($softname[6], 243, 166, 150, 20)
$soft[7] = GUICtrlCreateCheckbox($softname[7], 243, 216, 150, 20)
$soft[8] = GUICtrlCreateCheckbox($softname[8], 243, 266, 150, 20)

$soft[09] = GUICtrlCreateCheckbox($softname[9], 426, 110, 150, 20)
$soft[10] = GUICtrlCreateCheckbox($softname[10], 426, 166, 150, 20)
$soft[11] = GUICtrlCreateCheckbox($softname[11], 426, 216, 150, 20)
$soft[12] = GUICtrlCreateCheckbox($softname[12], 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[1] = GUICtrlCreateRadio($setA & "(&A)", 140, 327, 60, 17)
$radio[2] = 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[1] And BitAND(GUICtrlRead($radio[1]), $GUI_CHECKED) = $GUI_CHECKED 
                        $all = all()
                Case $nMsg = $radio[2] And BitAND(GUICtrlRead($radio[2]), $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
[/code]附:配置文件

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?加入

×
发表于 2015-6-11 20:20:27 | 显示全部楼层
#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[0][0]
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][0], $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[1] To $aChBox[$N]
                        If GUICtrlRead($nMsg) = $GUI_CHECKED Then
                                $aChecked[$nMsg - $aChBox[1] + 1] = 1
                                $aChecked[0] += 1
                        Else
                                $aChecked[$nMsg - $aChBox[1] + 1] = 0
                                $aChecked[0] -= 1
                        EndIf
                Case $radio1
                        _all_none()
                Case $radio2
                        _inverse()
                Case $Button3
                        _AZ()
                Case $Button4
                        ExitLoop
        EndSwitch
WEnd

Func _all_none()
        Select
                Case $aChecked[0] < $N
                        For $i = 1 To $N
                                $aChecked[$i] = 1
                                GUICtrlSetState($aChBox[$i], $GUI_CHECKED)
                        Next
                        $aChecked[0] = $N

                Case $aChecked[0] == $N
                        For $i = 1 To $N
                                $aChecked[$i] = 0
                                GUICtrlSetState($aChBox[$i], $GUI_UNCHECKED)
                        Next
                        $aChecked[0] = 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[0] -= 1
                Else
                        $aChecked[$i] = 1
                        $aChecked[0] += 1
                        GUICtrlSetState($aChBox[$i], $GUI_CHECKED)
                EndIf
        Next
EndFunc   ;==>_inverse

Func _AZ()
        If $aChecked[0] < 1 Then Return MsgBox(16, '操作错误', '当前选中了0个软件.', 0, $form)
        For $i = 1 To $N
                If $aChecked[$i] And FileExists(@ScriptDir & "" & $aSoft[$i][1]) Then
                        RunWait(@ScriptDir & "" & $aSoft[$i][1])
                EndIf
        Next
        ; If Not $softPath Then MsgBox(48, '温馨提示:', '您所选软件:现以安装完成,是否退?')
EndFunc   ;==>_AZ

评分

参与人数 1金钱 +10 收起 理由
dnvplj + 10 助人为乐

查看全部评分

发表于 2015-6-11 20:20:57 | 显示全部楼层
ini
[SOFT]
腾讯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"
 楼主| 发表于 2015-6-11 20:44:54 | 显示全部楼层
回复 3# Alam

感谢楼上朋友的回复,复制2楼的代码,用3楼的配置文件,按“全选”,在点“自动安装”,什么反映都没有(软件放到了Soft文件夹了);别外,“If Not $softPath Then MsgBox(48, '温馨提示:', '您所选软件:现以安装完成,是否退?')”一运行代码出错。
发表于 2015-6-11 21:41:25 | 显示全部楼层
回复 4# dnvplj

没有反映,应该是路径不对.要保证有此EXE文件,并且路径正确.

尝试去掉配置文件中的括住路径的"双引号", 比如:
迅雷极速版v2.0版=soft\8.exe
 楼主| 发表于 2015-6-11 21:49:53 | 显示全部楼层
腾讯QQ轻聊版6.7版=soft\1.exe
点“自动安装”后,主程序直接退出了。
 楼主| 发表于 2015-6-11 21:50:27 | 显示全部楼层
回复 5# Alam

腾讯QQ轻聊版6.7版=soft\1.exe
点“自动安装”后,主程序直接退出了。
发表于 2015-6-11 22:10:53 | 显示全部楼层
回复 7# dnvplj

自己尝试调试吧. 比如这样查看路径是否正确.
        For $i = 1 To $N
                ConsoleWrite($i & @TAB & $aSoft[$i][0] & @CRLF)
                If $aChecked[$i] And FileExists(@ScriptDir & "" & $aSoft[$i][1]) Then
                        MsgBox(0, 'path', @ScriptDir & "" & $aSoft[$i][1]))
                        RunWait(@ScriptDir & "" & $aSoft[$i][1])
                EndIf
        Next
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-9-28 18:20 , Processed in 0.107414 second(s), 29 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表