#include <GuiToolbar.au3>
#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>
#include <Constants.au3>
$Debug_TB = False ; 检查传递给函数的类名, 设置为True,并使用另一个控件句柄,看看它的工作.
Global $hGUI
Global $hToolbar, $iMemo
Global $iItem ; 与通知有关的按钮命令标识符.
Global Enum $idNew = 1000, $idOpen, $idSave, $idHelp
_Main()
Func _Main()
Local $hGUI, $aSize
; 创建 GUI
$hGUI = GUICreate("工具栏 UDF 函数演示", 600, 400)
$hToolbar = _GUICtrlToolbar_Create($hGUI)
$aSize = _GUICtrlToolbar_GetMaxSize($hToolbar)
$iMemo = GUICtrlCreateEdit("", 2, $aSize[1] + 20, 596, 396 - ($aSize[1] + 20), $WS_VSCROLL)
GUICtrlSetFont($iMemo, 9, 400, 0, "Courier New")
GUISetState()
;GUIRegisterMsg($WM_NOTIFY, "_WM_NOTIFY")
; 添加标准系统位图
_GUICtrlToolbar_AddBitmap($hToolbar, 1, -1, $IDB_STD_LARGE_COLOR)
; 添加按钮
_GUICtrlToolbar_AddButton($hToolbar, $idNew, $STD_FILENEW)
_GUICtrlToolbar_AddButton($hToolbar, $idOpen, $STD_FILEOPEN)
_GUICtrlToolbar_AddButton($hToolbar, $idSave, $STD_FILESAVE)
_GUICtrlToolbar_AddButtonSep($hToolbar)
_GUICtrlToolbar_AddButton($hToolbar, $idHelp, $STD_HELP)
; 循环到用户退出
Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE
EndFunc ;==>_Main
; 写运行结果信息到编辑框.
Func MemoWrite($sMessage = "")
GUICtrlSetData($iMemo, $sMessage & @CRLF, 1)
EndFunc ;==>MemoWrite
; 打开子窗口
Func childGUI()
$myGui = GUICreate("", 100, 100, -1, -1,$hGUI)
GUISetState()
Do
$msg = GUIGetMsg()
Until $msg = $GUI_EVENT_CLOSE
EndFunc ;==>childGUI
; WM_NOTIFY 通知事件处理程序
Func _WM_NOTIFY($hWndGUI, $MsgID, $wParam, $lParam)
#forceref $hWndGUI, $MsgID, $wParam
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 $TBN_HOTITEMCHANGE
$tNMTBHOTITEM = DllStructCreate($tagNMTBHOTITEM, $lParam)
$i_idOld = DllStructGetData($tNMTBHOTITEM, "idOld")
$i_idNew = DllStructGetData($tNMTBHOTITEM, "idNew")
$iItem = $i_idNew
$dwFlags = DllStructGetData($tNMTBHOTITEM, "dwFlags")
If BitAND($dwFlags, $HICF_LEAVING) = $HICF_LEAVING Then
MemoWrite("$HICF_LEAVING 鼠标离开: " & $i_idOld)
Else
Switch $i_idNew
Case $idNew
;----------------------------------------------------------------------------------------------
MemoWrite("$TBN_HOTITEMCHANGE 鼠标停留: 在'新建'")
;----------------------------------------------------------------------------------------------
childGUI()
EndSwitch
EndIf
EndSwitch
EndSwitch
Return $GUI_RUNDEFMSG
EndFunc ;==>_WM_NOTIFY