找回密码
 加入
搜索
查看: 16339|回复: 26

[AU3基础] [已解决]8个复选框如何全选和反选

 火.. [复制链接]
发表于 2014-9-27 09:26:15 | 显示全部楼层 |阅读模式
本帖最后由 dnvplj 于 2014-10-7 21:04 编辑

请问各位朋友:如何点“全选”8个复选框全部选中,并按“安装”后按1-8的顺序或按所选进行软件安装,按"全不选"取消全部。
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=c:\documents and settings\administrator\桌面\form_softinstall.kxf
$Form_SoftInstall = GUICreate("Soft_Name", 552, 393, 193, 131)
GUISetBkColor(0xC0C0C0)
$Pic1 = GUICtrlCreatePic("C:\WINDOWS\Web\Wallpaper\bliss.jpg", 0, 0, 551, 92)
$Group_ChooseSoft = GUICtrlCreateGroup("  选择软件:  ", 8, 96, 537, 245, -1, $WS_EX_TRANSPARENT)
$Checkbox1 = GUICtrlCreateCheckbox("软件1", 64, 136, 193, 33)
$Checkbox2 = GUICtrlCreateCheckbox("软件2", 64, 193, 193, 33)
$Checkbox3 = GUICtrlCreateCheckbox("软件3", 64, 243, 193, 33)
$Checkbox4 = GUICtrlCreateCheckbox("软件4", 64, 308, 193, 17)
$Checkbox5 = GUICtrlCreateCheckbox("软件5", 336, 144, 193, 17)
$Checkbox6 = GUICtrlCreateCheckbox("软件6", 336, 199, 193, 17)
$Checkbox7 = GUICtrlCreateCheckbox("软件7", 336, 253, 193, 17)
$Checkbox8 = GUICtrlCreateCheckbox("软件8", 336, 308, 193, 17)
$Icon2 = GUICtrlCreateIcon("", -1, 24, 195, 25, 25)
$Icon1 = GUICtrlCreateIcon("", -1, 24, 140, 25, 25)
$Icon3 = GUICtrlCreateIcon("", -1, 24, 249, 25, 25)
$Icon4 = GUICtrlCreateIcon("", -1, 24, 304, 25, 25)
$Icon5 = GUICtrlCreateIcon("", -1, 296, 140, 25, 25)
$Icon6 = GUICtrlCreateIcon("", -1, 296, 195, 25, 25)
$Icon7 = GUICtrlCreateIcon("", -1, 296, 249, 25, 25)
$Icon8 = GUICtrlCreateIcon("", -1, 296, 304, 25, 25)

GUICtrlCreateGroup("", -99, -99, 1, 1)
$Button1 = GUICtrlCreateButton("安装", 352, 360, 75, 25)
$Button2 = GUICtrlCreateButton("退   出", 440, 360, 75, 25)
$Radio1 = GUICtrlCreateRadio("全选", 216, 364, 57, 17)
$Radio2 = GUICtrlCreateRadio("全不选", 280, 364, 65, 17)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        Exit

        EndSwitch
WEnd
发表于 2014-9-27 10:49:37 | 显示全部楼层
用 _WinAPI_EnumChildWindows得到子窗口句柄和类名
把类名为button的过滤出来
把button的风格为checkbox($BS_AUTOCHECKBOX)的过滤出来
发消息改变其状态


#Include <Constants.au3 >
#Include <WinAPI.au3>
#Include <WinAPIEx.au3>

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=c:\documents and settings\administrator\桌面\form_softinstall.kxf
$Form_SoftInstall = GUICreate("Soft_Name", 552, 393, 193, 131)
GUISetBkColor(0xC0C0C0)
$Pic1 = GUICtrlCreatePic("C:\WINDOWS\Web\Wallpaper\bliss.jpg", 0, 0, 551, 92)
$Group_ChooseSoft = GUICtrlCreateGroup("  选择软件:  ", 8, 96, 537, 245, -1, $WS_EX_TRANSPARENT)
$Checkbox1 = GUICtrlCreateCheckbox("软件1", 64, 136, 193, 33)
$Checkbox2 = GUICtrlCreateCheckbox("软件2", 64, 193, 193, 33)
$Checkbox3 = GUICtrlCreateCheckbox("软件3", 64, 243, 193, 33)
$Checkbox4 = GUICtrlCreateCheckbox("软件4", 64, 308, 193, 17)
$Checkbox5 = GUICtrlCreateCheckbox("软件5", 336, 144, 193, 17)
$Checkbox6 = GUICtrlCreateCheckbox("软件6", 336, 199, 193, 17)
$Checkbox7 = GUICtrlCreateCheckbox("软件7", 336, 253, 193, 17)
$Checkbox8 = GUICtrlCreateCheckbox("软件8", 336, 308, 193, 17)
$Icon2 = GUICtrlCreateIcon("", -1, 24, 195, 25, 25)
$Icon1 = GUICtrlCreateIcon("", -1, 24, 140, 25, 25)
$Icon3 = GUICtrlCreateIcon("", -1, 24, 249, 25, 25)
$Icon4 = GUICtrlCreateIcon("", -1, 24, 304, 25, 25)
$Icon5 = GUICtrlCreateIcon("", -1, 296, 140, 25, 25)
$Icon6 = GUICtrlCreateIcon("", -1, 296, 195, 25, 25)
$Icon7 = GUICtrlCreateIcon("", -1, 296, 249, 25, 25)
$Icon8 = GUICtrlCreateIcon("", -1, 296, 304, 25, 25)

