Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I auto release or shut application on inactivity ?

Usefull Functions & Procedures

How do I auto release or shut application on inactivity ?

by  ramani  Posted    (Edited  )
**********************************************************
* 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

PROCEDURE Release
WAIT CLEAR
ENDPROC

PROCEDURE KeyPress
m.tLastUsed = DATETIME()
ENDPROC

PROCEDURE cmdExit.Click
ThisForm.Release
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.
**************************************************
Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search

Back
Top