Войти

Показать полную графическую версию : Объёденить 2 скрипта в один


sashadeg
16-11-2009, 13:07
Подскажите, как объёденить 2 скрипта в 1.


Вот моя ситуация:

У меня в программе имеется msgbox в котором кнопка "Да" должна сама нажаться через 5 сек, если не нажали кнопку "Нет"...

Для этого программа перед появлением msgbox'a запускает вторую прогут которая сначало изменяет текст кнопки "Да" на текст "Да [4]", потом текст кнопки изменяет на "Да [3]" и так далее... а потом как будет "Да [1]" нажмёт кнопку сама...

Вот код 2 программы для ясности:
If WinExists(@ScriptName) Then
Exit
EndIf
AutoItWinSetTitle(@ScriptName)
Opt("TrayIconHide", 1)
ControlSetText("программа","","&Да","Да [5]")
sleep(1000)
ControlSetText("программа","","Да [5]","Да [4]")
sleep(1000)
ControlSetText("программа","","Да [4]","Да [3]")
sleep(1000)
ControlSetText("программа","","Да [3]","Да [2]")
sleep(1000)
ControlSetText("программа","","Да [2]","Да [1]")
sleep(1000)
ControlClick("программа","","Да [1]")


Код программы в которой имеется msgbox я думаю будет лишним...

Лично у меня проблема возникла в том, что скрипт после появления msgbox'a останавливает свою работу, пока в окне не нажать какуюнибудь кнопку, чтобы окно закрылось... И в следствии у меня не получается "держать" 2 процесса в 1 программе: Держать окно и в то же время изменять в нем текст кнопки...

Заранее спасибо!

FlatX007
16-11-2009, 17:47
(С) - CreatOR
http://forum.oszone.net/thread-149514.html
Global $subject = "Заголовок", $sms = "Проверка"
Global $Wait = 10
Global $smsWinTitle = "Оповещение SMS"
Global $smsMessage = _
'Тема: ' & $subject & @CRLF & 'Сообщение: ' & $sms & @CRLF & 'Время до отправки SMS: %s' & @CRLF & _
'сек. ' & @CRLF & @CRLF & 'Нажмите Отмена, если Вы НЕ хотите получить эту СМС'

$isSend = _MsgBoxTimer(1, $smsWinTitle, $smsMessage, $Wait)

Func _MsgBoxTimer($iFlag, $sTitle, $sText, $iMBTimeOut = 0, $hWnd=0)
Local $hFile, $sMBLine, $sSet_Text, $iRet

$sSet_Text = StringReplace($sText, @CRLF, '\n')

$sMBLine = '#NoTrayIcon' & @CRLF
$sMBLine &= 'Opt("WinWaitDelay", 1)' & @CRLF
$sMBLine &= 'While Not WinExists("' & $sTitle & '")' & @CRLF
$sMBLine &= ' Sleep(10)' & @CRLF
$sMBLine &= 'WEnd' & @CRLF
$sMBLine &= 'ControlSetText("' & $sTitle & '", "", "Static1", StringFormat("' & $sSet_Text & '", ' & $iMBTimeOut & '))' & @CRLF

If $iMBTimeOut > 0 Then
$sMBLine &= _
'$TimerInit = TimerInit()' & @CRLF & _
'$iTime = ' & $iMBTimeOut & @CRLF & _
'While $iTime > 0' & @CRLF & _
' ControlSetText("' & $sTitle & '", "", "Static1", StringFormat("' & $sSet_Text & '", $iTime))' & @CRLF & _
' If Not WinExists("' & $sTitle & '") Then ExitLoop' & @CRLF & _
' Sleep(1000)' & @CRLF & _
' $iTime -= 1' & @CRLF & _
'WEnd'
EndIf

$hFile = FileOpen(@TempDir & '\MiscMMB.tmp', 2)
FileWrite($hFile, $sMBLine)
FileClose($hFile)

Run(@AutoItExe & ' /AutoIt3ExecuteScript "' & @TempDir & '\MiscMMB.tmp"')
$iRet = MsgBox($iFlag, $sTitle, StringFormat($sText, $iMBTimeOut), $iMBTimeOut)

While FileExists(@TempDir & '\MiscMMB.tmp')
FileDelete(@TempDir & '\MiscMMB.tmp')
WEnd

