找回密码
 加入
搜索
查看: 10586|回复: 16

[GUI管理] 能否有办法侦测到Group组内的复选框的个数等信息?

 火.. [复制链接]
发表于 2012-12-4 21:03:12 | 显示全部楼层 |阅读模式
能否有办法侦测到Group组内的复选框的个数等信息?
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 397, 170, 198, 191)
$Group1 = GUICtrlCreateGroup("Group1", 88, 24, 185, 105)
$Checkbox1 = GUICtrlCreateCheckbox("Checkbox1", 104, 48, 97, 17)
$Checkbox2 = GUICtrlCreateCheckbox("Checkbox2", 104, 80, 97, 17)
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

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

        EndSwitch
WEnd
发表于 2012-12-4 21:08:24 | 显示全部楼层
lz要先搞明白,group不是个实际控件,不是只有checkbox在里面的
 楼主| 发表于 2012-12-4 21:16:31 | 显示全部楼层
怪不得没有任何拓展函数!
发表于 2012-12-4 21:24:56 | 显示全部楼层
自建的东西还要侦测吗?
发表于 2012-12-4 21:32:07 | 显示全部楼层
真想弄倒是也行
#Include <WinAPIEx.au3>
_WinAPI_EnumChildWindows
获取界面上所有子窗体,检查类名为checkbox的项目,获取各控件的坐标,和group对比
发表于 2012-12-4 22:12:55 | 显示全部楼层
回复 5# netegg

对比坐标是个不错的想法,不过可惜的是,Checkbox的控件类是Button~~

估计楼主是闲得蛋疼了~~
发表于 2012-12-4 23:10:57 | 显示全部楼层
回复 6# 轩辕小妖
这个倒是也不难做,button的状态值是1和0(未按下,默认),checkbox的状态值是4(未选中,默认)和1
 楼主| 发表于 2012-12-5 12:24:14 | 显示全部楼层
回复 5# netegg
多谢了,自己先查下资料学习下!
发表于 2012-12-5 14:10:25 | 显示全部楼层
本帖最后由 netegg 于 2012-12-5 14:39 编辑

[au3]#include <Array.au3>
#include <WinAPIEx.au3>
#include <GUIConstantsEx.au3>


Opt('MustDeclareVars', 1)

Global $hForm, $Data

$hForm = GUICreate('MyGUI', 310, 360)
GUISetFont(8.5, 400, 0, 'MS Shell Dlg', $hForm)
GUICtrlCreateGroup('Group', 10, 10, 140, 95)
GUICtrlCreateCheckbox('Check1', 22, 26, 120, 23)
GUICtrlCreateCheckbox('Check2', 22, 49, 120, 23)
GUICtrlCreateCheckbox('Check3', 22, 72, 120, 23)
GUICtrlCreateGroup('Group', 160, 10, 140, 95)
GUICtrlCreateRadio('Radio1', 172, 26, 120, 23)
GUICtrlCreateRadio('Radio2', 172, 49, 120, 23)
GUICtrlCreateRadio('Radio3', 172, 72, 120, 23)
GUICtrlCreateButton('OK', 120, 330, 70, 23)
GUICtrlCreateTab(10, 118, 292, 206)
GUICtrlCreateTabItem('Tab1')
GUICtrlCreateTabItem('Tab2')
GUICtrlCreateTabItem('')
GUISetState()

$Data = _WinAPI_EnumChildWindows($hForm)
Dim $aA[UBound($Data) - 1][3]
Local $j = 1
For $i = 1 To $Data[0][0]
        If $Data[$i][1] = 'button' Then
                $aA[$j - 1][0] = $Data[$i][0]
                $aA[$j - 1][1] = _WinAPI_GetWindowLong($Data[$i][0], $GWL_ID)
                $aA[$j - 1][2] = GUICtrlRead($aA[$j - 1][1])
                If IsNumber(GUICtrlRead($aA[$j - 1][1])) And GUICtrlSetState($aA[$j - 1][1], 2) Then
                        If BitAND(GUICtrlRead($aA[$j - 1][1]), $GUI_CHECKED) Then
                                $j += 1
                                ReDim $aA[$j][3]
                        EndIf
                EndIf
        EndIf
