**********************************************************
* Author : Ramani (Subramanian.G)
* FoxAcc Software / Winners Software
* Type : Freeware with reservation to Copyrights
* Warranty : Nothing implied or explicit
***********************************************************
** How to AutoClose a form or application.
**
#IF .f. && Just to avoid explanations from being run
[color blue]* 1. Add this Timer class definition at the end of your Main.Prg
*
* Timer Class to shutdown
* Set the interval as half of inactivity time
* i.e. if you want to shut in 10 minutes of inactivity
* set timer interval as (5 Min * 60 Sec * 1000 milli)
DEFINE CLASS ShutTimer AS Timer
Interval = 10 * (60*1000/2) && 10 minutes
Name = "ShutTimer1"
PROCEDURE Init
IF VARTYPE(ptLastUsed) = "U"
PUBLIC ptLastUsed
ENDIF
m.ptLastUsed = DATETIME()
ON KEY LABEL MOUSE m.ptLastUsed = DATETIME()
ENDPROC
PROCEDURE Timer
IF ( DATETIME()- m.ptLastUsed )*1000 > This.Interval * 2
* ThisForm.Release && if only form to be released
DO myShutDown && if application to be shutdown
ENDIF
ENDDEFINE
** Enddefine
**************************************************
* 2. ADD in the KeyPress Event of the form..
m.ptLastUsed = DATETIME()
**************************************************
* 3. Set the forms property KeyPreview = .t.
**************************************************
* 4. Add the following code in the Init of the form.
WITH ThisForm
.AddObject("oTimer","Timer")
ENDWITH
**************************************************
* 5. Add a myShutDown procedure to the end of Main.Prg
PROCEDURE myShutDown
CLEAR EVENTS
QUIT
**************************************************
** 6. Add the follwoing code at the beginning of your Main.PRG
ON SHUTDOWN DO myShutDown
**************************************************
[color black]#ENDIF && end of explanations
**************************************************
*
*[color green]
**************************************************
** Following is an example....
** A sample form with above
*************************************************
PUBLIC oForm
ON SHUTDOWN DO myShutDown
oForm = NEWOBJECT("gsShutForm")
oForm.Show
RETURN
**************************************************
PROCEDURE myShutDown
CLEAR EVENTS
QUIT
ENDPROC
**************************************************
DEFINE CLASS gsShutForm AS form
Height = 324
Width = 598
DoCreate = .T.
Caption = "Example to show auto release of forms"
Name = "gsShurForm"
KeyPreview = .t.
ADD OBJECT cmdExit AS commandbutton WITH ;
Top = 12, ;
Left = 444, ;
Height = 27, ;
Width = 60, ;
Caption = "Exit", ;
Name = "cmdExit"
PROCEDURE Init
WITH Thisform
.AddObject("oTimer","ShutTimer")
ENDWITH
ENDPROC
PROCEDURE activate
WAIT WINDOW "This form will be released if remains idle for 6 seconds" NOWAIT NOCLEAR
ENDPROC
ENDDEFINE
* EndDefine: gsShutForm
**************************************************
DEFINE CLASS ShutTimer AS Timer
Interval = .1 * (60*1000/2) && 6 seconds
Name = "ShutTimer1"
PROCEDURE Init
IF VARTYPE(ptLastUsed) = "U"
PUBLIC ptLastUsed
ENDIF
m.ptLastUsed = DATETIME()
ON KEY LABEL MOUSE m.ptLastUsed = DATETIME()
ENDPROC
PROCEDURE Timer
IF ( DATETIME()- m.ptLastUsed )*1000 > This.Interval * 2
ThisForm.Release && if only form to be released
* DO myShutDown && if application to be shutdown
ENDIF
ENDDEFINE
** Enddefine
**************************************************
** End of sample code [color black]
**************************************************
* Ramani (Subramanian.G) - FoxAcc / WinnerSoft
* www.winnersoft.coolfreepages.com
**************************************************
* Evaluate to let others know how useful is this.
**************************************************
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.