Function Reference


Create a Toolbar control

#include <GuiToolbar.au3>
_GUICtrlToolbar_Create ( $hWnd [, $iStyle = 0x00000800 [, $iExStyle = 0x00000000]] )


$hWnd Handle to parent or owner window
$iStyle [optional] Control styles:
    $TBSTYLE_ALTDRAG - Allows users to change a toolbar button's position by dragging it while holding down the ALT key.
        If this style is not specified, the user must hold down the SHIFT key while dragging a button.
        Note that the $CCS_ADJUSTABLE style must be specified to enable toolbar buttons to be dragged.
    $TBSTYLE_CUSTOMERASE - Generates $NM_CUSTOMDRAW messages when the toolbar processes $WM_ERASEBKGND messages
    $TBSTYLE_FLAT - Creates a flat toolbar
    $TBSTYLE_LIST - Creates a flat toolbar with button text to the right of the bitmap
    $TBSTYLE_REGISTERDROP - Generates $TBN_GETOBJECT notification messages to request drop target objects when the cursor passes over toolbar buttons.
    $TBSTYLE_TOOLTIPS - Creates a ToolTip control that an application can use to display descriptive text for the buttons in the toolbar.
    $TBSTYLE_TRANSPARENT - Creates a transparent toolbar. In a transparent toolbar, the toolbar is transparent but the buttons are not.
        Button text appears under button bitmaps. To prevent repainting problems, this style should be set before the toolbar control becomes visible.
    $TBSTYLE_WRAPABLE - Creates a toolbar that can have multiple lines of buttons.
        Toolbar buttons can "wrap" to the next line when the toolbar becomes too narrow to include all buttons on the same line.
        When the toolbar is wrapped, the break will occur on either the rightmost separator or the rightmost button if there are no separators on the bar.
        This style must be set to display a vertical toolbar control when the toolbar is part of a vertical rebar control.

$iExStyle [optional] Control extended styles:
    $TBSTYLE_EX_DRAWDDARROWS - Allows buttons to have a separate dropdown arrow. Buttons that have the
    $BTNS_DROPDOWN style will be drawn with a drop down arrow in a separate section, to the right of the button.
        If the arrow is clicked, only the arrow portion of the button will depress, and the toolbar control will send a $TBN_DROPDOWN notification to prompt the application to display the dropdown menu.
        If the main part of the button is clicked, the toolbar control sends a $WM_COMMAND message with the button's ID.
    $TBSTYLE_EX_HIDECLIPPEDBUTTONS - Hides partially clipped buttons
    $TBSTYLE_EX_DOUBLEBUFFER - Requires the toolbar to be double buffered
    $TBSTYLE_EX_MIXEDBUTTONS - Allows you to set text for all buttons, but only display it for the buttons with the $BTNS_SHOWTEXT button style.
        The $TBSTYLE_LIST style must also be set.
        Normally, when a button does not display text, you must handle $TBN_GETINFOTIP to display a ToolTip.
        With the $TBSTYLE_EX_MIXEDBUTTONS extended style, text that is set but not displayed on a button will automatically be used as the button's ToolTip text.
        You only need to handle $TBN_GETINFOTIP if it needs more flexibility in specifying the ToolTip text.

Return Value

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




#include <GUIConstantsEx.au3>
#include <GuiToolbar.au3>
#include <WinAPIConstants.au3>
#include <WindowsConstants.au3>

Global $g_hToolbar, $g_idMemo
Global $g_iItem ; Command identifier of the button associated with the notification.
Global Enum $e_idNew = 1000, $e_idOpen, $e_idSave, $e_idHelp


Func Example()
        Local $hGUI, $aSize

        ; Create GUI
        $hGUI = GUICreate("Toolbar", 600, 400)
        $g_hToolbar = _GUICtrlToolbar_Create($hGUI)
        $aSize = _GUICtrlToolbar_GetMaxSize($g_hToolbar)

        $g_idMemo = GUICtrlCreateEdit("", 2, $aSize[1] + 20, 596, 396 - ($aSize[1] + 20), $WS_VSCROLL)
        GUICtrlSetFont($g_idMemo, 9, 400, 0, "Courier New")
        GUIRegisterMsg($WM_NOTIFY, "_WM_NOTIFY")

        ; Add standard system bitmaps
        _GUICtrlToolbar_AddBitmap($g_hToolbar, 1, -1, $IDB_STD_LARGE_COLOR)

        ; Add buttons
        _GUICtrlToolbar_AddButton($g_hToolbar, $e_idNew, $STD_FILENEW)
        _GUICtrlToolbar_AddButton($g_hToolbar, $e_idOpen, $STD_FILEOPEN)
        _GUICtrlToolbar_AddButton($g_hToolbar, $e_idSave, $STD_FILESAVE)
        _GUICtrlToolbar_AddButton($g_hToolbar, $e_idHelp, $STD_HELP)

        ; Loop until the user exits.
        Until GUIGetMsg() = $GUI_EVENT_CLOSE
EndFunc   ;==>Example

; Write message to memo
Func MemoWrite($sMessage = "")
        GUICtrlSetData($g_idMemo, $sMessage & @CRLF, 1)
EndFunc   ;==>MemoWrite

; WM_NOTIFY event handler
Func _WM_NOTIFY($hWndGUI, $iMsgID, $wParam, $lParam)
        #forceref $hWndGUI, $iMsgID, $wParam
        Local $tNMHDR, $hWndFrom, $iCode, $iNew, $iFlags, $iOld
        Local $tNMTBHOTITEM
        $tNMHDR = DllStructCreate($tagNMHDR, $lParam)
        $hWndFrom = DllStructGetData($tNMHDR, "hWndFrom")
        $iCode = DllStructGetData($tNMHDR, "Code")
        Switch $hWndFrom
                Case $g_hToolbar
                        Switch $iCode
                                Case $NM_LDOWN
                                        MemoWrite("$NM_LDOWN: Clicked Item: " & $g_iItem & " at index: " & _GUICtrlToolbar_CommandToIndex($g_hToolbar, $g_iItem))
                                Case $TBN_HOTITEMCHANGE
                                        $tNMTBHOTITEM = DllStructCreate($tagNMTBHOTITEM, $lParam)
                                        $iOld = DllStructGetData($tNMTBHOTITEM, "idOld")
                                        $iNew = DllStructGetData($tNMTBHOTITEM, "idNew")
                                        $g_iItem = $iNew
                                        $iFlags = DllStructGetData($tNMTBHOTITEM, "dwFlags")
                                        If BitAND($iFlags, $HICF_LEAVING) = $HICF_LEAVING Then
                                                MemoWrite("$HICF_LEAVING: " & $iOld)
                                                Switch $iNew
                                                        Case $e_idNew
                                                                MemoWrite("$TBN_HOTITEMCHANGE: $e_idNew")
                                                        Case $e_idOpen
                                                                MemoWrite("$TBN_HOTITEMCHANGE: $e_idOpen")
                                                        Case $e_idSave
                                                                MemoWrite("$TBN_HOTITEMCHANGE: $e_idSave")
                                                        Case $e_idHelp
                                                                MemoWrite("$TBN_HOTITEMCHANGE: $idHelp")
        Return $GUI_RUNDEFMSG
EndFunc   ;==>_WM_NOTIFY