Next
msgbox(0,0,'total number of checkboxes: ' & $j-1)

Do
Until GUIGetMsg() = -3

[/au3]有个问题,改变状态了,如果不分单选和复选的话倒是没什么问题
发表于 2012-12-5 14:42:23 | 显示全部楼层
回复 9# netegg


    蛋蛋还真是蛋疼不已……
#include <Array.au3>
#include <WinAPIEx.au3>
#include <WindowsConstants.au3>
#include <ButtonConstants.au3>

$hForm = GUICreate('MyGUI', 310, 360)
GUISetFont(8.5, 400, 0, 'MS Shell Dlg', $hForm)
GUICtrlCreateGroup('Group', 10, 10, 140, 95)
GUICtrlCreateCheckbox('Check1', 22, 26, 120, 23)
GUICtrlCreateCheckbox('Check2', 22, 49, 120, 23)
GUICtrlCreateCheckbox('Check3', 22, 72, 120, 23)
GUICtrlCreateGroup('Group', 160, 10, 140, 95)
GUICtrlCreateRadio('Radio1', 172, 26, 120, 23)
GUICtrlCreateRadio('Radio2', 172, 49, 120, 23)
GUICtrlCreateRadio('Radio3', 172, 72, 120, 23)
GUICtrlCreateButton('OK', 120, 330, 70, 23)
GUICtrlCreateTab(10, 118, 292, 206)
GUICtrlCreateTabItem('Tab1')
GUICtrlCreateTabItem('Tab2')
GUICtrlCreateTabItem('')
GUISetState()

$Data = _WinAPI_EnumChildWindows($hForm)
Dim $aA[UBound($Data) - 1][2]
Local $j = 1
For $i = 1 To $Data[0][0]
        If $Data[$i][1] = 'button' Then
                $aA[$j - 1][0] = ControlGetText('', '', $Data[$i][0])
                $long = _WinAPI_GetWindowLong($Data[$i][0], 0xFFFFFFF0)
                If BitAND($long, $BS_AUTORADIOBUTTON) = $BS_AUTORADIOBUTTON Then
                        $aA[$j - 1][1] = '单选框'
                ElseIf BitAND($long, $WS_GROUP) = $WS_GROUP Then
                        $aA[$j - 1][1] = '分组框'
                ElseIf BitAND($long, $BS_AUTOCHECKBOX) = $BS_AUTOCHECKBOX Then
                        $aA[$j - 1][1] = '复选框'
                Else
                        $aA[$j - 1][1] = '按钮'
                EndIf
                $j += 1
        EndIf
Next
ReDim $aA[$j - 1][2]
_ArrayDisplay($aA, '_WinAPI_EnumChildWindows')

Do
Until GUIGetMsg() = -3
发表于 2012-12-5 14:46:39 | 显示全部楼层
本帖最后由 netegg 于 2012-12-5 14:51 编辑

$BS_AUTOCHECKBOX,$BS_AUTORADIOBUTTON这俩值是什么,倒是没想到
9和3,不错不错,赞了
发表于 2012-12-5 23:30:49 | 显示全部楼层
楼上两位高人都蛋疼了
 楼主| 发表于 2012-12-8 20:06:04 | 显示全部楼层
感谢蛋大,A大的回答!运行成功!还要仔细研究方能理解!
 楼主| 发表于 2012-12-8 20:07:02 | 显示全部楼层
回复 10# afan
有没有中间侦测的语句说明,谢谢了!
发表于 2012-12-8 20:41:42 | 显示全部楼层
回复 14# blue_dvd
什么意思?lz太邪门了,实时监控个数?
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-5-17 17:01 , Processed in 0.081163 second(s), 22 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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