Jump to content

How to Resume a function after Interuptting It ?


Recommended Posts

  • Moderators

Can you please explain a little more about what you're trying to do, and possibly post your code thus far? What triggers a need to exit the function, what are you doing outside the function, and then what triggers a need to re-enter the function? This will help us help you.

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

iam Making an Autosaver ; The program Basically Sends " Ctrl + s" to Save Your Progress on Programs like Photoshop Notepad Dreamweaver or any Program You Want ;

So i wanted to add  a pause Function So The user Can Pause THe timer , i have made it to interupt  The Function and stop The Timer But  I cant Get The timer to Continue Its Function

 

here THe Code i hope u understand it :D sorry for my Bad english

#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <GUIListBox.au3>
#include <File.au3>
Opt("GUIOnEventMode", 1)
#Region ### START Koda GUI section ### Form
;---------------------Graphic User Interfernce Section-----------------------
$Form1 = GUICreate("TheBlackAutoSaver", 650, 372, 257, 171)
$Status = GUICtrlCreateLabel("Status:", 184, 168, 40, 17)
GUICtrlSetTip(-1, "The Status ")
GUICtrlSetOnEvent(-1, "Label1Click")
$program = GUICtrlCreateLabel("program:", 288, 168, 40, 17)
$Timer = GUICtrlCreateLabel("Timer",  256, 40, 76, 23)
$Input2 = GUICtrlCreateInput("", 320, 40, 161, 21)
$Start = GUICtrlCreateButton("Start", 8, 312, 121, 25)
GUICtrlSetOnEvent(-1, 'start')
$Pause = GUICtrlCreateButton("Pause", 152, 312, 75, 25)
GUICtrlSetOnEvent(-1, 'pause')
$Label1 = GUICtrlCreateLabel("TImer", 168, 192, 76, 17)
$Label2 = GUICtrlCreateLabel("Minutes Passed", 168, 216, 76, 17)
$Label3 = GUICtrlCreateLabel("seconds ", 168, 240, 76, 17)
$Add = GUICtrlCreateButton("Add", 520, 8, 49, 25)
GUICtrlSetOnEvent(-1, 'Add')
$Delete = GUICtrlCreateButton("Delete", 576, 8, 65, 25)
GUICtrlSetOnEvent(-1,'Delete')
$Input1 = GUICtrlCreateInput("Input1", 208, 8, 161, 21)
$Group1 = GUICtrlCreateGroup("Timer", 24, 160, 241, 121)
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
;---------------------/// Pause Code \\\ ---------------------- | Start | 
$hAccelInterupt = GUICtrlCreateDummy()
 GUICtrlSetOnEvent($hAccelInterupt, "_Interrupt_Accel")
 ; Set an Accelerator key to action the dummy control
 Dim $AccelKeys[1][2]=[ ["z", $hAccelInterupt] ]
 GUISetAccelerators($AccelKeys)
 
 GUISetState()
 
 ; Intercept Windows command messages with out own handler
 GUIRegisterMsg($WM_COMMAND, "_WM_COMMAND")
 ;--------------------------- /// Pause Code \\\ ------------------ | End | 


;-------------------- The List Loader ---------------------------------------------
$file = "C:\Users\SuPeRBiGMaC\Desktop\Autosave\Test.txt"
FileOpen($file, 0)
$List1 = GUICtrlCreateList("", 520, 40, 121, 279)
For $i = 1 to _FileCountLines($file)
    $line = FileReadLine($file, $i)
GUICtrlSetData(-1, $line &"|")
Next
FileClose($file)
;------------------------Close By Hotkey ------------------------------------------
HotKeySet("{ESC}", "_Terminate")
;---------------------------------------------------------------------------------------


; ---------------------------- \\ Pause HotKey // --------------------

 HotKeySet("x", "_Interrupt")
 HotKeySet("c" , "_resume" ) 
 ; Declare a flag
 $fInterrupt = 0
;  -------------------------------------------------------------------------

Func _Terminate()
    Exit
EndFunc   ;==>_Terminate

Func _Timer ()
$fInterrupt = 0 
$app = GUICtrlRead($list1)
$x1 = "[Class:"&$app &"]" 
$Minutes = 1 ;will wait the time in The InputBox minutes
Local $60Count = 0, $begin = TimerInit()
While $Minutes > $60Count
    $dif = TimerDiff($begin)
    $dif2 = StringLeft($dif, StringInStr($dif, ".") -1)
    $Count = int($dif/1000)
    $60Count = Int($Count / 60)
    
; ----------------- \\\ The label Loader /// -------------------------- 
$Label6 = GUICtrlCreateLabel($Minutes, 296, 192, 33, 17)
GUICtrlSetColor(-1, 0x00FF00)
$Label7 = GUICtrlCreateLabel($60Count, 296, 212, 89, 20)
GUICtrlSetColor(-1, 0x00FF00)
$Label8 = GUICtrlCreateLabel($Count, 296, 236, 65, 20)
GUICtrlSetColor(-1, 0x00FF00)
$Status2 = GUICtrlCreateLabel("Working", 224, 168, 40, 17)
GUICtrlSetColor(-1, 0x00FF00)
$program2  = GUICtrlCreateLabel($app, 344, 168, 50, 17)
GUICtrlSetColor(-1 ,0x00FF00)
; ---------------------- \\\ loader Ends  /// --------------------------


