Function Reference


_GUICtrlButton_Create

Creates a Button control

#include <GuiButton.au3>
_GUICtrlButton_Create ( $hWnd, $sText, $iX, $iY, $iWidth, $iHeight [, $iStyle = -1 [, $iExStyle = -1]] )

Parameters

$hWnd Handle to parent or owner window
$sText Text to add to Button
$iX Horizontal position of the control
$iY Vertical position of the control
$iWidth Control width
$iHeight Control height
$iStyle [optional] Control style:
    $BS_AUTO3STATE - Creates a three-state check box in which the state cycles through selected, unavailable, and cleared each time the user selects the check box.
    $BS_AUTOCHECKBOX - Creates a check box in which the check state switches between selected and cleared each time the user selects the check box.
    $BS_AUTORADIOBUTTON - Same as a radio button, except that when the user selects it, the button automatically highlights itself and removes the selection from any other radio buttons with the same style in the same group.
    $BS_FLAT - Specifies that the button is two-dimensional; it does not use the default shading to create a 3-D image.
    $BS_GROUPBOX - Creates a rectangle in which other buttons can be grouped. Any text associated with this style is displayed in the rectangle’s upper-left corner.
    $BS_PUSHLIKE - Makes a button (such as a check box, three-state check box, or radio button) look and act like a push button. The button looks raised when it isn't pushed or checked, and sunken when it is pushed or checked.

    $BS_DEFPUSHBUTTON - Creates a push button with a heavy black border. If the button is in a dialog box, the user can select the button by pressing the ENTER key, even when the button does not have the input focus. This style is useful for enabling the user to quickly select the most likely option, or default.

    $BS_BOTTOM - Places the text at the bottom of the button rectangle.
    $BS_CENTER - Centers the text horizontally in the button rectangle.
    $BS_LEFT - Left-aligns the text in the button rectangle on the right side of the check box.
    $BS_MULTILINE - Wraps the button text to multiple lines if the text string is too long to fit on a single line in the button rectangle.
    $BS_RIGHT - Right-aligns text in the button rectangle on the right side of the check box.
    $BS_RIGHTBUTTON - Positions a check box square on the right side of the button rectangle.
    $BS_TOP - Places text at the top of the button rectangle.
    $BS_VCENTER - Vertically centers text in the button rectangle.

    $BS_ICON - Specifies that the button displays an icon.
    $BS_BITMAP - Specifies that the button displays a bitmap.

    $BS_NOTIFY - Enables a button to send BN_KILLFOCUS and BN_SETFOCUS notification messages to its parent window. Note that buttons send the BN_CLICKED notification message regardless of whether it has this style. To get BN_DBLCLK notification messages, the button must have the BS_RADIOBUTTON or BS_OWNERDRAW style.

Vista Sytles:
    $BS_SPLITBUTTON - Creates a split button. A split button has a drop down arrow
    $BS_DEFSPLITBUTTON - Creates a split button that behaves like a $BS_PUSHBUTTON style button, but also has a distinctive appearance.
    $BS_COMMANDLINK - Creates a command link button
    $BS_DEFCOMMANDLINK - Creates a command link button that behaves like a $BS_PUSHBUTTON style button.

Default: ( -1) : none
Forced : $WS_CHILD, $WS_TABSTOP, $WS_VISIBLE, $BS_NOTIFY
$iExStyle [optional] Control extended style. These correspond to the standard $WS_EX_* constants. See Extended Style Table.

Return Value

Success: the handle to the Button control.
Failure: 0.

Remarks

Above constants require #include <ButtonConstants.au3>.

This function is for Advanced users and for learning how the control works.

Related

_GUICtrlButton_Destroy

Example

#include <GuiButton.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

Global $g_idBtn, $g_idRdo, $g_idChk, $g_idMemo

; Note the controlID from these buttons can NOT be read with GUICtrlRead

Example()

Func Example()
    Local $hGUI

    $hGUI = GUICreate("Buttons", 400, 400)
    $g_idMemo = GUICtrlCreateEdit("", 119, 10, 276, 374, $WS_VSCROLL)
    GUICtrlSetFont($g_idMemo, 9, 400, 0, "Courier New")

    $g_idBtn = _GUICtrlButton_Create($hGUI, "Button1", 10, 10, 90, 50)

    $g_idRdo = _GUICtrlButton_Create($hGUI, "Radio1", 10, 60, 90, 50, $BS_AUTORADIOBUTTON)

    $g_idChk = _GUICtrlButton_Create($hGUI, "Check1", 10, 120, 90, 50, $BS_AUTO3STATE)

    GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")
    GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")

    GUISetState(@SW_SHOW)

    MemoWrite("$g_idBtn handle: " & $g_idBtn)
    MemoWrite("$g_idRdo handle: " & $g_idRdo)
    MemoWrite("$g_idChk handle: " & $g_idChk & @CRLF)

    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ExitLoop
        EndSwitch
    WEnd

    Exit
EndFunc   ;==>Example

; Write a line to the memo control
Func MemoWrite($sMessage)
    GUICtrlSetData($g_idMemo, $sMessage & @CRLF, 1)
EndFunc   ;==>MemoWrite

Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam)
    #forceref $hWnd, $iMsg, $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 $iFlags = DllStructGetData($tNMBHOTITEM, "dwFlags")
    Local $sText = ""

    Switch $nNotifyCode
        Case $BCN_HOTITEMCHANGE ; Win XP and Above
            If BitAND($iFlags, 0x10) = 0x10 Then
                $sText = "$BCN_HOTITEMCHANGE - Entering: " & @CRLF

            ElseIf BitAND($iFlags, 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, $iMsg, $wParam, $lParam)
    #forceref $hWnd, $iMsg
    Local $nNotifyCode = BitShift($wParam, 16)
    Local $nID = BitAND($wParam, 0x0000FFFF)
    Local $hCtrl = $lParam
    Local $sText = ""

    Switch $hCtrl
        Case $g_idBtn, $g_idRdo, $g_idChk
            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