Как назначить действие кнопке ToolBar-a, например простой вывод сообщения?
код:
код:
Код:
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <Array.au3>
#include <GuiEdit.au3>
#include <ButtonConstants.au3>
#include <GuiToolbar.au3>
#include <Constants.au3>
#include <GuiStatusBar.au3>
#include <GuiMenu.au3>
Opt("MustDeclareVars", 1)
Opt("GUIOnEventMode", 1)
Global $gForm1, $gForm2, $gForm1_Button1, $gForm1_Button2, $gForm1_Edit1, $gForm1_Chekbox1, $gForm3, $gForm3_Button1
Global $gForm1_Button3, $gForm1_Button4, $gForm1_Button5, $gForm1_Button6, $gForm1_Button7, $gForm1_Slider1
Global $gForm1_Progress1, $Filemenu1, $Filemenu2, $Filemenu3, $StartBar, $_ExitQuestion, $gSlider, $gsIni
Global $gForm2_Button1 = 11, $hToolbar, $ghStatus, $gButtonNew
$gsIni = @ScriptDir & "\GUI.ini"
Example()
;~ CheckUncheck()
;~ _Main()
While 1
Sleep(10)
WEnd
;_GUICtrlToolbar_SetExtendedStyle
Func Example()
Local $aGuiMessage, $lChekboxIniFlag
Local Enum $idNew = 1000, $idOpen, $idSave, $idHelp
Local $aText[3] = ["Left ", @TAB & "Centered", @TAB & " " & "Right"]
Local $aParts[3] = [130, 200, -1]
; Главное окно
$gForm1 = GUICreate("GUI", 600, 650, -1, -1, $WS_OVERLAPPEDWINDOW)
GUISetOnEvent($GUI_EVENT_CLOSE, "Form1_Button6_Click")
GUISetOnEvent($GUI_EVENT_RESIZED, "Form1_Resize")
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
$hToolbar = _GUICtrlToolbar_Create($gForm1)
_GUICtrlToolbar_AddBitmap($hToolbar, 1, -1, $IDB_VIEW_LARGE_COLOR)
; добавление кнопок к тулбару
$gButtonNew = _GUICtrlToolbar_AddButton($hToolbar, $idNew, $STD_FILENEW)
;~ GUIRegisterMsg($WM_NCMBUTTONDOWN, "_ExitQuestion")
_GUICtrlToolbar_AddButton($hToolbar, $idOpen, $STD_FILEOPEN)
_GUICtrlToolbar_AddButtonSep($hToolbar)
_GUICtrlToolbar_AddButton($hToolbar, $idSave, $STD_FILESAVE)
_GUICtrlToolbar_AddButtonSep($hToolbar)
_GUICtrlToolbar_AddButton($hToolbar, $idHelp, $STD_HELP)
$Filemenu1 = GUICtrlCreateMenu("Файл", -1, 0)
GUICtrlCreateMenuItem("Открыть", $Filemenu1, 0, 1)
GUICtrlCreateMenuItem("Сохранить", $Filemenu1, 1)
$StartBar = GUICtrlCreateMenuItem("Пуск прогресбара", $Filemenu1);, 1) ; пуск прогресбара
GUICtrlSetState(-1, $GUI_CHECKED)
GUICtrlSetOnEvent($StartBar, "CheckUncheck")
$_ExitQuestion = GUICtrlCreateMenuItem("Выход", $Filemenu1);, 2, 1) ; Выход с главного меню с подтверждением
GUICtrlSetOnEvent($_ExitQuestion, "_ExitQuestion")
$Filemenu3 = GUICtrlCreateMenu("Правка", -1, 1)
$Filemenu2 = GUICtrlCreateMenu("Формат", -1, 2)
$Filemenu2 = GUICtrlCreateMenu("Вид", -1, 3)
$Filemenu2 = GUICtrlCreateMenu("?", -1, 4)
$gForm1_Edit1 = GUICtrlCreateEdit("Первая строка", 10, 50, 300, 200)
$lChekboxIniFlag = IniRead($gsIni, "Section1", "key", 0)
$gForm1_Chekbox1 = GUICtrlCreateCheckbox("Чекбокс", 340, 60, 60, 20, $BS_AUTO3STATE)
GUICtrlSetState($gForm1_Chekbox1, $lChekboxIniFlag)
$gForm1_Slider1 = GUICtrlCreateSlider(340, 95, 60, 20)
GUICtrlSetData($gForm1_Slider1, 50) ; слайдер
$ghStatus = _GUICtrlStatusBar_Create($gForm1, $aParts, $aText);,$SBARS_SIZEGRIP)
GUIRegisterMsg($WM_SIZE, "WM_SIZE")
$gForm1_Progress1 = GUICtrlCreateProgress(340, 150, 100, 15)
GUICtrlSetData($gForm1_Progress1, 80)
$gForm1_Button1 = GUICtrlCreateButton("Скрыть Edit", 10, 380, 100)
GUICtrlSetOnEvent($gForm1_Button1, "Form1_Button1_Click")
$gForm1_Button3 = GUICtrlCreateButton("Спрятать чекбокс", 200, 380, 100)
GUICtrlSetOnEvent($gForm1_Button3, "Form1_Button3_Click")
$gForm1_Button2 = GUICtrlCreateButton("Of\On чекбокс", 390, 380, 100)
GUICtrlSetOnEvent($gForm1_Button2, "Form1_Button2_Click")
$gForm1_Button4 = GUICtrlCreateButton("Фокус на чекбокс", 10, 430, 100)
GUICtrlSetOnEvent($gForm1_Button4, "Form1_Button4_Click")
$gForm1_Button5 = GUICtrlCreateButton("Дочернее", 200, 430, 100)
GUICtrlSetOnEvent($gForm1_Button5, "Form1_Button5_Click")
$gForm1_Button6 = GUICtrlCreateButton("Завершить", 390, 430, 100)
GUICtrlSetOnEvent($gForm1_Button6, "Form1_Button6_Click")
$gForm1_Button7 = GUICtrlCreateButton("Свободное", 10, 480, 100)
GUICtrlSetOnEvent($gForm1_Button7, "Form1_Button7_Click")
GUISetState()
;~ GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
EndFunc ;==>Example
;~ 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_TrackPopupMenu($hMenu, $gForm1)
;~ _GUICtrlMenu_DestroyMenu($hMenu)
;~ EndIf
;~ Return $GUI_RUNDEFMSG
;~ EndFunc ;==>WM_NOTIFY
; изменять размер статусбара при изменении окна
Func WM_SIZE($hWnd, $iMsg, $iwParam, $ilParam)
_GUICtrlStatusBar_Resize($ghStatus)
Return $GUI_RUNDEFMSG
EndFunc ;==>WM_SIZE
;выход с завершением
Func _ExitQuestion()
If MsgBox(1, "", "Завершить?") = 1 Then
Exit
EndIf
EndFunc ;==>_ExitQuestion
Func CheckUncheck()
If BitAND(GUICtrlRead($StartBar), $GUI_CHECKED) = $GUI_CHECKED Then
GUICtrlSetState($StartBar, $GUI_UNCHECKED)
_RunProgressbar()
;~ MsgBox(0,"333","555")
Else
GUICtrlSetState($StartBar, $GUI_CHECKED)
;~ GUICtrlSetState($StartBar, $GUI_UNCHECKED)
;~ MsgBox(0,"333","1111")
;~ _RunProgressbar()
EndIf
EndFunc ;==>CheckUncheck
Func _RunProgressbar()
Local $y
While 1 ;BitAND(GUICtrlRead($StartBar), $GUI_CHECKED) = $GUI_CHECKED
$gSlider = GUICtrlRead($gForm1_Slider1)
If $gSlider = 0 Then
GUICtrlSetState($StartBar, $GUI_UNCHECKED)
ExitLoop
EndIf
;~ MsgBox(0,"2",$gSlider)
For $i = 1 To 100 Step $gSlider
GUICtrlSetData($gForm1_Progress1, $i)
Sleep(20)
Next
For $y = 100 To 1 Step -$gSlider
GUICtrlSetData($gForm1_Progress1, $y);(100 - $i))
Sleep(20)
Next
WEnd
EndFunc ;==>_RunProgressbar
Func Form1_Resize()
Local $Win_Pos, $Button_1_Text, $Control_Pos1, $Control_Pos2, $Button_2_Text, $Win_Pos, $iWidth
$Win_Pos = WinGetPos($gForm1)
$Button_1_Text = ControlGetText($gForm1, "", $gForm1_Button1) ; текст кнопки OK
$Button_2_Text = ControlGetText($gForm1, "", $gForm1_Button2) ; Текст кнопки Отмена
$Control_Pos1 = ControlGetPos($gForm1, $Button_1_Text, $gForm1_Button1) ; Координаты кнопки ОК
$Control_Pos2 = ControlGetPos($gForm1, $Button_2_Text, $gForm1_Button2) ; координаты кнопки отмена
$iWidth = 26 + $Control_Pos1[2] + $Control_Pos2[2]
If $Win_Pos[2] < $iWidth Then
WinMove($gForm1, "", $Win_Pos[0], $Win_Pos[1], $iWidth, $Win_Pos[3])
ElseIf $Win_Pos[3] < 300 Then
WinMove($gForm1, "", $Win_Pos[0], $Win_Pos[1], $Win_Pos[2], 300)
EndIf
EndFunc ;==>Form1_Resize
Func Form1_Button1_Click() ; спрятать\показать EDIT
If GUICtrlGetState($gForm1_Edit1) = ($GUI_SHOW + $GUI_ENABLE) Then
GUICtrlSetState($gForm1_Edit1, $GUI_HIDE)
Else
GUICtrlSetState($gForm1_Edit1, $GUI_SHOW)
EndIf
EndFunc ;==>Form1_Button1_Click
Func Form1_Button2_Click(); вкл откл чекбокс чекбокс и записать состояние в INI
If GUICtrlRead($gForm1_Chekbox1) = $GUI_UNCHECKED Then
GUICtrlSetState($gForm1_Chekbox1, $GUI_CHECKED)
IniWrite($gsIni, "section1", "key", $GUI_CHECKED)
ElseIf GUICtrlRead($gForm1_Chekbox1) = $GUI_CHECKED Then
GUICtrlSetState($gForm1_Chekbox1, $GUI_INDETERMINATE)
IniWrite($gsIni, "section1", "key", $GUI_INDETERMINATE)
ElseIf GUICtrlRead($gForm1_Chekbox1) = $GUI_INDETERMINATE Then
GUICtrlSetState($gForm1_Chekbox1, $GUI_UNCHECKED)
IniWrite($gsIni, "section1", "key", $GUI_UNCHECKED)
EndIf
EndFunc ;==>Form1_Button2_Click
Func Form1_Button3_Click(); спрятать чекбокс
If GUICtrlGetState($gForm1_Chekbox1) = ($GUI_SHOW + $GUI_ENABLE) Then
GUICtrlSetState($gForm1_Chekbox1, $GUI_DISABLE)
Else
GUICtrlSetState($gForm1_Chekbox1, $GUI_ENABLE)
EndIf
EndFunc ;==>Form1_Button3_Click
Func Form1_Button4_Click(); установка фокуса на чекбокс
ControlFocus($gForm1, "", $gForm1_Chekbox1)
EndFunc ;==>Form1_Button4_Click
Func Form1_Button5_Click(); дочернее окно
$gForm2 = GUICreate("Дочернее", 400, 500, -1, -1, -1, -1, $gForm1)
GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")
$gForm2_Button1 = GUICtrlCreateButton("Фокус на 1окно", 20, 20, 100)
GUICtrlSetOnEvent($gForm2_Button1, "ActivateParent")
GUISetState()
EndFunc ;==>Form1_Button5_Click
Func ActivateParent() ; активировать родительское окно
WinActivate($gForm1)
EndFunc ;==>ActivateParent
Func Form1_Button7_Click(); свободное окно
$gForm3 = GUICreate("Свободное", 400, 500, -1, -1)
GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")
$gForm3_Button1 = GUICtrlCreateButton("Sample", 20, 20, 100)
GUISetState()
EndFunc ;==>Form1_Button7_Click
Func Form1_Button6_Click() ; завершить
Exit
EndFunc ;==>Form1_Button6_Click
Func _Exit()
If @GUI_WinHandle = $gForm1 Then Exit
GUIDelete(@GUI_WinHandle)
EndFunc ;==>_Exit