saavaage
18-08-2010, 01:24
Вопрос в различии между этими 2-мя режимами и их применением в ситуации, когда форма содержит Tab с вкладками и кнопками на каждой из них, а также общие кнопки для всей формы.
Изучил справку по этим 2-м режимам (rus). Но остался ряд вопросов:
1. OnEvent Mode прерывает выполнение скрипта на время выполнения события. В справке нет ответа как действует в этом случае MessageLoop?
2. Не совсем понятна фраза справки: "Обработка сообщений в режиме опроса требует обеспечения высокой скорости чтения вызовом GUIGetMsg и последующей обработки полученных сообщений. Иначе не все события будут обработаны." Что означает "высокой скорости чтения вызовом GUIGetMsg"? Значит ли это, что машина со старым процессором может отработать скрипт неполностью (особенно если в цикле много case)?
3. В справке указано, что MessageLoop, не смотря на цикл, не грузит процессор. Насколько я понял, OnEvent Mode, не является циклическим процессом и срабатывает только при активации пользователем. Логично предположить, что он также не грузит процессор. Я прав?
4. Для меня осталось не совсем понятно, в чем принципиальное отличие этих 2-х режимов? Они выполняют одну и туже функцию, без особой нагрузки на процессор... Какой режим когда лучше, в таком случае, применять? Какой из них менее ресурсоемкий и более надежный?
5. Если брать мой частный случай, то меня конкретно интересует следующее: если гуи-форма содержит много кнопок на разных вкладках + общие кнопки, то как будет лучше действовать:
- использовать вариант MessageLoop - для общих кнопок, а вариант OnEvent Mode - для кнопок на конкретной вкладке
- лучше использовать только вариант MessageLoop
- лучше использовать только вариант OnEvent Mode
- все равно
Если можно, прокомментируйте свои ответы (особенно на вопрос #5).
Заранее благодарю за помощь.
Немного по теме: http://autoit-script.ru/index.php/topic,459.0.htmlкак действует в этом случае MessageLoop? »
Смотря что в нём происходит, если дополнительный цикл, тогда будет также останавливать.
Значит ли это, что машина со старым процессором может отработать скрипт неполностью »
Не сталкивался с подобным, не должно оно влиять. В любом случае GUIGetMsg содержит в себе паузу примерно в 10 мс, поэтому добавлять паузы в цикл больше не нужно.
В справке указано, что MessageLoop, не смотря на цикл, не грузит процессор »
Ну если в цикле нет паузы (Sleep) и не опрашивается с GUIGetMsg, то нагрузка будет).
Логично предположить, что он также не грузит процессор. Я прав? »
Логично, событие вызывается при неком действий, а цикл проверяет всегда (если скрипт не блокируется функцией).
Какой из них менее ресурсоемкий и более надежный? »
Вместе не получится, нужно разделить два этих критерия :) MessageLoop надёжнее в плане удобства и доступности, но в то же время он может быть ресурсоёмким. А режим OnEvent он более сложный для работы с многими окнами и элементами, однако ресурсов в большинстве случаев потребляет меньше... хотя это всё поддаётся сравнению, прочитайте тему по ссылке что я привёл в начале, там это расписано.
использовать вариант MessageLoop - для общих кнопок, а вариант OnEvent Mode - для кнопок на конкретной вкладке »
Это как? :) совмещать режимы для одного GUI не получится.
лучше использовать только вариант MessageLoop »
Если нет дочерних окон, то да.
лучше использовать только вариант OnEvent Mode »
Если есть дочерние окна которые создаются по запросу (по кнопке, в функций к примеру).
все равно »
Можно и так :unsure:
saavaage
18-08-2010, 11:20
Creat0R, спасибо за развернутый ответ. Есть еще один вопрос по форме с вкладками: как сделать так, чтобы скрипты, находящиеся в привязке к определенной вкладке Tab, отрабатывали только тогда, когда я перехожу на эту вкладку (делаю ее активной), а не при загрузке всей формы. Просто, при большом количестве вкладок и скриптов, вся прога грузится довольно долго, пока не обработаются все скрипты вкладок.
Спасибо
Есть еще один вопрос по форме с вкладками »
Этот вопрос заслуживает отдельной темы (где не помешало бы выложить пример этой самой формы).
saavaage
18-08-2010, 20:34
Creat0R, так точно, сэр :-). Закрываю.
saavaage
21-08-2010, 01:16
Creat0R, извините, но обнаружил на русском форуме Autoit Ваше высказывание на тему MessageLoop vs OnEvent Mode:
пост http://autoit-script.ru/index.php/topic,459.0.html
цитата: "Это всё зависит от поставленной задачи. Иногда лучше использовать MessageLoop (например если некие элементы вызывают дочернее окно которое также требует обработку событий), а иногда лучше OnEvent. "
Оно противоречит Вашему ответу в текущем посте:
лучше использовать только вариант MessageLoop »
Если нет дочерних окон, то да. »
Дело в том, что я планирую делать подчиненное окно с настройками утилиты, где будут:
выпадающий список (combo), внесение твика в реестр (прописывание в автозагрузке), кнопка сохранения и закрытия
и для меня очень важно сразу определиться какой режим лучше использовать, чтобы потом не переделывать скрипт.
Спасибо
Оно противоречит Вашему ответу в этом посте »
И в чём же противоречие? и там и там я пишу про то что в неких ситуациях лучше использовать «MessageLoop».
я планирую делать подчиненное окно с настройками утилиты »
Вариант с MessageLoop:
#include (http://www.autoitscript.com/autoit3/docs/keywords.htm##include) <GUIConstantsEx.au3>
#include (http://www.autoitscript.com/autoit3/docs/keywords.htm##include) <WindowsConstants.au3>
#Region Main GUI
$hMain_GUI = GUICreate (http://www.autoitscript.com/autoit3/docs/functions/GUICreate.htm)("My Program", 500, 300)
$nMain_Exit_Button = GUICtrlCreateButton (http://www.autoitscript.com/autoit3/docs/functions/GUICtrlCreateButton.htm)("Exit", 20, 270, 60, 20)
$nMain_Settings_Button = GUICtrlCreateButton (http://www.autoitscript.com/autoit3/docs/functions/GUICtrlCreateButton.htm)("Settings", 90, 270, 60, 20)
GUISetState (http://www.autoitscript.com/autoit3/docs/functions/GUISetState.htm)(@SW_SHOW (http://www.autoitscript.com/autoit3/docs/macros.htm#@sw_show), $hMain_GUI)
#EndRegion Main GUI
#Region Settings GUI
$hSettings_GUI = GUICreate (http://www.autoitscript.com/autoit3/docs/functions/GUICreate.htm)("Settings", 400, 250, -1, -1, -1, -1, $hMain_GUI)
$nStngs_Close_Button = GUICtrlCreateButton (http://www.autoitscript.com/autoit3/docs/functions/GUICtrlCreateButton.htm)("Close", 20, 220, 60, 20)
$nStngs_Save_Button = GUICtrlCreateButton (http://www.autoitscript.com/autoit3/docs/functions/GUICtrlCreateButton.htm)("Save", 90, 220, 60, 20)
#EndRegion Settings GUI
While (http://www.autoitscript.com/autoit3/docs/keywords.htm#While) 1
$nMsg = GUIGetMsg (http://www.autoitscript.com/autoit3/docs/functions/GUIGetMsg.htm)(1)
Switch (http://www.autoitscript.com/autoit3/docs/keywords.htm#Switch) $nMsg[0]
Case (http://www.autoitscript.com/autoit3/docs/keywords.htm#Case) $GUI_EVENT_CLOSE, $nStngs_Close_Button, $nMain_Exit_Button
If (http://www.autoitscript.com/autoit3/docs/keywords.htm#If) $nMsg[1] = $hSettings_GUI Then (http://www.autoitscript.com/autoit3/docs/keywords.htm#Then)
GUISetState (http://www.autoitscript.com/autoit3/docs/functions/GUISetState.htm)(@SW_ENABLE (http://www.autoitscript.com/autoit3/docs/macros.htm#@sw_enable), $hMain_GUI)
GUISetState (http://www.autoitscript.com/autoit3/docs/functions/GUISetState.htm)(@SW_HIDE (http://www.autoitscript.com/autoit3/docs/macros.htm#@sw_hide), $hSettings_GUI)
Else (http://www.autoitscript.com/autoit3/docs/keywords.htm#Else)
Exit (http://www.autoitscript.com/autoit3/docs/keywords.htm#Exit)
EndIf (http://www.autoitscript.com/autoit3/docs/keywords.htm#EndIf)
Case (http://www.autoitscript.com/autoit3/docs/keywords.htm#Case) $nMain_Settings_Button
GUISetState (http://www.autoitscript.com/autoit3/docs/functions/GUISetState.htm)(@SW_DISABLE (http://www.autoitscript.com/autoit3/docs/macros.htm#@sw_disable), $hMain_GUI)
GUISetState (http://www.autoitscript.com/autoit3/docs/functions/GUISetState.htm)(@SW_SHOW (http://www.autoitscript.com/autoit3/docs/macros.htm#@sw_show), $hSettings_GUI)
Case (http://www.autoitscript.com/autoit3/docs/keywords.htm#Case) $nStngs_Save_Button
MsgBox (http://www.autoitscript.com/autoit3/docs/functions/MsgBox.htm)(64, 'Title', 'Settings saved!', 0, $hSettings_GUI)
EndSwitch (http://www.autoitscript.com/autoit3/docs/keywords.htm#EndSwitch)
WEnd (http://www.autoitscript.com/autoit3/docs/keywords.htm#WEnd)
Вариант с OnEvent:
#include (http://www.autoitscript.com/autoit3/docs/keywords.htm##include) <GUIConstantsEx.au3>
#include (http://www.autoitscript.com/autoit3/docs/keywords.htm##include) <WindowsConstants.au3>
Opt (http://www.autoitscript.com/autoit3/docs/functions/Opt.htm)("GUIOnEventMode", 1)
#Region Main GUI
$hMain_GUI = GUICreate (http://www.autoitscript.com/autoit3/docs/functions/GUICreate.htm)("My Program", 500, 300)
$nMain_Exit_Button = GUICtrlCreateButton (http://www.autoitscript.com/autoit3/docs/functions/GUICtrlCreateButton.htm)("Exit", 20, 270, 60, 20)
$nMain_Settings_Button = GUICtrlCreateButton (http://www.autoitscript.com/autoit3/docs/functions/GUICtrlCreateButton.htm)("Settings", 90, 270, 60, 20)
GUICtrlSetOnEvent (http://www.autoitscript.com/autoit3/docs/functions/GUICtrlSetOnEvent.htm)($nMain_Exit_Button, "_MainGUI_Events")
GUICtrlSetOnEvent (http://www.autoitscript.com/autoit3/docs/functions/GUICtrlSetOnEvent.htm)($nMain_Settings_Button, "_MainGUI_Events")
GUISetOnEvent (http://www.autoitscript.com/autoit3/docs/functions/GUISetOnEvent.htm)($GUI_EVENT_CLOSE, "_MainGUI_Events", $hMain_GUI)
GUISetState (http://www.autoitscript.com/autoit3/docs/functions/GUISetState.htm)(@SW_SHOW (http://www.autoitscript.com/autoit3/docs/macros.htm#@sw_show), $hMain_GUI)
#EndRegion Main GUI
#Region Settings GUI
$hSettings_GUI = GUICreate (http://www.autoitscript.com/autoit3/docs/functions/GUICreate.htm)("Settings", 400, 250, -1, -1, -1, -1, $hMain_GUI)
$nStngs_Close_Button = GUICtrlCreateButton (http://www.autoitscript.com/autoit3/docs/functions/GUICtrlCreateButton.htm)("Close", 20, 220, 60, 20)
$nStngs_Save_Button = GUICtrlCreateButton (http://www.autoitscript.com/autoit3/docs/functions/GUICtrlCreateButton.htm)("Save", 90, 220, 60, 20)
GUICtrlSetOnEvent (http://www.autoitscript.com/autoit3/docs/functions/GUICtrlSetOnEvent.htm)($nStngs_Close_Button, "_SettingsGUI_Events")
GUICtrlSetOnEvent (http://www.autoitscript.com/autoit3/docs/functions/GUICtrlSetOnEvent.htm)($nStngs_Save_Button, "_SettingsGUI_Events")
GUISetOnEvent (http://www.autoitscript.com/autoit3/docs/functions/GUISetOnEvent.htm)($GUI_EVENT_CLOSE, "_SettingsGUI_Events", $hSettings_GUI)
#EndRegion Settings GUI
While (http://www.autoitscript.com/autoit3/docs/keywords.htm#While) 1
Sleep (http://www.autoitscript.com/autoit3/docs/functions/Sleep.htm)(100)
WEnd (http://www.autoitscript.com/autoit3/docs/keywords.htm#WEnd)
Func (http://www.autoitscript.com/autoit3/docs/keywords.htm#Func) _MainGUI_Events()
Switch (http://www.autoitscript.com/autoit3/docs/keywords.htm#Switch) @GUI_CtrlId (http://www.autoitscript.com/autoit3/docs/macros.htm#@gui_ctrlid)
Case (http://www.autoitscript.com/autoit3/docs/keywords.htm#Case) $GUI_EVENT_CLOSE, $nMain_Exit_Button
Exit (http://www.autoitscript.com/autoit3/docs/keywords.htm#Exit)
Case (http://www.autoitscript.com/autoit3/docs/keywords.htm#Case) $nMain_Settings_Button
GUISetState (http://www.autoitscript.com/autoit3/docs/functions/GUISetState.htm)(@SW_DISABLE (http://www.autoitscript.com/autoit3/docs/macros.htm#@sw_disable), $hMain_GUI)
GUISetState (http://www.autoitscript.com/autoit3/docs/functions/GUISetState.htm)(@SW_SHOW (http://www.autoitscript.com/autoit3/docs/macros.htm#@sw_show), $hSettings_GUI)
EndSwitch (http://www.autoitscript.com/autoit3/docs/keywords.htm#EndSwitch)
EndFunc (http://www.autoitscript.com/autoit3/docs/keywords.htm#EndFunc)
Func (http://www.autoitscript.com/autoit3/docs/keywords.htm#Func) _SettingsGUI_Events()
Switch (http://www.autoitscript.com/autoit3/docs/keywords.htm#Switch) @GUI_CtrlId (http://www.autoitscript.com/autoit3/docs/macros.htm#@gui_ctrlid)
Case (http://www.autoitscript.com/autoit3/docs/keywords.htm#Case) $GUI_EVENT_CLOSE, $nStngs_Close_Button
GUISetState (http://www.autoitscript.com/autoit3/docs/functions/GUISetState.htm)(@SW_ENABLE (http://www.autoitscript.com/autoit3/docs/macros.htm#@sw_enable), $hMain_GUI)
GUISetState (http://www.autoitscript.com/autoit3/docs/functions/GUISetState.htm)(@SW_HIDE (http://www.autoitscript.com/autoit3/docs/macros.htm#@sw_hide), $hSettings_GUI)
Case (http://www.autoitscript.com/autoit3/docs/keywords.htm#Case) $nStngs_Save_Button
MsgBox (http://www.autoitscript.com/autoit3/docs/functions/MsgBox.htm)(64, 'Title', 'Settings saved!', 0, $hSettings_GUI)
EndSwitch (http://www.autoitscript.com/autoit3/docs/keywords.htm#EndSwitch)
EndFunc (http://www.autoitscript.com/autoit3/docs/keywords.htm#EndFunc)
Хотя я лично предпочитаю в таком случае создавать GUI в функций, и временно изменить с OnEvent на MessageLoop, так мне кажется удобнее, тем более что так меньше ресурсов потребляет:
#include (http://www.autoitscript.com/autoit3/docs/keywords.htm##include) <GUIConstantsEx.au3>
#include (http://www.autoitscript.com/autoit3/docs/keywords.htm##include) <WindowsConstants.au3>
Opt (http://www.autoitscript.com/autoit3/docs/functions/Opt.htm)("GUIOnEventMode", 1)
#Region Main GUI
$hMain_GUI = GUICreate (http://www.autoitscript.com/autoit3/docs/functions/GUICreate.htm)("My Program", 500, 300)
$nExit_Button = GUICtrlCreateButton (http://www.autoitscript.com/autoit3/docs/functions/GUICtrlCreateButton.htm)("Exit", 20, 270, 60, 20)
$nSettings_Button = GUICtrlCreateButton (http://www.autoitscript.com/autoit3/docs/functions/GUICtrlCreateButton.htm)("Settings", 90, 270, 60, 20)
GUICtrlSetOnEvent (http://www.autoitscript.com/autoit3/docs/functions/GUICtrlSetOnEvent.htm)($nExit_Button, "_MainGUI_Events")
GUICtrlSetOnEvent (http://www.autoitscript.com/autoit3/docs/functions/GUICtrlSetOnEvent.htm)($nSettings_Button, "_MainGUI_Events")
GUISetOnEvent (http://www.autoitscript.com/autoit3/docs/functions/GUISetOnEvent.htm)($GUI_EVENT_CLOSE, "_MainGUI_Events", $hMain_GUI)
GUISetState (http://www.autoitscript.com/autoit3/docs/functions/GUISetState.htm)(@SW_SHOW (http://www.autoitscript.com/autoit3/docs/macros.htm#@sw_show), $hMain_GUI)
#EndRegion Main GUI
While (http://www.autoitscript.com/autoit3/docs/keywords.htm#While) 1
Sleep (http://www.autoitscript.com/autoit3/docs/functions/Sleep.htm)(100)
WEnd (http://www.autoitscript.com/autoit3/docs/keywords.htm#WEnd)
Func (http://www.autoitscript.com/autoit3/docs/keywords.htm#Func) _MainGUI_Events()
Switch (http://www.autoitscript.com/autoit3/docs/keywords.htm#Switch) @GUI_CtrlId (http://www.autoitscript.com/autoit3/docs/macros.htm#@gui_ctrlid)
Case (http://www.autoitscript.com/autoit3/docs/keywords.htm#Case) $GUI_EVENT_CLOSE, $nExit_Button
Exit (http://www.autoitscript.com/autoit3/docs/keywords.htm#Exit)
Case (http://www.autoitscript.com/autoit3/docs/keywords.htm#Case) $nSettings_Button
_Settings_GUI($hMain_GUI)
EndSwitch (http://www.autoitscript.com/autoit3/docs/keywords.htm#EndSwitch)
EndFunc (http://www.autoitscript.com/autoit3/docs/keywords.htm#EndFunc)
Func (http://www.autoitscript.com/autoit3/docs/keywords.htm#Func) _Settings_GUI($hParent)
Local (http://www.autoitscript.com/autoit3/docs/keywords.htm#Local) $iOpt_GOEM, $hSettings_GUI, $nStngs_Close_Button, $nStngs_Save_Button
$iOpt_GOEM = Opt (http://www.autoitscript.com/autoit3/docs/functions/Opt.htm)("GUIOnEventMode", 0)
$hSettings_GUI = GUICreate (http://www.autoitscript.com/autoit3/docs/functions/GUICreate.htm)("Settings", 400, 250, -1, -1, -1, -1, $hParent)
$nStngs_Close_Button = GUICtrlCreateButton (http://www.autoitscript.com/autoit3/docs/functions/GUICtrlCreateButton.htm)("Close", 20, 220, 60, 20)
$nStngs_Save_Button = GUICtrlCreateButton (http://www.autoitscript.com/autoit3/docs/functions/GUICtrlCreateButton.htm)("Save", 90, 220, 60, 20)
GUISetState (http://www.autoitscript.com/autoit3/docs/functions/GUISetState.htm)(@SW_DISABLE (http://www.autoitscript.com/autoit3/docs/macros.htm#@sw_disable), $hParent)
GUISetState (http://www.autoitscript.com/autoit3/docs/functions/GUISetState.htm)(@SW_SHOW (http://www.autoitscript.com/autoit3/docs/macros.htm#@sw_show), $hSettings_GUI)
While (http://www.autoitscript.com/autoit3/docs/keywords.htm#While) 1
Switch (http://www.autoitscript.com/autoit3/docs/keywords.htm#Switch) GUIGetMsg (http://www.autoitscript.com/autoit3/docs/functions/GUIGetMsg.htm)()
Case (http://www.autoitscript.com/autoit3/docs/keywords.htm#Case) $GUI_EVENT_CLOSE, $nStngs_Close_Button
ExitLoop (http://www.autoitscript.com/autoit3/docs/keywords.htm#ExitLoop)
Case (http://www.autoitscript.com/autoit3/docs/keywords.htm#Case) $nStngs_Save_Button
MsgBox (http://www.autoitscript.com/autoit3/docs/functions/MsgBox.htm)(64, 'Title', 'Settings saved!', 0, $hSettings_GUI)
EndSwitch (http://www.autoitscript.com/autoit3/docs/keywords.htm#EndSwitch)
WEnd (http://www.autoitscript.com/autoit3/docs/keywords.htm#WEnd)
GUISetState (http://www.autoitscript.com/autoit3/docs/functions/GUISetState.htm)(@SW_ENABLE (http://www.autoitscript.com/autoit3/docs/macros.htm#@sw_enable), $hParent)
GUISetState (http://www.autoitscript.com/autoit3/docs/functions/GUISetState.htm)(@SW_HIDE (http://www.autoitscript.com/autoit3/docs/macros.htm#@sw_hide), $hSettings_GUI)
Opt (http://www.autoitscript.com/autoit3/docs/functions/Opt.htm)("GUIOnEventMode", $iOpt_GOEM)
EndFunc (http://www.autoitscript.com/autoit3/docs/keywords.htm#EndFunc)
Выбирай :)
saavaage
21-08-2010, 04:47
Creat0R, большое спасибо (особенно за 3 вариант)
PS противоречие было в том, что в первой цитате Вы рекомендовали использовать MessageLoop с дочерними окнами, а во-второй, наоборот, если нет дочерних окон.
Не заглянете в тему http://forum.oszone.net/thread-182740.html ? Там у нас небольшая проблема возникла с ограничением вывода инфо в ListViewItem
противоречие было в том, что в первой цитате Вы рекомендовали использовать MessageLoop с дочерними окнами, а во-второй, наоборот, если нет дочерних окон. »
Там речь шла про события, это именно тот случай когда «всё зависит от поставленной задачи» ;).
Не заглянете в тем »
Заглянул :)
vBulletin v3.6.4, Copyright ©2000-2025, Jelsoft Enterprises Ltd.
Available in ZeroNet 1osznRoVratMCN3bFoFpR2pSV5c9z6sTC