使用快捷键点击特定按钮
#Include <GuiToolBar.au3>
_GUICtrlToolbar_ClickAccel($hWnd, $cAccel[, $sButton = "left"[, $fMove = False[, $iClicks = 1[, $iSpeed = 1]]]])
$hWnd | 控件句柄 |
$cAccel | 按钮快捷键 |
$sButton | [可选参数] 点击的按钮 |
$fMove | [可选参数] 鼠标移动标志: True - 鼠标移动 False - 鼠标不移动 |
$iClicks | [可选参数] 点击次数 |
$iSpeed | [可选参数] 鼠标移动速度 |
#include <GuiToolbar.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <Constants.au3>
$Debug_TB = False ; 检查传递给函数的类名, 设置为真并使用另一控件的句柄可以看出它是否有效
Global $hToolbar, $iMemo
Global $iItem ; 与通告相关联的按钮的命令标识符
Global Enum $idNew = 1000, $idOpen, $idSave, $idHelp
_Main()
Func _Main()
Local $hGUI, $aSize, $aStrings[4]
; 创建 GUI
$hGUI = GUICreate("Toolbar", 600, 400)
$hToolbar = _GUICtrlToolbar_Create($hGUI)
$aSize = _GUICtrlToolbar_GetMaxSize($hToolbar)
$iMemo = GUICtrlCreateEdit("", 2, $aSize[1] + 30, 596, 396 - ($aSize[1] + 30), $WS_VSCROLL)
GUICtrlSetFont($iMemo, 9, 400, 0, "Courier New")
GUISetState()
GUIRegisterMsg($WM_NOTIFY, "_WM_NOTIFY")
; 添加标准系统位图
_GUICtrlToolbar_AddBitmap($hToolbar, 1, -1, $IDB_STD_LARGE_COLOR)
; 添加字符串
$aStrings[0] = _GUICtrlToolbar_AddString($hToolbar, "&New")
$aStrings[1] = _GUICtrlToolbar_AddString($hToolbar, "&Open")
$aStrings[2] = _GUICtrlToolbar_AddString($hToolbar, "&Save")
$aStrings[3] = _GUICtrlToolbar_AddString($hToolbar, "&Help")
; 添加按钮
_GUICtrlToolbar_AddButton($hToolbar, $idNew, $STD_FILENEW, $aStrings[0])
_GUICtrlToolbar_AddButton($hToolbar, $idOpen, $STD_FILEOPEN, $aStrings[1])
_GUICtrlToolbar_AddButton($hToolbar, $idSave, $STD_FILESAVE, $aStrings[2])
_GUICtrlToolbar_AddButtonSep($hToolbar)
_GUICtrlToolbar_AddButton($hToolbar, $idHelp, $STD_HELP, $aStrings[3])
; 使用快捷键点击保存按钮
_GUICtrlToolbar_ClickAccel($hToolbar, "s", "left", True)
; 循环直到用户退出
Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE
EndFunc ;==>_Main
; 写入消息到 memo
Func MemoWrite($sMessage = "")
GUICtrlSetData($iMemo, $sMessage & @CRLF, 1)
EndFunc ;==>MemoWrite
; WM_NOTIFY 事件处理程序
Func _WM_NOTIFY($hWndGUI, $MsgID, $wParam, $lParam)
#forceref $hWndGUI, $MsgID, $wParam
Local $tNMHDR, $hwndFrom, $code, $i_idNew, $dwFlags, $i_idOld
Local $tNMTBHOTITEM
$tNMHDR = DllStructCreate($tagNMHDR, $lParam)
$hwndFrom = DllStructGetData($tNMHDR, "hWndFrom")
$code = DllStructGetData($tNMHDR, "Code")
Switch $hwndFrom
Case $hToolbar
Switch $code
Case $NM_LDOWN
;----------------------------------------------------------------------------------------------
MemoWrite("$NM_LDOWN: Clicked Item: " & $iItem & " at index: " & _GUICtrlToolbar_CommandToIndex($hToolbar, $iItem))
;----------------------------------------------------------------------------------------------
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: $idNew")
;----------------------------------------------------------------------------------------------
Case $idOpen
;----------------------------------------------------------------------------------------------
MemoWrite("$TBN_HOTITEMCHANGE: $idOpen")
;----------------------------------------------------------------------------------------------
Case $idSave
;----------------------------------------------------------------------------------------------
MemoWrite("$TBN_HOTITEMCHANGE: $idSave")
;----------------------------------------------------------------------------------------------
Case $idHelp
;----------------------------------------------------------------------------------------------
MemoWrite("$TBN_HOTITEMCHANGE: $idHelp")
;----------------------------------------------------------------------------------------------
EndSwitch
EndIf
EndSwitch
EndSwitch
Return $GUI_RUNDEFMSG
EndFunc ;==>_WM_NOTIFY