#include <Constants.au3>
#include <GuiToolbar.au3>
#include <GuiImageList.au3>
#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>
Global $iButtonNum = 30
Global $iCmdID
Global $iWidth = 80, $iHeight = 80
$MyGui = GUICreate("ToolBar 应用", 600, 450)
$hToolBar = _GUICtrlToolbar_Create($MyGui, $TBSTYLE_WRAPABLE)
$hToolBar_Image = _GUIImageList_Create(32, 32, 5, 3)
_GUICtrlToolbar_SetImageList($hToolBar, $hToolBar_Image)
_GUICtrlToolbar_SetIndent($hToolBar, 5)
For $i = 0 To $iButtonNum
_GUIImageList_AddIcon($hToolBar_Image, @SystemDir & "\Shell32.dll", 100 + $i, True)
$sButtonText = _GUICtrlToolbar_AddString($hToolBar, "按钮 - " & $i + 1)
_GUICtrlToolbar_AddButton($hToolBar, 1000 + $i, $i, $sButtonText)
Next
_GUICtrlToolbar_SetButtonSize($hToolBar, $iWidth, $iHeight)
_GUICtrlToolbar_SetStyle($hToolBar, BitOR($TBSTYLE_FLAT, $TBSTYLE_WRAPABLE, $CCS_TOP, $TBSTYLE_TRANSPARENT))
GUISetState()
GUIRegisterMsg($WM_NOTIFY, "_WM_NOTIFY")
Do
Until GUIGetMsg() = -3
Func _WM_NOTIFY($hWndGUI, $MsgID, $wParam, $lParam)
Local $tNMHDR, $event, $hwndFrom, $code, $i_idNew, $dwFlags, $lResult, $idFrom, $i_idOld
Local $tNMTOOLBAR, $tNMTBHOTITEM
$tNMHDR = DllStructCreate($tagNMHDR, $lParam)
$hwndFrom = DllStructGetData($tNMHDR, "hWndFrom")
$idFrom = DllStructGetData($tNMHDR, "IDFrom")
$code = DllStructGetData($tNMHDR, "Code")
Switch $hwndFrom
Case $hToolBar
Switch $code
Case -2
If $iCmdID Then
MsgBox(0, 'CmdID = ' & $iCmdID, 'ButtonText = ' & _GUICtrlToolbar_GetButtonText($hToolBar, $iCmdID))
EndIf
$iCmdID = ''
Case $TBN_HOTITEMCHANGE
$tNMTBHOTITEM = DllStructCreate($tagNMTBHOTITEM, $lParam)
$i_idOld = DllStructGetData($tNMTBHOTITEM, "idOld")
$i_idNew = DllStructGetData($tNMTBHOTITEM, "idNew")
$iCmdID = $i_idNew
EndSwitch
EndSwitch
Return $GUI_RUNDEFMSG
EndFunc ;==>_WM_NOTIFY
|