# 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 "Extras\HelpFileInternals.au3"
    #include "Extras\WM_NOTIFY.au3"

    #include <GuiButton.au3>
    #include <GUIConstantsEx.au3>
    #include <StructureConstants.au3>
    #include <WindowsNotifsConstants.au3>
    #include <WindowsStylesConstants.au3>

    Global $g_hBtn, $g_hRdo, $g_hChk

    ; Note: The handle from these buttons can NOT be read with GUICtrlRead

    Example()

    Func Example()
        Local $hGUI = GUICreate("Button Create (v" & @AutoItVersion & ")", 400, 400)
        _MemoCreate(119, 10, 276, 374, $WS_VSCROLL)

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

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

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

        GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")
        _WM_NOTIFY_Register($_g_idLst_Memo)

        GUISetState(@SW_SHOW)

        _MemoWrite("$g_hBtn handle: " & $g_hBtn)
        _MemoWrite("$g_hRdo handle: " & $g_hRdo)
        _MemoWrite("$g_hChk handle: " & $g_hChk & @CRLF)

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

        Exit
    EndFunc   ;==>Example

    Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam)
        #forceref $hWnd, $iMsg, $wParam
        Local Const $BCN_HOTITEMCHANGE = -1249
        Local $tagNMBHOTITEM = $tagNMHDR & ";dword dwFlags"
        Local $tNMBHOTITEM = DllStructCreate($tagNMBHOTITEM, $lParam)
        Local $iCode = DllStructGetData($tNMBHOTITEM, "Code")
        Local $hWndFrom = DllStructGetData($tNMBHOTITEM, "hWndFrom")
        Local $iFlags = DllStructGetData($tNMBHOTITEM, "dwFlags")
        Local $sText = ""

        Switch $iCode
            Case $BCN_HOTITEMCHANGE ; Win XP and Above
                $sText = "Text=" & _GUICtrlButton_GetText($hWndFrom)
                If BitAND($iFlags, 0x10) = 0x10 Then
                    _WM_NOTIFY_DebugEvent("$BCN_HOTITEMCHANGE - Entering", $tagNMBHOTITEM, $lParam, "IDFrom", $sText)
                ElseIf BitAND($iFlags, 0x20) = 0x20 Then
                    _WM_NOTIFY_DebugEvent("$BCN_HOTITEMCHANGE - Leaving", $tagNMBHOTITEM, $lParam, "IDFrom", $sText)
                EndIf
        EndSwitch
        Return $GUI_RUNDEFMSG
    EndFunc   ;==>WM_NOTIFY

    ; React on a button click
    Func WM_COMMAND($hWnd, $iMsg, $wParam, $lParam)
        #forceref $hWnd, $iMsg
        Local $iCode = BitShift($wParam, 16)
        Local $hCtrl = $lParam
        Local $sCode, $sText

        Switch $hCtrl
            Case $g_hBtn, $g_hRdo, $g_hChk
                Switch $iCode
                    Case $BN_CLICKED
                        $sCode = "$BN_CLICKED"
                    Case $BN_PAINT
                        $sCode = "$BN_PAINT"
                    Case $BN_PUSHED
                        $sCode = "$BN_PUSHED"
                    Case $BN_HILITE
                        $sCode = "$BN_HILITE"
                    Case $BN_UNPUSHED
                        $sCode = "$BN_UNPUSHED"
                    Case $BN_UNHILITE
                        $sCode = "$BN_UNHILITE"
                    Case $BN_DISABLE
                        $sCode = "$BN_DISABLE"
                    Case $BN_DBLCLK
                        $sCode = "$BN_DBLCLK"
                    Case $BN_DOUBLECLICKED
                        $sCode = "$BN_DOUBLECLICKED"
                    Case $BN_SETFOCUS
                        $sCode = "$BN_SETFOCUS"
                    Case $BN_KILLFOCUS
                        $sCode = "$BN_KILLFOCUS"
                EndSwitch
                $sText = "Text=" & _GUICtrlButton_GetText($hCtrl)
                _WM_NOTIFY_DebugEvent($sCode, $tagNMHDR, $lParam, "IDFrom", $sText)
                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