Return $iRet
EndFunc

sashadeg
16-11-2009, 20:28
Спасибо, но мне нужно чтобы изменялся текст кнопки...
используя только 1 скрипт

FlatX007
16-11-2009, 20:51
А зделать по образцу ... или всё расжевать нужно.

sashadeg
16-11-2009, 21:16
лучше разжевать xD я за разжеванные благодарность не забываю ставить =) да и респеХт тебе от народа будет =)

Creat0R
16-11-2009, 22:27
мне нужно чтобы изменялся текст кнопки »

_MsgBoxTimer(36, 'Заголовок', 'Сообщение', 5)

Func (http://www.autoitscript.com/autoit3/docs/keywords.htm#Func) _MsgBoxTimer($iFlag, $sTitle, $sText, $iMBTimeOut = 0, $hWnd = 0)
Local (http://www.autoitscript.com/autoit3/docs/keywords.htm#Local) $hFile, $sMBLine, $sSet_Text, $iRet

$sMBLine = '#NoTrayIcon' & @CRLF (http://www.autoitscript.com/autoit3/docs/macros.htm#@CRLF)
$sMBLine &= '$h_Title = WinGetHandle("' & $sTitle & '")' & @CRLF (http://www.autoitscript.com/autoit3/docs/macros.htm#@CRLF)
$sMBLine &= 'Opt("WinWaitDelay", 1)' & @CRLF (http://www.autoitscript.com/autoit3/docs/macros.htm#@CRLF)
$sMBLine &= 'While Not WinExists($h_Title)' & @CRLF (http://www.autoitscript.com/autoit3/docs/macros.htm#@CRLF)
$sMBLine &= ' Sleep(10)' & @CRLF (http://www.autoitscript.com/autoit3/docs/macros.htm#@CRLF)
$sMBLine &= 'WEnd' & @CRLF (http://www.autoitscript.com/autoit3/docs/macros.htm#@CRLF)

If (http://www.autoitscript.com/autoit3/docs/keywords.htm#If) $iMBTimeOut > 0 Then (http://www.autoitscript.com/autoit3/docs/keywords.htm#Then)
$sMBLine &= _
'$sButtonText = ControlGetText($h_Title, "", "Button1")' & @CRLF (http://www.autoitscript.com/autoit3/docs/macros.htm#@CRLF) & _
'ControlSetText($h_Title, "", "Button1", $sButtonText & " (' & $iMBTimeOut & ')")' & @CRLF (http://www.autoitscript.com/autoit3/docs/macros.htm#@CRLF) & _
'$TimerInit = TimerInit()' & @CRLF (http://www.autoitscript.com/autoit3/docs/macros.htm#@CRLF) & _
'$iTime = ' & $iMBTimeOut & @CRLF (http://www.autoitscript.com/autoit3/docs/macros.htm#@CRLF) & _
'While $iTime > 0' & @CRLF (http://www.autoitscript.com/autoit3/docs/macros.htm#@CRLF) & _
' If Not WinExists($h_Title) Then ExitLoop' & @CRLF (http://www.autoitscript.com/autoit3/docs/macros.htm#@CRLF) & _
' $sButtonText = StringRegExpReplace(ControlGetText($h_Title, "", "Button1"), " \(\d+\)$", "")' & @CRLF (http://www.autoitscript.com/autoit3/docs/macros.htm#@CRLF) & _
' ControlSetText($h_Title, "", "Button1", $sButtonText & " (" & $iTime & ")")' & @CRLF (http://www.autoitscript.com/autoit3/docs/macros.htm#@CRLF) & _
' If Not WinExists($h_Title) Then ExitLoop' & @CRLF (http://www.autoitscript.com/autoit3/docs/macros.htm#@CRLF) & _
' Sleep(1000)' & @CRLF (http://www.autoitscript.com/autoit3/docs/macros.htm#@CRLF) & _
' If Not WinExists($h_Title) Then ExitLoop' & @CRLF (http://www.autoitscript.com/autoit3/docs/macros.htm#@CRLF) & _
' $iTime -= 1' & @CRLF (http://www.autoitscript.com/autoit3/docs/macros.htm#@CRLF) & _
'WEnd'
EndIf (http://www.autoitscript.com/autoit3/docs/keywords.htm#EndIf)

$hFile = FileOpen (http://www.autoitscript.com/autoit3/docs/functions/FileOpen.htm)(@TempDir (http://www.autoitscript.com/autoit3/docs/macros.htm#@TempDir) & '\MiscMMB.tmp', 2)
FileWrite (http://www.autoitscript.com/autoit3/docs/functions/FileWrite.htm)($hFile, $sMBLine)
FileClose (http://www.autoitscript.com/autoit3/docs/functions/FileClose.htm)($hFile)

Run (http://www.autoitscript.com/autoit3/docs/functions/Run.htm)(@AutoItExe (http://www.autoitscript.com/autoit3/docs/macros.htm#@AutoItExe) & ' /AutoIt3ExecuteScript "' & @TempDir (http://www.autoitscript.com/autoit3/docs/macros.htm#@TempDir) & '\MiscMMB.tmp"')
$iRet = MsgBox (http://www.autoitscript.com/autoit3/docs/functions/MsgBox.htm)($iFlag, $sTitle, StringFormat (http://www.autoitscript.com/autoit3/docs/functions/StringFormat.htm)($sText, $iMBTimeOut), $iMBTimeOut)

While (http://www.autoitscript.com/autoit3/docs/keywords.htm#While) FileExists (http://www.autoitscript.com/autoit3/docs/functions/FileExists.htm)(@TempDir (http://www.autoitscript.com/autoit3/docs/macros.htm#@TempDir) & '\MiscMMB.tmp')
FileDelete (http://www.autoitscript.com/autoit3/docs/functions/FileDelete.htm)(@TempDir (http://www.autoitscript.com/autoit3/docs/macros.htm#@TempDir) & '\MiscMMB.tmp')
WEnd (http://www.autoitscript.com/autoit3/docs/keywords.htm#WEnd)

Return (http://www.autoitscript.com/autoit3/docs/keywords.htm#Return) $iRet
EndFunc (http://www.autoitscript.com/autoit3/docs/keywords.htm#EndFunc) ;==>_MsgBoxTimer

Creat0R
16-11-2009, 22:34
Ну или вариант с самопальным (GUI)MsgBox:

#Include <GUIConstantsEx.au3>
#Include <ButtonConstants.au3>
#Include <WindowsConstants.au3>
;

$Title = "My Custom MsgBox"
$Prompt = "Вы уверены?"
$CheckBoxText = "Больше не спрашивать"

$hWnd = WinGetHandle (http://www.autoitscript.com/autoit3/docs/functions/WinGetHandle.htm)("")

$Ask = _GUIMsgBox(36, 2, $Title, $Prompt, 330, 120, $CheckBoxText, 10, $hWnd, "Да", "Нет")

Func (http://www.autoitscript.com/autoit3/docs/keywords.htm#Func) _GUIMsgBox($iIcoType,$iBtnNum,$sTitle,$sTxt,$iW=350,$iH=130,$sCB_Txt=-1,$iTimer=-1,$hWnd=0,$sB1Txt=-1,$sB2Txt=-1,$nExStyle=-1)
Local (http://www.autoitscript.com/autoit3/docs/keywords.htm#Local) $nYes_Button, $nNo_Button, $nOK_Button, $nCheckBox=-1, $hMsgBox_GUI, $iGuiHeight = $iH
Local (http://www.autoitscript.com/autoit3/docs/keywords.htm#Local) $nStyle = BitOR (http://www.autoitscript.com/autoit3/docs/functions/BitOR.htm)($WS_CAPTION, $WS_POPUP)
Local (http://www.autoitscript.com/autoit3/docs/keywords.htm#Local) $nMsg, $iReturnVal = 0
Local (http://www.autoitscript.com/autoit3/docs/keywords.htm#Local) $nDefButton, $sDefButtonText = $sB1Txt, $iCounter
Local (http://www.autoitscript.com/autoit3/docs/keywords.htm#Local) $iMessageBeep = -1, $iIcon_Id = 102

Local (http://www.autoitscript.com/autoit3/docs/keywords.htm#Local) $iOld_Opt_GOEM = Opt (http://www.autoitscript.com/autoit3/docs/functions/Opt.htm)('GuiOnEventMode', 0)
Local (http://www.autoitscript.com/autoit3/docs/keywords.htm#Local) $iOld_Opt_GCOE = Opt (http://www.autoitscript.com/autoit3/docs/functions/Opt.htm)('GUICloseOnESC', 0)

If (http://www.autoitscript.com/autoit3/docs/keywords.htm#If) $iBtnNum = 1 Then (http://www.autoitscript.com/autoit3/docs/keywords.htm#Then) $nStyle = BitOR (http://www.autoitscript.com/autoit3/docs/functions/BitOR.htm)($nStyle, $WS_SYSMENU)

If (http://www.autoitscript.com/autoit3/docs/keywords.htm#If) BitAND (http://www.autoitscript.com/autoit3/docs/functions/BitAND.htm)($iIcoType, 262144) Then (http://www.autoitscript.com/autoit3/docs/keywords.htm#Then)
If (http://www.autoitscript.com/autoit3/docs/keywords.htm#If) $nExStyle = -1 Or (http://www.autoitscript.com/autoit3/docs/keywords.htm#Or) $nExStyle = Default (http://www.autoitscript.com/autoit3/docs/keywords.htm#Default) Then (http://www.autoitscript.com/autoit3/docs/keywords.htm#Then) $nExStyle = 0
$nExStyle = BitOR (http://www.autoitscript.com/autoit3/docs/functions/BitOR.htm)($nExStyle, $WS_EX_TOPMOST)
EndIf (http://www.autoitscript.com/autoit3/docs/keywords.htm#EndIf)

If (http://www.autoitscript.com/autoit3/docs/keywords.htm#If) $sCB_Txt <> -1 Then (http://www.autoitscript.com/autoit3/docs/keywords.htm#Then) $iGuiHeight += 25

If (http://www.autoitscript.com/autoit3/docs/keywords.htm#If) $sB1Txt = -1 Then (http://www.autoitscript.com/autoit3/docs/keywords.htm#Then) $sB1Txt = 'OK'
If (http://www.autoitscript.com/autoit3/docs/keywords.htm#If) $sB2Txt = -1 Then (http://www.autoitscript.com/autoit3/docs/keywords.htm#Then) $sB2Txt = 'Cancel'

If (http://www.autoitscript.com/autoit3/docs/keywords.htm#If) IsHWnd (http://www.autoitscript.com/autoit3/docs/functions/IsHWnd.htm)($hWnd) Then (http://www.autoitscript.com/autoit3/docs/keywords.htm#Then) WinSetState (http://www.autoitscript.com/autoit3/docs/functions/WinSetState.htm)($hWnd, "", @SW_DISABLE (http://www.autoitscript.com/autoit3/docs/macros.htm#@SW_DISABLE))

$hMsgBox_GUI = GUICreate (http://www.autoitscript.com/autoit3/docs/functions/GUICreate.htm)($sTitle, $iW, $iGuiHeight, -1, -1, $nStyle, $nExStyle, $hWnd)

Select (http://www.autoitscript.com/autoit3/docs/keywords.htm#Select)
Case (http://www.autoitscript.com/autoit3/docs/keywords.htm#Case) $iIcoType = 16 Or (http://www.autoitscript.com/autoit3/docs/keywords.htm#Or) $iIcoType = 16 + 256
$iIcon_Id = 103
$iMessageBeep = 0x00000010
Case (http://www.autoitscript.com/autoit3/docs/keywords.htm#Case) $iIcoType = 32 Or (http://www.autoitscript.com/autoit3/docs/keywords.htm#Or) $iIcoType = 32 + 256
$iIcon_Id = 102
$iMessageBeep = 0x00000020
Case (http://www.autoitscript.com/autoit3/docs/keywords.htm#Case) $iIcoType = 48 Or (http://www.autoitscript.com/autoit3/docs/keywords.htm#Or) $iIcoType = 48 + 256
$iIcon_Id = 101
$iMessageBeep = 0x00000030
Case (http://www.autoitscript.com/autoit3/docs/keywords.htm#Case) $iIcoType = 64 Or (http://www.autoitscript.com/autoit3/docs/keywords.htm#Or) $iIcoType = 64 + 256
$iIcon_Id = 104
$iMessageBeep = 0x00000040
EndSelect (http://www.autoitscript.com/autoit3/docs/keywords.htm#EndSelect)

GUICtrlCreateIcon (http://www.autoitscript.com/autoit3/docs/functions/GUICtrlCreateIcon.htm)('user32.dll', $iIcon_Id, 10, 10)
GUICtrlCreateLabel (http://www.autoitscript.com/autoit3/docs/functions/GUICtrlCreateLabel.htm)($sTxt, 70, 15, $iW-80, $iH-50)

Select (http://www.autoitscript.com/autoit3/docs/keywords.htm#Select)
Case (http://www.autoitscript.com/autoit3/docs/keywords.htm#Case) $iBtnNum = 2
$nYes_Button = GUICtrlCreateButton (http://www.autoitscript.com/autoit3/docs/functions/GUICtrlCreateButton.htm)($sB1Txt, ($iW/2)-90, $iH-35, 70, 20, $BS_DEFPUSHBUTTON)
$nDefButton = $nYes_Button

Local (http://www.autoitscript.com/autoit3/docs/keywords.htm#Local) $iSecButtDeffStyle = 0
If (http://www.autoitscript.com/autoit3/docs/keywords.htm#If) BitAND (http://www.autoitscript.com/autoit3/docs/functions/BitAND.htm)($iIcoType, 256) Then (http://www.autoitscript.com/autoit3/docs/keywords.htm#Then) $iSecButtDeffStyle = $BS_DEFPUSHBUTTON

$nNo_Button = GUICtrlCreateButton (http://www.autoitscript.com/autoit3/docs/functions/GUICtrlCreateButton.htm)($sB2Txt, ($iW/2)+20, $iH-35, 70, 20, $iSecButtDeffStyle)
If (http://www.autoitscript.com/autoit3/docs/keywords.htm#If) BitAND (http://www.autoitscript.com/autoit3/docs/functions/BitAND.htm)($iIcoType, 256) Then (http://www.autoitscript.com/autoit3/docs/keywords.htm#Then) $nDefButton = $nNo_Button
Case (http://www.autoitscript.com/autoit3/docs/keywords.htm#Case) Else (http://www.autoitscript.com/autoit3/docs/keywords.htm#Else)
$nOK_Button = GUICtrlCreateButton (http://www.autoitscript.com/autoit3/docs/functions/GUICtrlCreateButton.htm)($sB1Txt, ($iW-70)/2, $iH-35, 70, 20)
GUICtrlSetState (http://www.autoitscript.com/autoit3/docs/functions/GUICtrlSetState.htm)($nOK_Button, $GUI_ONTOP)
$nDefButton = $nOK_Button
EndSelect (http://www.autoitscript.com/autoit3/docs/keywords.htm#EndSelect)

If (http://www.autoitscript.com/autoit3/docs/keywords.htm#If) $sCB_Txt <> -1 Then (http://www.autoitscript.com/autoit3/docs/keywords.htm#Then) $nCheckBox = GUICtrlCreateCheckbox (http://www.autoitscript.com/autoit3/docs/functions/GUICtrlCreateCheckbox.htm)($sCB_Txt, 15, $iH-10)

GUISetState (http://www.autoitscript.com/autoit3/docs/functions/GUISetState.htm)(@SW_SHOW (http://www.autoitscript.com/autoit3/docs/macros.htm#@SW_SHOW), $hMsgBox_GUI)
DllCall (http://www.autoitscript.com/autoit3/docs/functions/DllCall.htm)("user32.dll", "int", "MessageBeep", "int", $iMessageBeep)

If (http://www.autoitscript.com/autoit3/docs/keywords.htm#If) $iTimer > 0 Then (http://www.autoitscript.com/autoit3/docs/keywords.htm#Then)
$iCounter = $iTimer
$iTimer = TimerInit (http://www.autoitscript.com/autoit3/docs/functions/TimerInit.htm)()
$sDefButtonText = GUICtrlRead (http://www.autoitscript.com/autoit3/docs/functions/GUICtrlRead.htm)($nDefButton)
GUICtrlSetData (http://www.autoitscript.com/autoit3/docs/functions/GUICtrlSetData.htm)($nDefButton, $sDefButtonText & ' (' & $iCounter & ')')
EndIf (http://www.autoitscript.com/autoit3/docs/keywords.htm#EndIf)

While (http://www.autoitscript.com/autoit3/docs/keywords.htm#While) 1
$nMsg = GUIGetMsg (http://www.autoitscript.com/autoit3/docs/functions/GUIGetMsg.htm)()

If (http://www.autoitscript.com/autoit3/docs/keywords.htm#If) $iTimer > 0 And (http://www.autoitscript.com/autoit3/docs/keywords.htm#And) TimerDiff (http://www.autoitscript.com/autoit3/docs/functions/TimerDiff.htm)($iTimer) >= 1000 Then (http://www.autoitscript.com/autoit3/docs/keywords.htm#Then)
$iTimer = TimerInit (http://www.autoitscript.com/autoit3/docs/functions/TimerInit.htm)()
$iCounter -= 1
GUICtrlSetData (http://www.autoitscript.com/autoit3/docs/functions/GUICtrlSetData.htm)($nDefButton, $sDefButtonText & ' (' & $iCounter & ')')
If (http://www.autoitscript.com/autoit3/docs/keywords.htm#If) $iCounter < 0 Then (http://www.autoitscript.com/autoit3/docs/keywords.htm#Then) $nMsg = $nDefButton
EndIf (http://www.autoitscript.com/autoit3/docs/keywords.htm#EndIf)

Select (http://www.autoitscript.com/autoit3/docs/keywords.htm#Select)
Case (http://www.autoitscript.com/autoit3/docs/keywords.htm#Case) $iBtnNum = 2 And (http://www.autoitscript.com/autoit3/docs/keywords.htm#And) $nMsg = $nYes_Button
$iReturnVal = 6
ExitLoop (http://www.autoitscript.com/autoit3/docs/keywords.htm#ExitLoop)
Case (http://www.autoitscript.com/autoit3/docs/keywords.htm#Case) $iBtnNum = 2 And (http://www.autoitscript.com/autoit3/docs/keywords.htm#And) $nMsg = $nNo_Button
$iReturnVal = 7
ExitLoop (http://www.autoitscript.com/autoit3/docs/keywords.htm#ExitLoop)
Case (http://www.autoitscript.com/autoit3/docs/keywords.htm#Case) $nMsg = -3 Or (http://www.autoitscript.com/autoit3/docs/keywords.htm#Or) ($nMsg = $nOK_Button And (http://www.autoitscript.com/autoit3/docs/keywords.htm#And) $iBtnNum <> 2)
$iReturnVal = 1
ExitLoop (http://www.autoitscript.com/autoit3/docs/keywords.htm#ExitLoop)
EndSelect (http://www.autoitscript.com/autoit3/docs/keywords.htm#EndSelect)
WEnd (http://www.autoitscript.com/autoit3/docs/keywords.htm#WEnd)

If (http://www.autoitscript.com/autoit3/docs/keywords.htm#If) GUICtrlRead (http://www.autoitscript.com/autoit3/docs/functions/GUICtrlRead.htm)($nCheckBox) = 1 Then (http://www.autoitscript.com/autoit3/docs/keywords.htm#Then) $iReturnVal += 8

If (http://www.autoitscript.com/autoit3/docs/keywords.htm#If) IsHWnd (http://www.autoitscript.com/autoit3/docs/functions/IsHWnd.htm)($hWnd) Then (http://www.autoitscript.com/autoit3/docs/keywords.htm#Then) WinSetState (http://www.autoitscript.com/autoit3/docs/functions/WinSetState.htm)($hWnd, "", @SW_ENABLE (http://www.autoitscript.com/autoit3/docs/macros.htm#@SW_ENABLE))
GUIDelete (http://www.autoitscript.com/autoit3/docs/functions/GUIDelete.htm)($hMsgBox_GUI)

If (http://www.autoitscript.com/autoit3/docs/keywords.htm#If) IsHWnd (http://www.autoitscript.com/autoit3/docs/functions/IsHWnd.htm)($hWnd) Then (http://www.autoitscript.com/autoit3/docs/keywords.htm#Then) GUISwitch (http://www.autoitscript.com/autoit3/docs/functions/GUISwitch.htm)($hWnd)

Opt (http://www.autoitscript.com/autoit3/docs/functions/Opt.htm)('GuiOnEventMode', $iOld_Opt_GOEM)
Opt (http://www.autoitscript.com/autoit3/docs/functions/Opt.htm)('GUICloseOnESC', $iOld_Opt_GCOE)

Return (http://www.autoitscript.com/autoit3/docs/keywords.htm#Return) $iReturnVal
EndFunc (http://www.autoitscript.com/autoit3/docs/keywords.htm#EndFunc)

Текст будет обновляться на дефолтной кнопке (если к флагу первого параметра добавить 256, то текст будет обновляться на второй кнопке).

sashadeg
17-11-2009, 07:43
В этих скриптах идёт 2 процесса вместе? Мне как бы это главнее =)

sashadeg
17-11-2009, 09:06
Creat0R, я использовал твой первый код...
Просит endf =( А куда его вставить я не понимаю.... Где ошибка???

Вот вся прога:
Opt("TrayAutoPause", 0)
TrayTip("The Internet is connected?", "Подождите...", 5, 1)
$var = Ping("www.google.com")
If $var <> 0 Then
MsgBox(64, "The Internet is connected?", "Все в порядке, Интрернет работает :)"& @CRLF &"Время подключения: " & @hour &":"& @min &":"&@sec)
Exit
Else
$1=_MsgBoxTimer(36, 'Заголовок', 'Сообщение', 5)

Func _MsgBoxTimer($iFlag, $sTitle, $sText, $iMBTimeOut = 0, $hWnd = 0)
Local $hFile, $sMBLine, $sSet_Text, $iRet

$sMBLine = '#NoTrayIcon' & @CRLF
$sMBLine &= '$h_Title = WinGetHandle("' & $sTitle & '")' & @CRLF
$sMBLine &= 'Opt("WinWaitDelay", 1)' & @CRLF
$sMBLine &= 'While Not WinExists($h_Title)' & @CRLF
$sMBLine &= ' Sleep(10)' & @CRLF
$sMBLine &= 'WEnd' & @CRLF

If $iMBTimeOut > 0 Then
$sMBLine &= _
'$sButtonText = ControlGetText($h_Title, "", "Button1")' & @CRLF & _
'ControlSetText($h_Title, "", "Button1", $sButtonText & " (' & $iMBTimeOut & ')")' & @CRLF & _
'$TimerInit = TimerInit()' & @CRLF & _
'$iTime = ' & $iMBTimeOut & @CRLF & _
'While $iTime > 0' & @CRLF & _
' If Not WinExists($h_Title) Then ExitLoop' & @CRLF & _
' $sButtonText = StringRegExpReplace(ControlGetText($h_Title, "", "Button1"), " \(\d+\)$", "")' & @CRLF & _
' ControlSetText($h_Title, "", "Button1", $sButtonText & " (" & $iTime & ")")' & @CRLF & _
' If Not WinExists($h_Title) Then ExitLoop' & @CRLF & _
' Sleep(1000)' & @CRLF & _
' If Not WinExists($h_Title) Then ExitLoop' & @CRLF & _
' $iTime -= 1' & @CRLF & _
'WEnd'
EndIf

$hFile = FileOpen(@TempDir & '\MiscMMB.tmp', 2)
FileWrite($hFile, $sMBLine)
FileClose($hFile)

Run(@AutoItExe & ' /AutoIt3ExecuteScript "' & @TempDir & '\MiscMMB.tmp"')
$iRet = MsgBox($iFlag, $sTitle, StringFormat($sText, $iMBTimeOut), $iMBTimeOut)

While FileExists(@TempDir & '\MiscMMB.tmp')
FileDelete(@TempDir & '\MiscMMB.tmp')
WEnd

Return $iRet
EndFunc ;==>_MsgBoxTimer
EndIf

If $1<>7 Then
TrayTip("The Internet is connected?","Программа ожидает подключения сети Интернет...", 7, 1)
While 1
$var = Ping("www.google.com")
If $var <> 0 Then
MsgBox(64, "The Internet is connected?", "Все в порядке, Интрернет работает :)"& @CRLF &"Время подключения: " & @hour &":"& @min &":"&@sec)
Exit
EndIf
sleep(500)
WEnd
Else
TrayTip("The Internet is connected?","Bye-bye!!!", 3, 1)
Sleep(3000)
EndIf

beve
17-11-2009, 15:59
Саму функцию лушче всегда описывать после всего кода (по крайней мере не в середине "проверки условия" где у тебя), а вызов этой функции - в нужном тебе месте. Opt("TrayAutoPause", 0)
TrayTip("The Internet is connected?", "Подождите...", 5, 1)
$var = Ping("www.google.com")
;------------------------------------------------------------------------------------------
If $var<> 0 Then
MsgBox(64, "The Internet is connected?", "Все в порядке, Интрернет работает :)"& @CRLF &"Время подключения: " & @hour &":"& @min &":"&@sec)
Exit
Else
$1=_MsgBoxTimer(36, 'Заголовок', 'Сообщение', 5)
EndIf
;------------------------------------------------------------------------------------------
If $1<>7 Then
TrayTip("The Internet is connected?","Программа ожидает подключения сети Интернет...", 7, 1)
While 1
$var = Ping("www.google.com")
If $var <> 0 Then
MsgBox(64, "The Internet is connected?", "Все в порядке, Интрернет работает :)"& @CRLF &"Время подключения: " & @hour &":"& @min &":"&@sec)
Exit
EndIf
sleep(500)
WEnd
Else
TrayTip("The Internet is connected?","Bye-bye!!!", 3, 1)
Sleep(3000)
EndIf


Func _MsgBoxTimer($iFlag, $sTitle, $sText, $iMBTimeOut = 0, $hWnd = 0)
Local $hFile, $sMBLine, $sSet_Text, $iRet
$sMBLine = '#NoTrayIcon' & @CRLF
$sMBLine &= '$h_Title = WinGetHandle("' & $sTitle & '")' & @CRLF
$sMBLine &= 'Opt("WinWaitDelay", 1)' & @CRLF
$sMBLine &= 'While Not WinExists($h_Title)' & @CRLF
$sMBLine &= ' Sleep(10)' & @CRLF
$sMBLine &= 'WEnd' & @CRLF

If $iMBTimeOut > 0 Then
$sMBLine &= _
'$sButtonText = ControlGetText($h_Title, "", "Button1")' & @CRLF & _
'ControlSetText($h_Title, "", "Button1", $sButtonText & " (' & $iMBTimeOut & ')")' & @CRLF & _
'$TimerInit = TimerInit()' & @CRLF & _
'$iTime = ' & $iMBTimeOut & @CRLF & _
'While $iTime > 0' & @CRLF & _
' If Not WinExists($h_Title) Then ExitLoop' & @CRLF & _
' $sButtonText = StringRegExpReplace(ControlGetText($h_Title, "", "Button1"), " \(\d+\)$", "")' & @CRLF & _
' ControlSetText($h_Title, "", "Button1", $sButtonText & " (" & $iTime & ")")' & @CRLF & _
' If Not WinExists($h_Title) Then ExitLoop' & @CRLF & _
' Sleep(1000)' & @CRLF & _
' If Not WinExists($h_Title) Then ExitLoop' & @CRLF & _
' $iTime -= 1' & @CRLF & _
'WEnd'
EndIf
$hFile = FileOpen(@TempDir & '\MiscMMB.tmp', 2)
FileWrite($hFile, $sMBLine)
FileClose($hFile)

Run(@AutoItExe & ' /AutoIt3ExecuteScript "' & @TempDir & '\MiscMMB.tmp"')
$iRet = MsgBox($iFlag, $sTitle, StringFormat($sText, $iMBTimeOut), $iMBTimeOut)

While FileExists(@TempDir & '\MiscMMB.tmp')
FileDelete(@TempDir & '\MiscMMB.tmp')
WEnd

Return $iRet
EndFunc ;==>_MsgBoxTimer

sashadeg
17-11-2009, 19:46
Спасибо beve и Creat0R!!!


А что если вот здесь
MsgBox(64, "The Internet is connected?", "Все в порядке, Интрернет работает :)"& @CRLF &"Время подключения: " & @hour &":"& @min &":"&@sec)

изменить флаг(вроде так называется) из 64 на 65?
Получится 2 кнопки: Ok and Cancel. А как можно заменить текст кнопки Cancel? Естественно, всё в пределах одного кода, без участия сторонних скриптов...




© OSzone.net 2001-2012