blue_dvd 发表于 2012-12-4 21:03:12

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

能否有办法侦测到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

netegg 发表于 2012-12-4 21:08:24

lz要先搞明白,group不是个实际控件,不是只有checkbox在里面的

blue_dvd 发表于 2012-12-4 21:16:31

怪不得没有任何拓展函数!

afan 发表于 2012-12-4 21:24:56

自建的东西还要侦测吗?

netegg 发表于 2012-12-4 21:32:07

真想弄倒是也行
#Include <WinAPIEx.au3>
_WinAPI_EnumChildWindows
获取界面上所有子窗体,检查类名为checkbox的项目,获取各控件的坐标,和group对比

轩辕小妖 发表于 2012-12-4 22:12:55

回复 5# netegg

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

估计楼主是闲得蛋疼了~~

netegg 发表于 2012-12-4 23:10:57

回复 6# 轩辕小妖
这个倒是也不难做,button的状态值是1和0(未按下,默认),checkbox的状态值是4(未选中,默认)和1

blue_dvd 发表于 2012-12-5 12:24:14

回复 5# netegg
多谢了,自己先查下资料学习下!

netegg 发表于 2012-12-5 14:10:25

本帖最后由 netegg 于 2012-12-5 14:39 编辑

#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
Local $j = 1
For $i = 1 To $Data
        If $Data[$i] = 'button' Then
                $aA[$j - 1] = $Data[$i]
                $aA[$j - 1] = _WinAPI_GetWindowLong($Data[$i], $GWL_ID)
                $aA[$j - 1] = GUICtrlRead($aA[$j - 1])
                If IsNumber(GUICtrlRead($aA[$j - 1])) And GUICtrlSetState($aA[$j - 1], 2) Then
                        If BitAND(GUICtrlRead($aA[$j - 1]), $GUI_CHECKED) Then
                                $j += 1
                                ReDim $aA[$j]
                        EndIf
                EndIf
        EndIf
Next
msgbox(0,0,'total number of checkboxes: ' & $j-1)

Do
Until GUIGetMsg() = -3

有个问题,改变状态了,如果不分单选和复选的话倒是没什么问题

afan 发表于 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
Local $j = 1
For $i = 1 To $Data
        If $Data[$i] = 'button' Then
                $aA[$j - 1] = ControlGetText('', '', $Data[$i])
                $long = _WinAPI_GetWindowLong($Data[$i], 0xFFFFFFF0)
                If BitAND($long, $BS_AUTORADIOBUTTON) = $BS_AUTORADIOBUTTON Then
                        $aA[$j - 1] = '单选框'
                ElseIf BitAND($long, $WS_GROUP) = $WS_GROUP Then
                        $aA[$j - 1] = '分组框'
                ElseIf BitAND($long, $BS_AUTOCHECKBOX) = $BS_AUTOCHECKBOX Then
                        $aA[$j - 1] = '复选框'
                Else
                        $aA[$j - 1] = '按钮'
                EndIf
                $j += 1
        EndIf
Next
ReDim $aA[$j - 1]
_ArrayDisplay($aA, '_WinAPI_EnumChildWindows')

Do
Until GUIGetMsg() = -3

netegg 发表于 2012-12-5 14:46:39

本帖最后由 netegg 于 2012-12-5 14:51 编辑

$BS_AUTOCHECKBOX,$BS_AUTORADIOBUTTON这俩值是什么,倒是没想到
9和3,不错不错,赞了{:face (356):}

xms77 发表于 2012-12-5 23:30:49

楼上两位高人都蛋疼了{:face (303):}

blue_dvd 发表于 2012-12-8 20:06:04

感谢蛋大,A大的回答!运行成功!还要仔细研究方能理解!

blue_dvd 发表于 2012-12-8 20:07:02

回复 10# afan
有没有中间侦测的语句说明,谢谢了!

netegg 发表于 2012-12-8 20:41:42

回复 14# blue_dvd
什么意思?lz太邪门了,实时监控个数?
页: [1] 2
查看完整版本: 能否有办法侦测到Group组内的复选框的个数等信息?