找回密码
 加入
搜索
查看: 3749|回复: 3

[GUI管理] [已解决]如何确定GUI内哪个单选按钮为选中状态?

[复制链接]
发表于 2013-10-20 20:32:59 | 显示全部楼层 |阅读模式
本帖最后由 ioripalm 于 2013-11-21 18:23 编辑

比如有个GUI内有100个单选按钮,每次只能选择一个,怎么快速确定哪个被选中了,不要一个一个的用_GUICtrlButton_GetCheck()来遍历,用什么方法可以直接得到被选中控件的句柄?
发表于 2013-10-20 22:19:08 | 显示全部楼层
本帖最后由 user3000 于 2013-10-20 23:30 编辑

回复 1# ioripalm
没看清,最终要获取的是控件句柄。重新编辑一下。

看示例吧。
Local $iRadio = 1, $aRadio[10], $id
Local $hGui, $nMsg
$hGui = GUICreate('test', 400, 80)
For $i = 0 To 9
        $aRadio[$i] = GUICtrlCreateRadio('R'&$i+1, $i*35+5, 20, 35)
Next
GUICtrlSetState($aRadio[0], 1);$GUI_CHECKED
$id = $aRadio[0]
$bt = GUICtrlCreateButton('查看', 200, 50)
GUISetState()
While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case -3
                        GUIDelete($hGui)
                        ExitLoop
                Case $aRadio[0] To $aRadio[9]
                    $iRadio = $nMsg - $aRadio[0] +1
                        $id = $nMsg ; $iRadio + 2 
                Case $bt
             MsgBox(0, '选中第' & $iRadio & '个单选', '该单选句柄:  ' & GUICtrlGetHandle($id))                
    EndSwitch
WEnd
发表于 2013-10-20 22:43:25 | 显示全部楼层
参考 帮助中 的GUIRegisterMsg 函数 写的
处理WM_COMMAND消息得到 被点击按钮的句柄  ,单程序启动 和 关闭 时出现的消息要想办法过滤掉
#Include <WinAPI.au3>

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 544, 381, 192, 114)
$Radio1 = GUICtrlCreateRadio("Radio1", 64, 40, 73, 25)
$Radio2 = GUICtrlCreateRadio("Radio2", 64, 96, 65, 17)
$Radio3 = GUICtrlCreateRadio("Radio3", 72, 144, 81, 25)
$Radio4 = GUICtrlCreateRadio("Radio4", 80, 200, 97, 41)
$Radio5 = GUICtrlCreateRadio("Radio5", 112, 272, 65, 33)

GUIRegisterMsg($WM_COMMAND, "MY_WM_COMMAND")

GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

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

        EndSwitch
WEnd

Func MY_WM_COMMAND($hWnd, $Msg, $wParam, $lParam)
        MsgBox(0, "", _WinAPI_GetWindowText($lParam))
EndFunc
 楼主| 发表于 2013-11-22 20:10:19 | 显示全部楼层
回复 3# veket_linux


    这个麻烦就是在开始还没选就出现消息了,然后关闭窗口又出现消息,
如果我的gui上面有不止radio等别的按钮,就按下别的按钮或者输入任何操作都导致显示消息。
要用if来判断显示又觉得很啰嗦。
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-5-17 17:29 , Processed in 0.075568 second(s), 24 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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