PDA

Показать полную графическую версию : [решено] Зависание скрипта при _Hover_Func


Centrinar
25-03-2011, 16:20
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>
#include "GUICtrlOnHover.au3"
#Region Main form
$hMain_GUI = GUICreate("Главное окно", 300, 200)
$Label = GUICtrlCreateLabel("Настройки", 10, 170, 70, 20)
_GUICtrl_OnHoverRegister($Label, "_Hover_Func", "_Hover_Func")
$nExit_Btn = GUICtrlCreateButton("Выход", 90, 170, 70, 20)
GUISetState(@SW_SHOW, $hMain_GUI)
#EndRegion Main form

#Region Settings form
$hStngs_GUI = GUICreate("Настройки", 400, 200)
$nStngs_Ok_Btn = GUICtrlCreateButton("ОК", 10, 170, 80, 25)
$nStngs_Close_Btn = GUICtrlCreateButton("Закрыть", 310, 170, 80, 25)
#EndRegion Settings form



While 1
$aMsg = GUIGetMsg(1) ;Расширенная обработка событий

Switch $aMsg[0]
Case $GUI_EVENT_CLOSE, $nExit_Btn, $nStngs_Close_Btn
Switch $aMsg[1]
Case $hMain_GUI ;Событие поступило от главного окна - завершаем работу скрипта
Exit
Case $hStngs_GUI ;Событие поступило от окна настроек - закрываем его
GUISetState(@SW_HIDE, $hStngs_GUI)
EndSwitch
Case $Label
GUISetState(@SW_SHOW, $hStngs_GUI)
EndSwitch
WEnd

Func _Hover_Func($iCtrlID, $iParam)
Local $sConsole_Data = "Hovered"

Local $sButton_Text = "Hover Button"
Local $iLabel_Color = 0x00000FF
Local $iLabel_FontAttrib = 4
Local $iCheckBox_State = $GUI_CHECKED
Local $sEdit_Data = "New Edit Data"

If $iParam = 2 Then ;Indicates On *Leave* Hover process
$sConsole_Data = "NOT Hovered"

$sButton_Text = "Button"
$iLabel_Color = 0x000000
$iLabel_FontAttrib = 0
$iCheckBox_State = $GUI_UNCHECKED
$sEdit_Data = "Edit Data"
EndIf

Printf("Control " & $iCtrlID & " [Data: " & GUICtrlRead($iCtrlID, 1) & "] Is Now " & $sConsole_Data)

Switch $iCtrlID
Case $Button
If GUICtrlRead($iCtrlID) <> $sButton_Text Then GUICtrlSetData($iCtrlID, $sButton_Text)
Case $Label
GUICtrlSetColor($iCtrlID, $iLabel_Color)
GUICtrlSetFont($iCtrlID, Default, Default, $iLabel_FontAttrib)
Case $CheckBox
GUICtrlSetState($iCtrlID, $iCheckBox_State)
Case $Edit
If GUICtrlRead($iCtrlID) <> $sEdit_Data Then GUICtrlSetData($iCtrlID, $sEdit_Data)
EndSwitch
EndFunc

Func Printf($Str, $Line=@ScriptLineNumber)
ConsoleWrite("!===========================================================" & @LF & _
"+======================================================" & @LF & _
"--> Script Line (" & $Line & "):" & @LF & "!" & @TAB & $Str & @LF & _
"+======================================================" & @LF)
EndFunc

Собственно сабж, скрипт просто виснет

Creat0R
25-03-2011, 17:54
Вообще то сначала нужно проверять скрипт на ошибки синтаксиса, а потом писать что скрипт виснет.
Конечно он виснет, ошибка гинерируется внутри callback-функций, это один из (мелких я бы сказал) недостатков обработчика ошибок в AutoIt.

В скрипте проверяется $Button, $CheckBox и $Edit, которые нигде не объявлены.

#include (http://www.autoitscript.com/autoit3/docs/keywords.htm##include) <ButtonConstants.au3>
#include (http://www.autoitscript.com/autoit3/docs/keywords.htm##include) <GUIConstantsEx.au3>
#include (http://www.autoitscript.com/autoit3/docs/keywords.htm##include) <WindowsConstants.au3>
#include (http://www.autoitscript.com/autoit3/docs/keywords.htm##include) <GUIConstantsEx.au3>
#include (http://www.autoitscript.com/autoit3/docs/keywords.htm##include) "GUICtrlOnHover.au3"

