Function Reference


Determines where a point lies within the control

#include <GuiToolbar.au3>
_GUICtrlToolbar_HitTest ( $hWnd, $iX, $iY )


$hWnd Handle to the control
$iX X position to test
$iY Y position to test

Return Value

Success: If the value is zero or a positive value, it is the 0-based index of the nonseparator item in which the point lies.
Failure: If the value is negative, the point does not lie within a button.


The absolute value of the return value is the index of a separator item or the nearest nonseparator item.


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

Global $g_idMemo


Func Example()
    Local $hGUI, $hToolbar, $aRect, $iHit, $aStrings[4]
    Local Enum $e_idNew = 1000, $e_idOpen, $e_idSave, $idHelp

    ; Create GUI
    $hGUI = GUICreate("Toolbar", 400, 300)
    $hToolbar = _GUICtrlToolbar_Create($hGUI)
    $g_idMemo = GUICtrlCreateEdit("", 2, 36, 396, 262, $WS_VSCROLL)
    GUICtrlSetFont($g_idMemo, 10, 400, 0, "Courier New")

    ; Add standard system bitmaps
    Switch _GUICtrlToolbar_GetBitmapFlags($hToolbar)
        Case 0
            _GUICtrlToolbar_AddBitmap($hToolbar, 1, -1, $IDB_STD_SMALL_COLOR)
        Case 2
            _GUICtrlToolbar_AddBitmap($hToolbar, 1, -1, $IDB_STD_LARGE_COLOR)

    ; Add strings
    $aStrings[0] = _GUICtrlToolbar_AddString($hToolbar, "&New Button")
    $aStrings[1] = _GUICtrlToolbar_AddString($hToolbar, "&Open Button")
    $aStrings[2] = _GUICtrlToolbar_AddString($hToolbar, "&Save Button")
    $aStrings[3] = _GUICtrlToolbar_AddString($hToolbar, "&Help Button")

    ; Add buttons
    _GUICtrlToolbar_AddButton($hToolbar, $e_idNew, $STD_FILENEW, $aStrings[0])
    _GUICtrlToolbar_AddButton($hToolbar, $e_idOpen, $STD_FILEOPEN, $aStrings[1])
    _GUICtrlToolbar_AddButton($hToolbar, $e_idSave, $STD_FILESAVE, $aStrings[2])
    _GUICtrlToolbar_AddButton($hToolbar, $idHelp, $STD_HELP, $aStrings[3])

    ; Do a hit test on the Save button
    $aRect = _GUICtrlToolbar_GetButtonRect($hToolbar, $e_idSave)
    $iHit = _GUICtrlToolbar_HitTest($hToolbar, $aRect[0], $aRect[1])
    MemoWrite(StringFormat("Hit test at %d, %d = %d", $aRect[0], $aRect[1], $iHit))

    ; 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