INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Usefull Functions & Procedures

How do I auto release or shut application on inactivity ? by ramani
Posted: 21 Nov 03 (Edited 21 Nov 03)

**********************************************************
* 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
* 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
**************************************************
#ENDIF && end of explanations
**************************************************
*
*
**************************************************
** 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
**************************************************
* Ramani (Subramanian.G) - FoxAcc / WinnerSoft
* www.winnersoft.coolfreepages.com
**************************************************
* Evaluate to let others know how useful is this.
**************************************************

Back to Microsoft: Visual FoxPro FAQ Index
Back to Microsoft: Visual FoxPro Forum

My Archive

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close