#Region Main form
$hMain_GUI = GUICreate (http://www.autoitscript.com/autoit3/docs/functions/GUICreate.htm)("Главное окно", 300, 200)
$Label = GUICtrlCreateLabel (http://www.autoitscript.com/autoit3/docs/functions/GUICtrlCreateLabel.htm)("Настройки", 10, 170, 55, 20)
GUICtrlSetFont (http://www.autoitscript.com/autoit3/docs/functions/GUICtrlSetFont.htm)($Label, 8.5, 400, 0)
_GUICtrl_OnHoverRegister($Label, "_Hover_Func", "_Hover_Func")
$nExit_Btn = GUICtrlCreateButton (http://www.autoitscript.com/autoit3/docs/functions/GUICtrlCreateButton.htm)("Выход", 90, 170, 70, 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 form

#Region Settings form
$hStngs_GUI = GUICreate (http://www.autoitscript.com/autoit3/docs/functions/GUICreate.htm)("Настройки", 400, 200)
$nStngs_Ok_Btn = GUICtrlCreateButton (http://www.autoitscript.com/autoit3/docs/functions/GUICtrlCreateButton.htm)("ОК", 10, 170, 80, 25)
$nStngs_Close_Btn = GUICtrlCreateButton (http://www.autoitscript.com/autoit3/docs/functions/GUICtrlCreateButton.htm)("Закрыть", 310, 170, 80, 25)
#EndRegion Settings form


While (http://www.autoitscript.com/autoit3/docs/keywords.htm#While) 1
$aMsg = GUIGetMsg (http://www.autoitscript.com/autoit3/docs/functions/GUIGetMsg.htm)(1) ;Расширенная обработка событий

Switch (http://www.autoitscript.com/autoit3/docs/keywords.htm#Switch) $aMsg[0]
Case (http://www.autoitscript.com/autoit3/docs/keywords.htm#Case) $GUI_EVENT_CLOSE, $nExit_Btn, $nStngs_Close_Btn
Switch (http://www.autoitscript.com/autoit3/docs/keywords.htm#Switch) $aMsg[1]
Case (http://www.autoitscript.com/autoit3/docs/keywords.htm#Case) $hMain_GUI ;Событие поступило от главного окна - завершаем работу скрипта
Exit (http://www.autoitscript.com/autoit3/docs/keywords.htm#Exit)
Case (http://www.autoitscript.com/autoit3/docs/keywords.htm#Case) $hStngs_GUI ;Событие поступило от окна настроек - закрываем его
GUISetState (http://www.autoitscript.com/autoit3/docs/functions/GUISetState.htm)(@SW_HIDE (http://www.autoitscript.com/autoit3/docs/macros.htm#@sw_hide), $hStngs_GUI)
EndSwitch (http://www.autoitscript.com/autoit3/docs/keywords.htm#EndSwitch)
Case (http://www.autoitscript.com/autoit3/docs/keywords.htm#Case) $Label
GUISetState (http://www.autoitscript.com/autoit3/docs/functions/GUISetState.htm)(@SW_SHOW (http://www.autoitscript.com/autoit3/docs/macros.htm#@sw_show), $hStngs_GUI)
EndSwitch (http://www.autoitscript.com/autoit3/docs/keywords.htm#EndSwitch)
WEnd (http://www.autoitscript.com/autoit3/docs/keywords.htm#WEnd)

Func (http://www.autoitscript.com/autoit3/docs/keywords.htm#Func) _Hover_Func($iCtrlID, $iParam)
Local (http://www.autoitscript.com/autoit3/docs/keywords.htm#Local) $sConsole_Data = "Hovered"
Local (http://www.autoitscript.com/autoit3/docs/keywords.htm#Local) $iLabel_Color = 0x00000FF
Local (http://www.autoitscript.com/autoit3/docs/keywords.htm#Local) $iLabel_FontAttrib = 4
Local (http://www.autoitscript.com/autoit3/docs/keywords.htm#Local) $iLabel_CursorID = 0

If (http://www.autoitscript.com/autoit3/docs/keywords.htm#If) $iParam = 2 Then (http://www.autoitscript.com/autoit3/docs/keywords.htm#Then) ;Indicates On *Leave* Hover process
$sConsole_Data = "NOT Hovered"

$iLabel_Color = 0x000000
$iLabel_FontAttrib = 0
$iLabel_CursorID = -1
EndIf (http://www.autoitscript.com/autoit3/docs/keywords.htm#EndIf)

Printf("Control " & $iCtrlID & " [Data: " & GUICtrlRead (http://www.autoitscript.com/autoit3/docs/functions/GUICtrlRead.htm)($iCtrlID, 1) & "] Is Now " & $sConsole_Data)

Switch (http://www.autoitscript.com/autoit3/docs/keywords.htm#Switch) $iCtrlID
Case (http://www.autoitscript.com/autoit3/docs/keywords.htm#Case) $Label
GUICtrlSetColor (http://www.autoitscript.com/autoit3/docs/functions/GUICtrlSetColor.htm)($iCtrlID, $iLabel_Color)
GUICtrlSetFont (http://www.autoitscript.com/autoit3/docs/functions/GUICtrlSetFont.htm)($iCtrlID, 8.5, 400, $iLabel_FontAttrib)
GUICtrlSetCursor (http://www.autoitscript.com/autoit3/docs/functions/GUICtrlSetCursor.htm)($iCtrlID, $iLabel_CursorID)
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) Printf($Str, $Line=@ScriptLineNumber (http://www.autoitscript.com/autoit3/docs/macros.htm#@scriptlinenumber))
ConsoleWrite (http://www.autoitscript.com/autoit3/docs/functions/ConsoleWrite.htm)("!===========================================================" & @LF (http://www.autoitscript.com/autoit3/docs/macros.htm#@lf) & _
"+======================================================" & @LF (http://www.autoitscript.com/autoit3/docs/macros.htm#@lf) & _
"--> Script Line (" & $Line & "):" & @LF (http://www.autoitscript.com/autoit3/docs/macros.htm#@lf) & "!" & @TAB (http://www.autoitscript.com/autoit3/docs/macros.htm#@tab) & $Str & @LF (http://www.autoitscript.com/autoit3/docs/macros.htm#@lf) & _
"+======================================================" & @LF (http://www.autoitscript.com/autoit3/docs/macros.htm#@lf))
EndFunc (http://www.autoitscript.com/autoit3/docs/keywords.htm#EndFunc)

Creat0R
25-03-2011, 18:13
Кстати, в данном случае наверное будет лучше использовать _GUICtrlHyperlink (http://autoit-script.ru/index.php?topic=1587.msg11362#msg11362) для ссылки, и возможностей больше.

madmasles
25-03-2011, 18:53
Centrinar,
А что такое Засисание...
:laugh:

Centrinar
25-03-2011, 20:25
Как сделать фон прозрачным GUISetBkColor ($iCtrlID, $GUI_BKCOLOR_TRANSPARENT) не помогает

madmasles
25-03-2011, 20:51
Как сделать фон прозрачным »
Если я правильно Вас понял:#include (http://www.autoitscript.com/autoit3/docs/keywords.htm##include) <GUIConstantsEx.au3>

$hGui = GUICreate (http://www.autoitscript.com/autoit3/docs/functions/GUICreate.htm)('Test', 220, 100)
GUISetBkColor (http://www.autoitscript.com/autoit3/docs/functions/GUISetBkColor.htm)(0xE0FFFF)
$nSlider = GUICtrlCreateSlider (http://www.autoitscript.com/autoit3/docs/functions/GUICtrlCreateSlider.htm)(10, 10, 200, 20)
GUICtrlSetLimit (http://www.autoitscript.com/autoit3/docs/functions/GUICtrlSetLimit.htm)(-1, 255, 55)
GUICtrlSetData (http://www.autoitscript.com/autoit3/docs/functions/GUICtrlSetData.htm)($nSlider, 255)
GUISetState (http://www.autoitscript.com/autoit3/docs/functions/GUISetState.htm)()

While (http://www.autoitscript.com/autoit3/docs/keywords.htm#While) 1
$nMsg = GUIGetMsg (http://www.autoitscript.com/autoit3/docs/functions/GUIGetMsg.htm)()
Switch (http://www.autoitscript.com/autoit3/docs/keywords.htm#Switch) $nMsg
Case (http://www.autoitscript.com/autoit3/docs/keywords.htm#Case) $GUI_EVENT_CLOSE
Exit (http://www.autoitscript.com/autoit3/docs/keywords.htm#Exit)
Case (http://www.autoitscript.com/autoit3/docs/keywords.htm#Case) $nSlider
WinSetTrans (http://www.autoitscript.com/autoit3/docs/functions/WinSetTrans.htm)($hGui, '', GUICtrlRead (http://www.autoitscript.com/autoit3/docs/functions/GUICtrlRead.htm)($nSlider))
EndSwitch (http://www.autoitscript.com/autoit3/docs/keywords.htm#EndSwitch)
WEnd (http://www.autoitscript.com/autoit3/docs/keywords.htm#WEnd)

PS
Лучше было бы в новой теме вопрос задать.

Centrinar
25-03-2011, 20:58
фон лайбла

Creat0R
25-03-2011, 21:36
Как сделать фон прозрачным »
При чём тут эта тема?




© OSzone.net 2001-2012