;************************************************************************************
;---------------Начало секции инициализации всех функций-----------------------------
If A_IsCompiled
{
vDirGMB := "AllAddFunc.res\GMsgBox.res"
IfNotExist, AllAddFunc.res\GMsgBox.res
{
FileCreateDir, AllAddFunc.res\GMsgBox.res ; Создаём папку для ресурсов
FileSetAttrib, +H+A+R, AllAddFunc.res ; Делаем её архивной, только для чтения и скрытой
FileSetAttrib, +H+A+R, AllAddFunc.res\GMsgBox.res ; Делаем её архивной, только для чтения и скрытой
}
FileInstall, C:\AHK\Include\AllAddFunc.res\GMsgBox.res\GMB.ini, AllAddFunc.res\GMsgBox.res\GMB.ini
FileInstall, C:\AHK\Include\AllAddFunc.res\GMsgBox.res\Default.wav, AllAddFunc.res\GMsgBox.res\Default.wav
FileInstall, C:\AHK\Include\AllAddFunc.res\GMsgBox.res\Done.wav, AllAddFunc.res\GMsgBox.res\Done.wav
FileInstall, C:\AHK\Include\AllAddFunc.res\GMsgBox.res\Error.wav, AllAddFunc.res\GMsgBox.res\Error.wav
FileInstall, C:\AHK\Include\AllAddFunc.res\GMsgBox.res\Question.wav, AllAddFunc.res\GMsgBox.res\Question.wav
FileInstall, C:\AHK\Include\AllAddFunc.res\GMsgBox.res\Alert.wav, AllAddFunc.res\GMsgBox.res\Alert.wav
FileInstall, C:\AHK\Include\AllAddFunc.res\GMsgBox.res\Info.wav, AllAddFunc.res\GMsgBox.res\Info.wav
FileInstall, C:\AHK\Include\AllAddFunc.res\GMsgBox.res\Default.png, AllAddFunc.res\GMsgBox.res\Default.png
FileInstall, C:\AHK\Include\AllAddFunc.res\GMsgBox.res\Done.png, AllAddFunc.res\GMsgBox.res\Done.png
FileInstall, C:\AHK\Include\AllAddFunc.res\GMsgBox.res\Error.png, AllAddFunc.res\GMsgBox.res\Error.png
FileInstall, C:\AHK\Include\AllAddFunc.res\GMsgBox.res\Question.png, AllAddFunc.res\GMsgBox.res\Question.png
FileInstall, C:\AHK\Include\AllAddFunc.res\GMsgBox.res\Alert.png, AllAddFunc.res\GMsgBox.res\Alert.png
FileInstall, C:\AHK\Include\AllAddFunc.res\GMsgBox.res\Info.png, AllAddFunc.res\GMsgBox.res\Info.png
}
Else
{
vDirGMB := "C:\AHK\Include\AllAddFunc.res\GMsgBox.res"
}
Goto PointBypass_AllAddFunc ;Обход активной части модуля
;************************************************************************************
; Подпрограмма иницализации вызвать после подключения по...
; #Include C:\AHK\Include\AllAddFunc.ahk
;--------Beginning the initialization section of all functions---------------------------------
;--------Beginning of the initialization functions of GMsgBox----------------------------------
Install_GMsgBox:
fInstall_GMsgBox := False
сMsgOkInfoModal :=0+8192+64 ;only an OK button + Task Modal + Icon Asterisk(info)
сMsgOkErModal :=0+8192+16 ;only an OK button + Task Modal + Icon Hand (stop/error)
сMsgOkAlertModal :=0+8192+48 ;only an OK button + Task Modal + Icon Exclamation
сMsgYNQuestModal :=4+8192+32 ;Yes/No button + Task Modal + Icon Question
сMsgYNInfoModal :=4+8192+64 ;Yes/No button + Task Modal + Icon Asterisk (info)
; Проверка файлов на существование
; Описание массива Звук + ICO для простоты вызова
; Simple beep
cSoundDefault := "Default.wav", cIcoDefault := "Default.png"
; Done
cSoundDone := "Done.wav", cIcoDone := "Done.png"
; Error
cSoundError := "Error.wav", cIcoError := "Error.png",
; Question
cSoundQuest := "Question.wav", cIcoQuest := "Question.png",
; Alert
cSoundAlert := "Alert.wav", cIcoAlert := "Alert.png"
; Info
cSoundInfo := "Info.wav", cIcoInfo := "Info.png"
iSetOfButtonMin := iSetOfButtonBeep :=1
iSetOfButtonDone :=2
iSetOfButtonError :=3
iSetOfButtonQuest :=4
iSetOfButtonAlert :=5
iSetOfButtonMax := iSetOfButtonInfo :=6
arSoundIco := [[cSoundDefault,cIcoDefault,"Default"]
,[cSoundDone,cIcoDone,"Done"]
,[cSoundError,cIcoError,"Error"]
,[cSoundQuest,cIcoQuest,"Question"]
,[cSoundAlert,cIcoAlert,"Alert"]
,[cSoundInfo,cIcoInfo,"Info"]]
;Коды комбинаций кнопок, If ((cBtOk || cBtOkC || cBtYN || cBtYNC)<0) Then Left-Most Else Right-Most
cButtonKeyNot := False, cButtonKeyOk := 1, cButtonKeyOkC := 2, cButtonKeyYN := 3, cButtonKeyYNC := 4
;Имена кнопок(можно менять)
iNameEng := 1
iNameRus := 2
arNameBT := [["OK","Cansel","Yes","No"]
,["ОК","Отмена","Да","Нет"]]
Gosub lCheckUsedFiles
fInstall_GMsgBox := True
Return
;-----------End of the initialization functions of GMsgBox--------------------
;--------End of the initialization section of all functions-------------------
;************************************************************************************
;************************************************************************************
; Начало описания функций
;************************************************************************************
;------------------Начало определения функции GMsgBox (Свой MsgBox)------------------
GMsgBox(i,TittleGMB,TextGMB
,DelayGMB := 30.5, ButtonKey := False, ButtonLng := 2
,SizeTextGMB := 12, ColorTextGMB := "000000", FontWeightTextGMB := "300", FontTextGMB := "Verdana"
,SizeButnGMB := 14, ColorButnGMB := "000000", FontWeightButnGMB := "850", FontButnGMB := "MS sans serif")
{
Global vDirGMB, arSoundIco, arNameBT, сMsgOkErModal, iSetOfButtonMin, iSetOfButtonMax
; If ((BtOk || BtOkC || BtYN || BtYNC)<0) Then Left-Most Else Right-Most
BtNot := False, BtOk := 1, BtOkC := 2, BtYN := 3, BtYNC := 4
retDef := False ; Значение не определено
retTimeOut := 100, retOk := retYes := 1, retNo := 2, retESC := 3, retCross := 4, retCancel := -1
Gosub lAllCheck ;Проверяем валидность входных данных, т.е. которые можем проверить - выход без условный при ошибке
DelayGMB := Ceil(Round(DelayGMB,1)*10) ; Коррекция и установка времени задержки с точностью до одной десятой секунды.
DelayStep := 100 ; Шаг ожидания в цикле, даёт эквивалент для DelayGMB времени ожидания в секундах
SoundGMB := vDirGMB "\" arSoundIco[i,1] ; Установка звукового сигнала
PicGMB := vDirGMB "\" arSoundIco[i,2] ; Установка титульной картинки
ButOk := arNameBT[ButtonLng,1] ; Имя кнопки ОК
ButCancel := arNameBT[ButtonLng,2] ; Имя кнопки Cancel
ButYes := arNameBT[ButtonLng,3] ; Имя кнопки Yes
ButNo := arNameBT[ButtonLng,4] ; Имя кнопки No
If (ButtonKey < 0) ; Расчёт позиционировани кнопок
posBT:= "xm y+m" ; Слева
Else
posBT:= "x+m y+m" ; Справа
ButtonKey := Abs(ButtonKey) ;Сброс значения кнопок в абсолютное значение
Gosub lCreateGMB ; Создание окна MsgBox
Gosub lWaitGMB ; Ожидание кода возвората по событию или по тайм-ауту
Return ret
lCreateGMB:
Gui, New , -maximizebox -minimizebox +AlwaysOnTop +Caption, %TittleGMB%
Gui, Font, c%ColorTextGMB% s%SizeTextGMB% w%FontWeightTextGMB%, %FontTextGMB%
Gui, Add, Picture, xm ym, %PicGMB%
Gui, Add, Text,xm, %TextGMB%
Gui, Font, c%ColorButnGMB% s%SizeButnGMB% w%FontWeightButnGMB%, %FontButnGMB%
If (ButtonKey = BtOk)
Gui, Add, Button, section Default %posBT% gSubOk, &%ButOk%
Else If (ButtonKey = BtOkC)
{
Gui, Add, Button, section Default %posBT% gSubOk, &%ButOk%
Gui, Add, Button, section Default x+m gSubCancel, %ButCancel%
}
Else If (ButtonKey = BtYN)
{
Gui, Add, Button, section Default %posBT% gSubYes, &%ButYes%
Gui, Add, Button, section Default x+m gSubNo, %ButNo%
}
Else If (ButtonKey = BtYNC)
{
Gui, Add, Button, section Default %posBT% gSubYes, &%ButYes%
Gui, Add, Button, section Default x+m gSubNo, %ButNo%
Gui, Add, Button, section Default x+m gSubCancel, %ButCancel%
}
Else
{
;Ошибочный код, просто не выводим кнопки, эквивалент BtNot
}
Gui, Show, AutoSize Center
SoundPlay %SoundGMB%
fGMB := False
Return
;Подпрограмма тайм-аута
lWaitGMB:
Loop %DelayGMB% ; N секунд
{
If (fGMB)
Break
Sleep %DelayStep%
}
If (ret = retDef)
ret := retTimeOut
Gui, Cancel
Return
;Подпрограммы событий нажатия на кнопки
SubOk:
ret := retOk
fGMB := True
Return
SubCancel:
ret := retCancel
fGMB := True
Return
SubYes:
ret := retYes
fGMB := True
Return
SubNo:
ret := retNo
fGMB := True
Return
GuiEscape:
ret := retESC
fGMB := True
Return
GuiClose:
ret := retCross
fGMB := True
Return
;Подпрограмма валидности входных данных
lAllCheck:
txtErr1 := "Ошибка в при вызове функциии GMsgBox `n`n"
txtErr2 := "`n`n`n Критическое завершение программы"
If (i < iSetOfButtonMin || i > iSetOfButtonMax)
txtErr0 := "Ошибка в индексе набора звука и иконок"
Else If (DelayGMB<0)
txtErr0 := "Ошибка в задержке, она не должана быть отрпицатильным числом"
Else If (ButtonLng<=0 || ButtonLng>2)
txtErr0 := "Ошибка в индексе языка кнопок"
Else If (fInstall_GMsgBox = False)
txtErr0 := "Ошибка - не проведена ининициализация функции GMsgBox"
Else
Return ; Всё нормально
MsgBox % сMsgOkErModal, Ошибка использования GMsgBox
,%txtErr1% %txtErr0% %txtErr2%
,30
ExitApp
Return
}
;------------------Конец определения функции GMsgBox (Свой MsgBox)------------------
;---------------Addition to the initialization functions of GMsgBox-----------------
lCheckUsedFiles:
; Провеки верности и существования INI-файла, файлов звука и файлов картинок.
vPicGMB := vDirGMB "\GMB.ini"
IfNotExist, %vPicGMB%
{
MsgBox % сMsgOkErModal, Ошибка инициализации GMsgBox
,"Файл " %vPicGMB% "`n Не существует`n Выход из программы."
,30
ExitApp
}
i := iSetOfButtonMin
Loop %iSetOfButtonMax%
{
vKey := arSoundIco[i,3] ; Имя ключа
;-------- Проверка файла звука
IniRead, OutputVar, %vPicGMB%, Sound, %vKey%
If (OutputVar != arSoundIco[i,1])
{
MsgBox % сMsgOkErModal, Ошибка инициализации GMsgBox
,"Неверное названия файла звука " %OutputVar% "`n `n Выход из программы."
,30
ExitApp
}
vDirTmp := vDirGMB "\" OutputVar
IfNotExist, %vPicGMB%
{
MsgBox % сMsgOkErModal, "Ошибка инициализации GMsgBox"
,"Файл звука" %vPicGMB% "`n Не существует`n Выход из программы."
,30
ExitApp
}
;-------- Проверка файла картинки
IniRead, OutputVar, %vPicGMB%, Picture, %vKey%
If (OutputVar != arSoundIco[i,2])
{
MsgBox % сMsgOkErModal, Ошибка инициализации GMsgBox
,"Неверное названия файла картинки " %OutputVar% "`n `n Выход из программы."
,30
ExitApp
}
vDirTmp := vDirGMB "\" OutputVar
IfNotExist, %vPicGMB%
{
MsgBox % сMsgOkErModal, "Ошибка инициализации GMsgBox"
,"Файл картинки" %vPicGMB% "`n Не существует`n Выход из программы."
,30
ExitApp
}
i++
}
Return
;------------End of additions to initialization functions of GMsgBox;---------------
;************************************************************************************
; Конец описания функций
;************************************************************************************
PointBypass_AllAddFunc: