使此后所有被创建的控件都归为一组。
GUIStartGroup ( [窗口句柄] )
参数
| 窗口句柄 | [可选参数] 窗口句柄,可由 GUICreate 的返回值获得(若缺省则使用上一次用过的句柄)。 |
返回值
| 成功: | 返回值为1。 |
| 失败: | 返回值为0。 |
注意
本函数一般用于单选按钮控件。当用户点击某个单选按钮时其它所有在同一组的单选按钮将被重设。GUIStartGroup 函数使得我们能够轻松地定义控件组。
相关
GUICtrlCreateGroup
示例
#include <GUIconstants.au3>
Opt("GUICoordMode", 1)
GUICreate("单选按钮归组演示", 400,280)
; 创建控件
$button_1 = GUICtrlCreateButton ("B&utton 1", 30, 20, 120, 40)
$group_1 = GUICtrlCreateGroup ("Group 1", 30, 90, 165, 160)
GUIStartGroup()
$radio_1 = GUICtrlCreateRadio ("Radio &0", 50, 120, 70, 20)
$radio_2 = GUICtrlCreateRadio ("Radio &1", 50, 150, 60, 20)
$radio_3 = GUICtrlCreateRadio ("Radio &2", 50, 180, 60, 20)
GUIStartGroup()
$radio_4 = GUICtrlCreateRadio ("Radio &A", 120, 120, 70, 20)
$radio_5 = GUICtrlCreateRadio ("Radio &B", 120, 150, 60, 20)
$radio_6 = GUICtrlCreateRadio ("Radio &C", 120, 180, 60, 20)
GUIStartGroup()
$input_1 = GUICtrlCreateInput ("Input 1", 200, 20, 160, 30)
$input_2 = GUICtrlCreateInput ("Input 2", 200, 70, 160, 30)
; 设置默认项目(定义默认选中的单选按钮、默认按钮,等等)
GUICtrlSetState($radio_1, $GUI_CHECKED)
GUICtrlSetState($radio_6, $GUI_CHECKED)
GUICtrlSetState($button_1, $GUI_FOCUS + $GUI_DEFBUTTON)
; 初始化变量,用于跟踪 GUI 事件
$radioval1 = 0 ; 我们假定 0 = 第一个单选按钮被选中,2 = 最后一个单选按钮被选中
$radioval2 = 2
GUISetState ()
; 在下面这个消息循环中我们使用了变量来跟踪单选按钮的变化,
; 也有其它方法,比如使用 GUICtrlRead() 来读取每个控件的状态,
; 这两种方法都是可行的
While 1
$msg = GUIGetMsg()
Select
Case $msg = $GUI_EVENT_CLOSE
Exit
Case $msg = $button_1
MsgBox(0, "Button", "Radio " & $radioval1 & @LF & "Radio " & Chr($radioval2 + Asc("A")) & @LF & GUICtrlRead($input_1) & @LF & GUICtrlRead($input_2))
Case $msg = $radio_1 OR $msg = $radio_2 OR $msg = $radio_3
$radioval1 = $msg - $radio_1
Case $msg = $radio_4 OR $msg = $radio_5 OR $msg = $radio_6
$radioval2 = $msg - $radio_4
EndSelect
WEnd