找回密码
 加入
搜索
查看: 5691|回复: 13

[AU3基础] (已解决)GUICtrlCreateCheckbox判断勾选的问题

  [复制链接]
发表于 2010-8-9 10:05:21 | 显示全部楼层 |阅读模式
本帖最后由 xargw 于 2010-8-10 10:36 编辑

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 623, 449, 192, 114)
$Checkbox1 = GUICtrlCreateCheckbox("Checkbox1", 104, 48, 97, 17)
$Button1 = GUICtrlCreateButton("Button1", 112, 104, 75, 25)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

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

        EndSwitch

我想让程序实现,如果GUICtrlCreateCheckbox选中,点按钮提示,已选中,否则提示未选中,这个要怎么判断
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 623, 449, 192, 114)
$Checkbox1 = GUICtrlCreateCheckbox("Checkbox1", 104, 48, 97, 17)
$Button1 = GUICtrlCreateButton("Button1", 112, 104, 75, 25)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        Exit
                                Case $Checkbox1
                                        GUICtrlSetState(-1, $GUI_CHECKED)
                If GUICtrlRead($Checkbox1)=$$GUI_CHECKED Then
                Case $Form1
                Case $Button1
                                msgbox((,0),"提示","已选中")
                                Else
                           MsgBox(",0","提示","未选中")
                               endif

        EndSwitch
WEnd

评分

参与人数 1金钱 +10 收起 理由
afan + 10 感谢主动将修改帖子分类为[已解决],请继续 ...

查看全部评分

发表于 2010-8-9 10:16:25 | 显示全部楼层
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 623, 449, 192, 114)
$Checkbox1 = GUICtrlCreateCheckbox("Checkbox1", 104, 48, 97, 17)
$Button1 = GUICtrlCreateButton("Button1", 112, 104, 75, 25)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        Exit
                Case $Button1
                        If GUICtrlRead($Checkbox1) = $GUI_CHECKED Then
                                MsgBox(4096, "提示", "已选中")
                        Else
                                MsgBox(4096, "提示", "未选中")
                        EndIf
        EndSwitch
WEnd

评分

参与人数 1金钱 +20 收起 理由
afan + 20

查看全部评分

发表于 2010-8-9 10:21:00 | 显示全部楼层
本帖最后由 水木子 于 2010-8-9 10:22 编辑

回复 2# 破帽遮颜
呵呵!撞车啦!
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

GUICreate("Form1", 600, 450)
$Checkbox1 = GUICtrlCreateCheckbox("Checkbox1", 100, 50, 100, 17)
$Button1 = GUICtrlCreateButton("Button1", 100, 100, 75, 25)
GUISetState()

While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case - 3
                        Exit
                Case $Checkbox1

                Case $Button1
                        If BitAND(GUICtrlRead($Checkbox1), $GUI_CHECKED) Then
                                MsgBox(0, '', '已勾选')
                        Else
                                MsgBox(0, '', '未勾选')
                        EndIf
        EndSwitch
WEnd

评分

参与人数 1金钱 +20 收起 理由
afan + 20

查看全部评分

 楼主| 发表于 2010-8-9 18:09:40 | 显示全部楼层
谢谢,可以用
 楼主| 发表于 2010-8-9 18:17:30 | 显示全部楼层
If GUICtrlRead($Checkbox1) = $GUI_CHECKED Then
If BitAND(GUICtrlRead($Checkbox1), $GUI_CHECKED) Then
各位能解释一下么?
 楼主| 发表于 2010-8-9 18:18:44 | 显示全部楼层
If GUICtrlRead($Checkbox1) = $GUI_CHECKED Then
guictrlread读取$gui_checked有值表示选中,没值表示没选中,是这个意思么?
发表于 2010-8-9 18:22:38 | 显示全部楼层
都有值,=1为选中;=4为未选中
 楼主| 发表于 2010-8-9 18:39:10 | 显示全部楼层
If GUICtrlRead($Checkbox1) = $GUI_CHECKED then
这句怎么理解是=1呢
发表于 2010-8-9 18:39:34 | 显示全部楼层
你可以去看看 GUICtrlSetState 这个函数,下面有控件状态表!
看完你就知道是怎么回事了。
发表于 2010-8-9 18:40:44 | 显示全部楼层
$GUI_CHECKED 是个常量,值为1
发表于 2015-6-21 18:31:33 | 显示全部楼层
回复 2# 破帽遮颜
朋友您好,如果是12个复选框,如何判断:选中还是没有选中?
发表于 2015-6-21 20:31:51 | 显示全部楼层
回复 11# dnvplj

每个控件分配一个变量,通过查询GUICtrlRead(变量)是否等于1判断选中否。
发表于 2015-6-21 20:49:52 | 显示全部楼层
回复 12# 破帽遮颜
能否结合2楼的代码,给个范例,小弟对此还不是很熟悉,谢谢指教。
发表于 2016-2-6 11:26:59 | 显示全部楼层
我有个类似的问题,在这里,帮忙看一下
http://www.autoitx.com/forum.php ... id=51448&extra=
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-9-29 02:13 , Processed in 0.097279 second(s), 25 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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