GUICtrlCreateGroup("", -99, -99, 1, 1)
$Button1 = GUICtrlCreateButton("安装", 352, 360, 75, 25)
$Button2 = GUICtrlCreateButton("退   出", 440, 360, 75, 25)
$Radio1 = GUICtrlCreateRadio("全选", 216, 364, 57, 17)
$Radio2 = GUICtrlCreateRadio("全不选", 280, 364, 65, 17)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        Exit
                Case $Radio1
                        SetAllCheckBox(True)
                Case $Radio2
                        SetAllCheckBox(False)
        EndSwitch
WEnd
        
Func SetAllCheckBox($status)
        $childWndArray = _WinAPI_EnumChildWindows($Form_SoftInstall)
        If IsArray($childWndArray) Then
                If $status Then
                        For $i=1 To $childWndArray[0][0]
                                If $childWndArray[$i][1] = "Button" Then
                                        $btnStyle = _WinAPI_GetWindowLong($childWndArray[$i][0], $GWL_STYLE)
                                        If BitAND($btnStyle, $BS_AUTOCHECKBOX) = $BS_AUTOCHECKBOX Then
                                                _SendMessage($childWndArray[$i][0], $BM_SETCHECK, $BST_CHECKED)
                                        EndIf
                                EndIf
                        Next
                Else
                        For $i=1 To $childWndArray[0][0]
                                If $childWndArray[$i][1] = "Button" Then
                                        $btnStyle = _WinAPI_GetWindowLong($childWndArray[$i][0], $GWL_STYLE)
                                        If BitAND($btnStyle, $BS_AUTOCHECKBOX) = $BS_AUTOCHECKBOX Then
                                                _SendMessage($childWndArray[$i][0], $BM_SETCHECK, $BST_UNCHECKED)
                                        EndIf
                                EndIf
                        Next
                EndIf
        EndIf
EndFunc

本帖子中包含更多资源

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

×
发表于 2014-9-27 10:56:17 | 显示全部楼层
剩下点活你自己搞定吧
 楼主| 发表于 2014-9-27 11:01:07 | 显示全部楼层
回复 3# veket_linux
感谢veket_linux朋友的指教,大问题解决了,小问题我在研究。
 楼主| 发表于 2014-9-27 13:32:02 | 显示全部楼层
按“安装”后按1-8的顺序或按所选进行软件安装,不会了,那个朋友在帮下,多谢了。
发表于 2014-9-27 13:39:10 | 显示全部楼层
学习了,谢谢。
发表于 2014-9-27 17:57:27 | 显示全部楼层
回复 5# dnvplj
读取控件名称,建一个数组 for $i= 0 to 7一个一个运行就行了
 楼主| 发表于 2014-9-27 18:37:44 | 显示全部楼层
回复 7# netegg
感谢元老的回复,看了一下午的帮助了,还是看不懂,还请元老帮助解决为盼,多谢了。
发表于 2014-9-27 18:47:46 | 显示全部楼层
本帖最后由 netegg 于 2014-9-27 18:52 编辑

case button1

  if bitand(guictrlread($chcckbox1),$gui_checked) then do1
if  bitand(guictrlread($chcckbox2),$gui_checked) then do2
.....
发表于 2014-9-27 19:17:14 | 显示全部楼层
本帖最后由 dunphy 于 2014-9-27 19:21 编辑

回复 2# veket_linux


亲,善用搜索。来就提示你...
你们A版早就整出来了。看这贴

http://www.autoitx.com/forum.php ... heckbox%B2%D9%D7%F7

而且我还在自定义函数区故意把这贴特拿出来举例‘’

http://www.autoitx.com/forum.php?mod=viewthread&tid=45048
发表于 2014-9-28 00:07:08 | 显示全部楼层
回复 2# veket_linux


    亲,你的代码中和色彩是咱格弄出来的呢???
发表于 2014-9-28 08:35:34 | 显示全部楼层
回复 11# dunphy

亲 代码用
  your code 
括起来 a大的帖子自然是拜读过滴,
只不过很久了........ 干脆自己也写个
发表于 2014-9-28 08:36:34 | 显示全部楼层
前方括号   au  后放括号
代码
前方括号   /au  后放括号
发表于 2014-9-28 12:20:52 | 显示全部楼层
本帖最后由 dunphy 于 2014-9-28 12:23 编辑

已经搞明白了。在高级编辑贴子的地方,有个A2的图标,点一下,把代码弄在里面就行了。
 楼主| 发表于 2014-9-29 08:05:50 | 显示全部楼层
本帖最后由 dnvplj 于 2014-9-29 08:12 编辑

回复 2# veket_linux
朋友您好:请问,窗体上的“软件1至软件8”和“IOC图标”如何从配置文件中读取,位置不变,多谢了。
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-6-20 23:06 , Processed in 0.081795 second(s), 24 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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