Jump to content

Recommended Posts

Hey, I want, when I click in the MsgBox for example "cancel" the script should be canceled and when I click "retry" the script should rerun from beginning. The rerun thing is not the problem. But I dont know how to make the cancel thing work. Can somebody help me? 

Link to post
Share on other sites
Posted (edited)

See help file:

#include <MsgBoxConstants.au3>
Local $Ask = MsgBox($MB_RETRYCANCEL + $MB_ICONQUESTION + $MB_TOPMOST, 'VIP', 'Continue ?')
If (($Ask = $IDCANCEL) Or ($Ask = $IDABORT) Or ($Ask = $IDIGNORE) Or ($Ask = $IDNO)) Then
    MsgBox(0, '', ' CANCEL ')
Else
    MsgBox(0, '', 'CONTINUE')
EndIf

eg2:

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>

Global $Form_1 = GUICreate("Autoit Start/Stop", 693, 123)
Global $Edit_1 = GUICtrlCreateEdit("", 16, 16, 529, 73)
GUICtrlSetData(-1, "...")
Global $Button_1 = GUICtrlCreateButton("START", 552, 16, 121, 73)
Global $Label_1 = GUICtrlCreateLabel("Label1", 24, 96, 652, 17)
GUISetState(@SW_SHOW)

Global $nMsg, $iPause = 0, $onWork = 0
_GUIGetMsg()

While 1
    _GUIGetMsg()
WEnd

Func _GUIGetMsg()
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $Button_1
            _Click_Button_StartStop()
        Case $GUI_EVENT_CLOSE
            _Ask(1)

    EndSwitch
EndFunc   ;==>_GUIGetMsg

Func _Click_Button_StartStop()
    If $onWork = 1 Then
        _Ask()
    Else
        _FunWork()
    EndIf
EndFunc   ;==>_Click_Button_StartStop

Func _Ask($exit = 0)
    Local $Ask = MsgBox($MB_RETRYCANCEL + $MB_ICONQUESTION + $MB_TOPMOST, 'VIP', 'Continue ?')
    If (($Ask = $IDCANCEL) Or ($Ask = $IDABORT) Or ($Ask = $IDIGNORE) Or ($Ask = $IDNO)) Then
        If $exit Then Exit
        GUICtrlSetData($Button_1, "START")
        $onWork = 0
        $iPause = -1
        MsgBox(0, '', ' CANCEL ')
    Else
        $onWork = 1
        $iPause = 0
        GUICtrlSetData($Button_1, "STOP")
        MsgBox(0, '', 'CONTINUE')
    EndIf
EndFunc   ;==>_Ask

Func _FunWork()
    $onWork = 1
    GUICtrlSetData($Button_1, "STOP")
    For $i = 1 To 10
        _GUIGetMsg()
        If $onWork = 0 Then Return

        If $iPause = 1 Then
            $i -= 1
            _SetStatus('Paused')
            ContinueLoop
        EndIf
        _SetStatus('Working...' & $i)
        Sleep(250)
    Next
    _SetStatus('Ready')
    GUICtrlSetData($Button_1, "START")
    $onWork = 0
EndFunc   ;==>_FunWork

Func _SetStatus($Data)
    ConsoleWrite($Data & @CRLF)
    GUICtrlSetData($Edit_1, $Data & @CRLF)
    GUICtrlSetData($Label_1, $Data & @CRLF)
EndFunc   ;==>_SetStatus

 

Edited by VIP
eg

Regards,
 

Link to post
Share on other sites
Posted (edited)

Something like this?

 

#include <MsgBoxConstants.au3>

runSometFunc()

ConsoleWrite("Exited Program" & @CRLF)

Func runSometFunc()
    While 1 ;avoid recursion
        Switch MsgBox($MB_RETRYCANCEL, "Continue?", "")
            Case 2 ;$IDCANCEL (2)
                Return
            Case 4 ;$IDRETRY (4)
                someRedo()
                ContinueLoop
        EndSwitch
    WEnd
EndFunc   ;==>runSometFunc

Func someRedo() ;your code goes here
    ConsoleWrite("Im gona redo code inside this 'someRedo' func" & @CRLF)
EndFunc   ;==>someRedo

or your looking a way to pause script on cancel?

Edited by bogQ

TCP server and client - Learning about TCP servers and clients connection
Au3 oIrrlicht - Irrlicht project
Au3impact - Another 3D DLL game engine for autoit. (3impact 3Drad related)



460px-Thief-4-temp-banner.jpg
There are those that believe that the perfect heist lies in the preparation.
Some say that it’s all in the timing, seizing the right opportunity. Others even say it’s the ability to leave no trace behind, be a ghost.

 
Link to post
Share on other sites
1 hour ago, bogQ said:

Something like this?

 

#include <MsgBoxConstants.au3>

runSometFunc()

ConsoleWrite("Exited Program" & @CRLF)

Func runSometFunc()
    While 1 ;avoid recursion
        Switch MsgBox($MB_RETRYCANCEL, "Continue?", "")
            Case 2 ;$IDCANCEL (2)
                Return
            Case 4 ;$IDRETRY (4)
                someRedo()
                ContinueLoop
        EndSwitch
    WEnd
EndFunc   ;==>runSometFunc

Func someRedo() ;your code goes here
    ConsoleWrite("Im gona redo code inside this 'someRedo' func" & @CRLF)
EndFunc   ;==>someRedo

or your looking a way to pause script on cancel?

that is what i ve been looking for

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...