Компьютерный форум OSzone.net  

Компьютерный форум OSzone.net (http://forum.oszone.net/index.php)
-   AutoIt (http://forum.oszone.net/forumdisplay.php?f=103)
-   -   Объёденить 2 скрипта в один (http://forum.oszone.net/showthread.php?t=157242)

sashadeg 16-11-2009 13:07 1271695

Объёденить 2 скрипта в один
 
Подскажите, как объёденить 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 1271845

(С) - 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 1271998

Спасибо, но мне нужно чтобы изменялся текст кнопки...
используя только 1 скрипт

FlatX007 16-11-2009 20:51 1272025

А зделать по образцу ... или всё расжевать нужно.

sashadeg 16-11-2009 21:16 1272036

лучше разжевать xD я за разжеванные благодарность не забываю ставить =) да и респеХт тебе от народа будет =)

Creat0R 16-11-2009 22:27 1272093

Цитата:

Цитата sashadeg
мне нужно чтобы изменялся текст кнопки »

Код:

_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


Creat0R 16-11-2009 22:34 1272098

Ну или вариант с самопальным (GUI)MsgBox:

Код:

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

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

$hWnd = WinGetHandle("")

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

Func _GUIMsgBox($iIcoType,$iBtnNum,$sTitle,$sTxt,$iW=350,$iH=130,$sCB_Txt=-1,$iTimer=-1,$hWnd=0,$sB1Txt=-1,$sB2Txt=-1,$nExStyle=-1)
    Local $nYes_Button, $nNo_Button, $nOK_Button, $nCheckBox=-1, $hMsgBox_GUI, $iGuiHeight = $iH
    Local $nStyle = BitOR($WS_CAPTION, $WS_POPUP)
    Local $nMsg, $iReturnVal = 0
    Local $nDefButton, $sDefButtonText = $sB1Txt, $iCounter
    Local $iMessageBeep = -1, $iIcon_Id = 102

    Local $iOld_Opt_GOEM = Opt('GuiOnEventMode', 0)
    Local $iOld_Opt_GCOE = Opt('GUICloseOnESC', 0)

    If $iBtnNum = 1 Then $nStyle = BitOR($nStyle, $WS_SYSMENU)

    If BitAND($iIcoType, 262144) Then
        If $nExStyle = -1 Or $nExStyle = Default Then $nExStyle = 0
        $nExStyle = BitOR($nExStyle, $WS_EX_TOPMOST)
    EndIf

    If $sCB_Txt <> -1 Then $iGuiHeight += 25

    If $sB1Txt = -1 Then $sB1Txt = 'OK'
    If $sB2Txt = -1 Then $sB2Txt = 'Cancel'

    If IsHWnd($hWnd) Then WinSetState($hWnd, "", @SW_DISABLE)

    $hMsgBox_GUI = GUICreate($sTitle, $iW, $iGuiHeight, -1, -1, $nStyle, $nExStyle, $hWnd)

    Select
        Case $iIcoType = 16 Or $iIcoType = 16 + 256
            $iIcon_Id = 103
            $iMessageBeep = 0x00000010
        Case $iIcoType = 32 Or $iIcoType = 32 + 256
            $iIcon_Id = 102
            $iMessageBeep = 0x00000020
        Case $iIcoType = 48 Or $iIcoType = 48 + 256
            $iIcon_Id = 101
            $iMessageBeep = 0x00000030
        Case $iIcoType = 64 Or $iIcoType = 64 + 256
            $iIcon_Id = 104
            $iMessageBeep = 0x00000040
    EndSelect

    GUICtrlCreateIcon('user32.dll', $iIcon_Id, 10, 10)
    GUICtrlCreateLabel($sTxt, 70, 15, $iW-80, $iH-50)

    Select
        Case $iBtnNum = 2
            $nYes_Button = GUICtrlCreateButton($sB1Txt, ($iW/2)-90, $iH-35, 70, 20, $BS_DEFPUSHBUTTON)
            $nDefButton = $nYes_Button

            Local $iSecButtDeffStyle = 0
            If BitAND($iIcoType, 256) Then $iSecButtDeffStyle = $BS_DEFPUSHBUTTON

            $nNo_Button
= GUICtrlCreateButton($sB2Txt, ($iW/2)+20, $iH-35, 70, 20, $iSecButtDeffStyle)
            If BitAND($iIcoType, 256) Then $nDefButton = $nNo_Button
        Case Else
            $nOK_Button = GUICtrlCreateButton($sB1Txt, ($iW-70)/2, $iH-35, 70, 20)
            GUICtrlSetState($nOK_Button, $GUI_ONTOP)
            $nDefButton = $nOK_Button
    EndSelect

    If $sCB_Txt <> -1 Then $nCheckBox = GUICtrlCreateCheckbox($sCB_Txt, 15, $iH-10)

    GUISetState(@SW_SHOW, $hMsgBox_GUI)
    DllCall("user32.dll", "int", "MessageBeep", "int", $iMessageBeep)

    If $iTimer > 0 Then
        $iCounter = $iTimer
        $iTimer
= TimerInit()
        $sDefButtonText = GUICtrlRead($nDefButton)
        GUICtrlSetData($nDefButton, $sDefButtonText & ' (' & $iCounter & ')')
    EndIf

    While 1
        $nMsg = GUIGetMsg()

        If $iTimer > 0 And TimerDiff($iTimer) >= 1000 Then
            $iTimer = TimerInit()
            $iCounter -= 1
            GUICtrlSetData($nDefButton, $sDefButtonText & ' (' & $iCounter & ')')
            If $iCounter < 0 Then $nMsg = $nDefButton
        EndIf

        Select
            Case $iBtnNum = 2 And $nMsg = $nYes_Button
                $iReturnVal
= 6
                ExitLoop
            Case $iBtnNum = 2 And $nMsg = $nNo_Button
                $iReturnVal
= 7
                ExitLoop
            Case $nMsg = -3 Or ($nMsg = $nOK_Button And $iBtnNum <> 2)
                $iReturnVal = 1
                ExitLoop
        EndSelect
    WEnd

    If GUICtrlRead($nCheckBox) = 1 Then $iReturnVal += 8

    If IsHWnd($hWnd) Then WinSetState($hWnd, "", @SW_ENABLE)
    GUIDelete($hMsgBox_GUI)

    If IsHWnd($hWnd) Then GUISwitch($hWnd)

    Opt('GuiOnEventMode', $iOld_Opt_GOEM)
    Opt('GUICloseOnESC', $iOld_Opt_GCOE)

    Return $iReturnVal
EndFunc

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

sashadeg 17-11-2009 07:43 1272265

В этих скриптах идёт 2 процесса вместе? Мне как бы это главнее =)

sashadeg 17-11-2009 09:06 1272306

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 1272653

Саму функцию лушче всегда описывать после всего кода (по крайней мере не в середине "проверки условия" где у тебя), а вызов этой функции - в нужном тебе месте.
читать дальше »
Код:

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 1272864

Спасибо beve и Creat0R!!!


А что если вот здесь
Код:

MsgBox(64, "The Internet is connected?", "Все в порядке, Интрернет работает :)"& @CRLF &"Время подключения:  " & @hour &":"& @min &":"&@sec)
изменить флаг(вроде так называется) из 64 на 65?
Получится 2 кнопки: Ok and Cancel. А как можно заменить текст кнопки Cancel? Естественно, всё в пределах одного кода, без участия сторонних скриптов...


Время: 16:03.

Время: 16:03.
© OSzone.net 2001-