If $Minutes = $60Count Then 
 WinWaitActive("[CLASS:"&$app&"]", "", 0)
 Send ("^s")
EndIf 

WEnd
Sleep(200)

EndFunc 

Func start  ()
$x1  = GUICtrlRead($list1)

If $list1 = "" Then 
Msgbox("" , "" ,$x1  )
Elseif  ProcessExists ($x1 &".exe") Then
Call("_Timer")
Else 
MsgBox ("" , "" ,"The Program must Be Runnig for The Autosaver to work " )  
Endif 

EndFunc
Func Add() ; ---------------------------------------------------

; -------------------------------------------------------------------------
$Add = GUICtrlRead($Input1)
$file = "C:\Users\SuPeRBiGMaC\Desktop\Autosave\Test.txt"
$hFileOpen = FileOpen($file,0)
$hFileWrite = _FileCountLines($file)
$hLine = $hFileWrite + 1
FileWrite($file ,  $Add & @CRLF)
FileClose($file)
GUICtrlSetData(-1, $Add & "|")
EndFunc ; ------------------------------------------------------

Func Delete() ;--------------------------------------------------
$x1 = GUICtrlRead($List1)   
_GUICtrlListBox_DeleteString($List1, _GUICtrlListBox_GetCaretIndex($List1))     
Dim $aRecords
$File  = "C:\Users\SuPeRBiGMaC\Desktop\Autosave\Test.txt"
$hFileopen = FileOpen($File ,0 ) 
_FileReadToArray($File ,$aRecords)
For $x = 1 to $aRecords[0]
    if stringinstr($aRecords[$x], $x1) then 
    _FileWriteToLine($file , $x , "" , 1) 
    Endif   
    Next 
    FileClose($File) 
EndFunc       ;---------------------------------------------------

 
; -------------- Pause HotsetKey ---------------------
 Func _Interrupt()
     while 1 
     $fInterrupt = 2
     wend 
 EndFunc
; --------------------------------------------------------------

Func pause() 
MsgBox ("" , "" , "it Workde yaay " ) 
EndFunc 


Func _Interrupt_Accel()
     ; This is an empty function for the dummy control linked to the Accelerator key
 EndFunc

Func _WM_COMMAND($hWnd, $Msg, $wParam, $lParam)
     ; The Func 2 button was pressed so set the flag
     If BitAND($wParam, 0x0000FFFF) =  $pause  Then $fInterrupt = 1
     ; The dummy control was actioned by the Accelerator key so set the flag
     If BitAND($wParam, 0x0000FFFF) =  $hAccelInterupt Then $fInterrupt = 3
     Return $GUI_RUNDEFMSG
 EndFunc   ;==>_WM_COMMAND

 
 
Func _Resume () 

$fInterrupt = 0
 
EndFUnc  
While 1 
Sleep(5000)
Wend
Link to comment
Share on other sites

I didn't read thru your code either, so I am not exactly sure how or where this code would be implemented in yours, but this is a modified HotKeySet function example taken from the Help file. You should note that the example in the Help file can be used pretty much exactly like it is. The modifications I made were basically just a small exercise for me.

Global $Paused
HotKeySet("{PAUSE}", "TogglePause")
HotKeySet("{ESC}", "Terminate")

;;;; Body of program would go here ;;;;
While 1
    For $a = 1 to 100
        MsgBox(0, $a, $a, 1)
    Next
WEnd
;;;;;;;;

Func TogglePause()
    $Paused = Not $Paused
    While $Paused
        Sleep(100)
        Switch MsgBox(1, $a, "Continue (OK) or Exit (Cancel)")
            Case 1
                Send("{PAUSE}")
            Case 2
                Send("{ESC}")
        EndSwitch
    WEnd
    ToolTip("")
EndFunc   ;==>TogglePause

Func Terminate()
    Exit 0
EndFunc   ;==>Terminate

- Bruce /*somdcomputerguy */  If you change the way you look at things, the things you look at change.

Link to comment
Share on other sites

Thanx I figure it Out My self ; The Problem Was I Used This Code

Func Pause() 

While 1 
$fInterrupt = 2
Wend 
EndFunc

So it made An infinite Loop ! After Trying other Codes and Searching and Googling and some Testing Here is The Final Code which Had Worked Pretty Good :D

Func _Interrupt()

 $fInterrupt = 2 
 while $fInterrupt = 2 
            Switch GUIGetMsg ()
                 Case $Resume ()
                    $fInterrupt = 0 
            EndSwitch 
                    Wend 
EndFunc
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...