Что нового

Как назначить действие кнопке ToolBar-a

SET777

Новичок
Сообщения
51
Репутация
3
Как назначить действие кнопке 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
 

Yashied

Модератор
Команда форума
Глобальный модератор
Сообщения
5 379
Репутация
2 713
WM_NOTIFY здесь нужно только для всплывающих подсказок.

Код:
#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, $gForm1_Dummy
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, BitOR($BTNS_BUTTON, $BTNS_SHOWTEXT, $TBSTYLE_FLAT, $TBSTYLE_TOOLTIPS), $TBSTYLE_EX_DOUBLEBUFFER)
	_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)

	$gForm1_Dummy = GUICtrlCreateDummy()
	GUICtrlSetOnEvent($gForm1_Dummy, "Form1_Toolbar_Click")

	$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")

	GUIRegisterMsg($WM_COMMAND, 'WM_COMMAND')
	GUIRegisterMsg($WM_NOTIFY, 'WM_NOTIFY')

	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 Form1_Toolbar_Click()
	Local $ID = GUICtrlRead($gForm1_Dummy)
	Switch $ID
		Case 1000
			MsgBox(0, 'Toolbar', 'ID = 1000', 0, $gForm1)
		Case 1001
			MsgBox(0, 'Toolbar', 'ID = 1001', 0, $gForm1)
		Case 1002
			MsgBox(0, 'Toolbar', 'ID = 1002', 0, $gForm1)
		Case 1003
			MsgBox(0, 'Toolbar', 'ID = 1003', 0, $gForm1)
		Case Else

	EndSwitch
EndFunc   ;==>Form1_Toolbar_Click


Func _Exit()
	If @GUI_WinHandle = $gForm1 Then Exit
	GUIDelete(@GUI_WinHandle)
EndFunc   ;==>_Exit


Func WM_COMMAND($hWnd, $iMsg, $wParam, $lParam)

	Local $ID = BitAND($wParam, 0xFFFF), $Code = BitShift($wParam, 16)

	Switch $hWnd
		Case $gForm1
			Switch $ID
				Case 1000 To 1000 + 3
					Switch $Code
						Case $BN_CLICKED
							GUICtrlSendToDummy($gForm1_Dummy, $ID)
					EndSwitch
			EndSwitch
	EndSwitch
	Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_COMMAND


Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam)
	Local $tNMIA = DllStructCreate($tagNMITEMACTIVATE, $lParam)
	Local $hTarget = DllStructGetData($tNMIA, 'hWndFrom')
	Local $ID = DllStructGetData($tNMIA, 'Code')
	Switch $hWnd
		Case $gForm1
			Switch $hTarget
				Case $hToolbar
					Switch $ID
						Case $TBN_GETINFOTIPW
							Local $tNMTBGIT = DllStructCreate($tagNMHDR & ';ptr Text;int TextMax;int Item;lparam lParam;', $lParam)
							Local $Item = DllStructGetData($tNMTBGIT, 'Item')
							Local $Text
							Switch $Item
								Case 1000
									$Text = 'ID = 1000'
								Case 1001
									$Text = 'ID = 1001'
								Case 1002
									$Text = 'ID = 1002'
								Case 1003
									$Text = 'ID = 1003'
								Case Else
									$Text = ''
							EndSwitch
							If $Text Then
								DllStructSetData(DllStructCreate('wchar[' & DllStructGetData($tNMTBGIT, 'TextMax') & ']', DllStructGetData($tNMTBGIT, 'Text')), 1, $Text)
							EndIf
					EndSwitch
			EndSwitch
	EndSwitch
	Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY
 

AZJIO

Меценат
Меценат
Сообщения
2 752
Репутация
1 149
SET777

Вот что я пробовал. Но ажиотаж быстро спал, так как для WM_... не рекомендуется делать задержку и пришлось бы внутри WM_... передавать в глобальные переменные какие либо параметры (например пути копирования файлов), чтоб потом в общем цикле GUI их выполнить используя триггеры.

Код:
#include <GuiToolbar.au3>
#include <GuiImageList.au3>
#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>

Global $iItem
Global $hGUI, $hToolbar, $hNormal, $hDisabled, $hHot
Global Enum $but1 = 1000, $but2, $but3

; Создание GUI
$hGUI = GUICreate("Toolbar", 400, 300)
$hToolbar = _GUICtrlToolbar_Create($hGUI)
GUISetState()
GUIRegisterMsg($WM_NOTIFY, "_WM_NOTIFY")

; Список иконок для нормальных кнопок
$hNormal = _GUIImageList_Create(16,16, 5)
_GUIImageList_AddIcon($hNormal, 'shell32.dll', 3)
_GUIImageList_AddIcon($hNormal, 'regedit.exe', 0)
_GUIImageList_AddIcon($hNormal, 'notepad.exe', 0)
_GUICtrlToolbar_SetImageList($hToolbar, $hNormal)

; Список иконок для отключенных кнопок
$hDisabled = _GUIImageList_Create(16,16, 5)
_GUIImageList_AddIcon($hDisabled, 'shell32.dll', 7)
_GUIImageList_AddIcon($hDisabled, 'shell32.dll', 8)
_GUIImageList_AddIcon($hDisabled, 'shell32.dll', 12)
_GUICtrlToolbar_SetDisabledImageList($hToolbar, $hDisabled)

; Список иконок для состояния наведения на кнопку
$hHot = _GUIImageList_Create(16,16, 5)
_GUIImageList_AddIcon($hHot, 'shell32.dll', 4)
_GUIImageList_AddIcon($hHot, 'shell32.dll', 12)
_GUIImageList_AddIcon($hHot, 'shell32.dll', 3)
_GUICtrlToolbar_SetHotImageList($hToolbar, $hHot)

; Добавление кнопок
_GUICtrlToolbar_AddButton($hToolbar, $but1, 0)
_GUICtrlToolbar_AddButton($hToolbar, $but2, 1)
_GUICtrlToolbar_AddButton($hToolbar, $but3, 2)

; Disable Blue button
; _GUICtrlToolbar_EnableButton($hToolbar, $idBlue, False)

Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE

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 $NM_LDOWN
					$a = _GUICtrlToolbar_CommandToIndex ($hToolbar, $iItem)
					Switch $iItem
						Case $but1
							Run('Explorer.exe')
						Case $but2
							Run('regedit.exe')
						Case $but3
							Run('notepad.exe')
					EndSwitch
                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
                                ; SoundPlay(@WindowsDir & "\media\start.wav")
                    Else
                        Switch $i_idNew
                            Case $but1
                                SoundPlay(@WindowsDir & "\media\start.wav")
                            Case $but2
                                SoundPlay(@WindowsDir & "\media\start.wav")
                            Case $but3
                                SoundPlay(@WindowsDir & "\media\start.wav")
                        EndSwitch
                    EndIf
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>_WM_NOTIFY
 
Автор
S

SET777

Новичок
Сообщения
51
Репутация
3
Спасибо за наглядные примеры :smile:
 
Верх