创建一个按钮控件
#Include <GuiButton.au3>
_GUICtrlButton_Create($hWnd, $sText, $iX, $iY, $iWidth, $iHeight[, $iStyle = -1[, $iExStyle = -1]])
$hWnd | 父窗口或所有者窗口的句柄 |
$sText | 按钮文本 |
$iX | 水平位置 |
$iY | 垂直位置 |
$iWidth | 宽度 |
$iHeight | 高度 |
$iStyle | [可选参数] 控件样式: $BS_AUTO3STATE - 创建三态复选框,当用户选择复选框,其状态在选中、不可用、移除选中 3 状态中循环. $BS_AUTOCHECKBOX - 创建一个复选框,当用户选择复选框,其状态在选中和移除选中之间切换. $BS_AUTORADIOBUTTON - 相当于单选按钮,被选择时,按钮自动高亮显示,并移除同组中其它同等样式按钮的选中状态. $BS_FLAT - 二维按钮; 不使用默认明暗处理产生 3D 图像. $BS_GROUPBOX - 创建一个矩形,其他按钮可以在其中进行分组,矩形左上角显示按钮文本. $BS_PUSHLIKE - 生成的按钮 (如复选框, 三状态复选框, 或单选按钮)外表与动作类似按钮开关,当其不忙碌或未选中时,呈凸起状态;反之则呈凹下状态.(译注:反复推敲原文才如此翻译,但实际上却不知如何实现这个效果) [可选参数] $BS_DEFPUSHBUTTON - 创建一个重黑色边框按钮. 如果按钮在对话框中, 即使按钮不具有输入焦点, 用户也可以通过按 Enter 键选中它.对于用户的快速选择或设置默认状态,这个样式是非常有用的. [可选参数] $BS_BOTTOM - 文本在按钮底部. $BS_CENTER - 文本在按钮内水平居中. $BS_LEFT - 左对齐按钮文本. $BS_MULTILINE - 超长文本自动换行. $BS_RIGHT - 右对齐按钮文本. $BS_RIGHTBUTTON - 复选按钮的勾选方块定位到按钮矩形区右侧. $BS_TOP - 文本在按钮顶部. $BS_VCENTER - 文本在按钮矩形的垂直中心. [可选参数] $BS_ICON - 按钮显示 ico 图标. $BS_BITMAP - 按钮显示 bmp 位图. [可选参数] $BS_NOTIFY - 允许按钮发送 BN_KILLFOCUS 与 BN_SETFOCUS 通知消息到它的父窗口. 注意不论按钮是否有这个样式,都能发送 the BN_CLICKED 通知消息. 要获取 BN_DBLCLK 通知消息, 按钮必须有 BS_RADIOBUTTON 或 BS_OWNERDRAW 样式. [可选参数] Vista 样式: $BS_SPLITBUTTON - 有拆分标志 " l " 的按钮, 配合一个下拉菜单箭头 $BS_DEFSPLITBUTTON - 类似 $BS_PUSHBUTTON 样式的色边框(初始启动时)按钮, 也有拆分标志 " l ", 配合一个下拉菜单箭头. $BS_COMMANDLINK - 创建命令链接按钮 $BS_DEFCOMMANDLINK - 创建命令链接按钮, 类似 $BS_PUSHBUTTON 样式. [可选参数] 默认 : ( -1) : 无 强制 : $WS_CHILD, $WS_TABSTOP, $WS_VISIBLE, $BS_NOTIFY |
$iExStyle | [可选参数] 控件扩展样式. 对应于标准 $WS_EX_ 常量. |
成功: | 返回按钮控件句柄 |
失败: | 返回 0 |
#include <GUIConstantsEx.au3>
#include <GuiButton.au3>
#include <WindowsConstants.au3>
Global $btn, $rdo, $chk, $iMemo
; Note the controlId from these buttons can NOT be read with GuiCtrlRead
_Main()
Func _Main()
Local $hGUI
$hGUI = GUICreate("Buttons", 400, 400)
$iMemo = GUICtrlCreateEdit("", 119, 10, 276, 374, $WS_VSCROLL)
GUICtrlSetFont($iMemo, 9, 400, 0, "Courier New")
$btn = _GUICtrlButton_Create($hGUI, "Button1", 10, 10, 90, 50)
$rdo = _GUICtrlButton_Create($hGUI, "Radio1", 10, 60, 90, 50, $BS_AUTORADIOBUTTON)
$chk = _GUICtrlButton_Create($hGUI, "Check1", 10, 120, 90, 50, $BS_AUTO3STATE)
GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
GUISetState()
MemoWrite("$btn handle: " & $btn)
MemoWrite("$rdo handle: " & $rdo)
MemoWrite("$chk handle: " & $chk & @CRLF)
While 1
Switch GUIGetMsg()
Case $GUI_EVENT_CLOSE
ExitLoop
EndSwitch
WEnd
Exit
EndFunc ;==>_Main
; 写入一行到 memo 控件
Func MemoWrite($sMessage)
GUICtrlSetData($iMemo, $sMessage & @CRLF, 1)
EndFunc ;==>MemoWrite
Func WM_NOTIFY($hWnd, $Msg, $wParam, $lParam)
#forceref $hWnd, $Msg, $wParam
Local Const $BCN_HOTITEMCHANGE = -1249
Local $tNMBHOTITEM = DllStructCreate("hwnd hWndFrom;int IDFrom;int Code;dword dwFlags", $lParam)
Local $nNotifyCode = DllStructGetData($tNMBHOTITEM, "Code")
Local $nID = DllStructGetData($tNMBHOTITEM, "IDFrom")
Local $hCtrl = DllStructGetData($tNMBHOTITEM, "hWndFrom")
Local $dwFlags = DllStructGetData($tNMBHOTITEM, "dwFlags")
Local $sText = ""
Switch $nNotifyCode
Case $BCN_HOTITEMCHANGE ; Win XP and Above
If BitAND($dwFlags, 0x10) = 0x10 Then
$sText = "$BCN_HOTITEMCHANGE - Entering: " & @CRLF
ElseIf BitAND($dwFlags, 0x20) = 0x20 Then
$sText = "$BCN_HOTITEMCHANGE - Leaving: " & @CRLF
EndIf
MemoWrite($sText & _
"-----------------------------" & @CRLF & _
"WM_NOTIFY - Infos:" & @CRLF & _
"-----------------------------" & @CRLF & _
"Code" & @TAB & ":" & $nNotifyCode & @CRLF & _
"CtrlID" & @TAB & ":" & $nID & @CRLF & _
"CtrlHWnd:" & $hCtrl & @CRLF & _
_GUICtrlButton_GetText($hCtrl) & @CRLF)
EndSwitch
Return $GUI_RUNDEFMSG
EndFunc ;==>WM_NOTIFY
; React on a button click
Func WM_COMMAND($hWnd, $Msg, $wParam, $lParam)
#forceref $hWnd, $Msg
Local $nNotifyCode = BitShift($wParam, 16)
Local $nID = BitAND($wParam, 0x0000FFFF)
Local $hCtrl = $lParam
Local $sText = ""
Switch $hCtrl
Case $btn, $rdo, $chk
Switch $nNotifyCode
Case $BN_CLICKED
$sText = "$BN_CLICKED" & @CRLF
Case $BN_PAINT
$sText = "$BN_PAINT" & @CRLF
Case $BN_PUSHED, $BN_HILITE
$sText = "$BN_PUSHED, $BN_HILITE" & @CRLF
Case $BN_UNPUSHED, $BN_UNHILITE
$sText = "$BN_UNPUSHED" & @CRLF
Case $BN_DISABLE
$sText = "$BN_DISABLE" & @CRLF
Case $BN_DBLCLK, $BN_DOUBLECLICKED
$sText = "$BN_DBLCLK, $BN_DOUBLECLICKED" & @CRLF
Case $BN_SETFOCUS
$sText = "$BN_SETFOCUS" & @CRLF
Case $BN_KILLFOCUS
$sText = "$BN_KILLFOCUS" & @CRLF
EndSwitch
MemoWrite($sText & _
"-----------------------------" & @CRLF & _
"WM_COMMAND - Infos:" & @CRLF & _
"-----------------------------" & @CRLF & _
"Code" & @TAB & ":" & $nNotifyCode & @CRLF & _
"CtrlID" & @TAB & ":" & $nID & @CRLF & _
"CtrlHWnd:" & $hCtrl & @CRLF & _
_GUICtrlButton_GetText($hCtrl) & @CRLF)
Return 0 ; Only workout clicking on the button
EndSwitch
; Proceed the default AutoIt3 internal message commands.
; You also can complete let the line out.
; !!! But only 'Return' (without any value) will not proceed
; the default AutoIt3-message in the future !!!
Return $GUI_RUNDEFMSG
EndFunc ;==>WM_COMMAND