#include <GuiToolbar.au3>
#include <GuiMenu.au3>
#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>
#include <Constants.au3>
Opt('MustDeclareVars', 1)
$Debug_TB = False ; Check ClassName being passed to functions, set to True and use a handle to another control to see it work
Global $hGUI, $hToolbar
Global Enum $idNew = 1000, $idOpen, $idSave, $idHelp
_Main()
Func _Main()
; Create GUI
$hGUI = GUICreate("Toolbar", 200, 33, -1, -1, -1, BitOR($WS_EX_TOPMOST,$WS_EX_TOOLWINDOW))
;~ $hGUI = GUICreate("Toolbar", 250, 33, -1, -1, BitOR($WS_SYSMENU,$WS_CAPTION,$WS_MINIMIZEBOX), $WS_EX_TOPMOST)
$hToolbar = _GUICtrlToolbar_Create ($hGUI)
_GUICtrlToolbar_SetExtendedStyle($hToolbar, $TBSTYLE_EX_DRAWDDARROWS)
GUISetState()
; Add standard system bitmaps
Switch _GUICtrlToolbar_GetBitmapFlags ($hToolbar)
Case 2
_GUICtrlToolbar_AddBitmap ($hToolbar, 1, -1, $IDB_STD_SMALL_COLOR)
Case 0
_GUICtrlToolbar_AddBitmap ($hToolbar, 1, -1, $IDB_STD_LARGE_COLOR)
EndSwitch
; Add buttons
_GUICtrlToolbar_AddButton($hToolbar, $idNew, $STD_FILENEW, 0,$BTNS_WHOLEDROPDOWN ) ; 指定的按钮将会有一个下拉箭头
;~ _GUICtrlToolbar_AddButton($hToolbar, $idNew, $STD_FILENEW, 0,$BTNS_DROPDOWN) ; 创建一个下拉列表风格按钮,可以显示一个列表
_GUICtrlToolbar_AddButton($hToolbar, $idOpen, $STD_FILEOPEN)
_GUICtrlToolbar_AddButton($hToolbar, $idSave, $STD_FILESAVE)
_GUICtrlToolbar_AddButtonSep($hToolbar)
_GUICtrlToolbar_AddButton($hToolbar, $idHelp, $STD_HELP)
; Register message handlers
GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
; Loop until user exits
Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE
EndFunc ;==>_Main
; Handle TBN_DROPDOWN message
Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
Local $tNMHDR, $iCode, $hMenu
$tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
$iCode = DllStructGetData($tNMHDR, "Code")
If $iCode = $TBN_DROPDOWN Then ;
$hMenu = _GUICtrlMenu_CreatePopup()
_GUICtrlMenu_AddMenuItem($hMenu, "Template 1", 2000)
_GUICtrlMenu_AddMenuItem($hMenu, "Template 2", 2001)
_GUICtrlMenu_AddMenuItem($hMenu, "Template 3", 2002)
_GUICtrlMenu_AddMenuItem($hMenu, "", 0)
_GUICtrlMenu_AddMenuItem($hMenu, "Template 4", 2003)
_GUICtrlMenu_AddMenuItem($hMenu, "Template 5", 2004)
_GUICtrlMenu_TrackPopupMenu($hMenu, $hGUI)
_GUICtrlMenu_DestroyMenu($hMenu)
EndIf
Return $GUI_RUNDEFMSG
EndFunc ;==>WM_NOTIFY
; Handle WM_COMMAND messages
Func WM_COMMAND($hWnd, $iMsg, $iwParam, $ilParam)
Switch $iwParam
Case 2000
_WinAPI_ShowMsg ("Template 1")
Case 2001
_WinAPI_ShowMsg ("Template 2")
Case 2002
_WinAPI_ShowMsg ("Template 3")
Case $idOpen
_WinAPI_ShowMsg ("Open")
EndSwitch
EndFunc ;==>WM_COMMAND