Hi,
I am trying to close my app after a certain interval of user inactivity.
This is the code that you put on this forum a while ago. It worked except in the case of modal forms. When the user leaves the screen while in a modal form, a foxpro message comes as 'cannot quit visual foxpro'
How can I get around this and quit the app??
I tried a few work arounds, but they did'nt help.
Also, I changed the timer code little bit, in PROCEDURE timeoutapp, instead of goProgram.OnQuit, I said 'QUIT'.
Thanks in advance.
-----------------------------------------------------
**************************************************
*-- Class: tmrtimeout
*-- ParentClass: timer
*-- BaseClass: timer
*
DEFINE CLASS tmrtimeout AS TIMER
HEIGHT = 23
WIDTH = 23
*-- The amount of time to timeout on
ntimeout = 0
*-- Time this program last ran (in seconds)
nlastrun = 0
*-- Time the program detected the last change in state
nlastchange = 0
*-- Last mouse column detected
nlastmousecol = 0
*-- Last mouse row detected
nlastmouserow = 0
*-- Current mouse column
nmousecol = 0
*-- Current Mouse Row
nmouserow = 0
*-- Current Time the timer ran in calctime() format
nrun = 0
*-- Current active form.
cactiveform = ("")
*-- Active form at the last timer run
clastactiveform = ("")
*-- Value of LastKey() when timer is run.
nkey = 0
*-- Lastkey pressed by the user at the previous timer run.
nlastkey = 0
NAME = "tmrtimeout"
*-- Calculates time in seconds. Not the SECONDS() function.
PROCEDURE calctime
LPARAMETERS tcTime
IF PCOUNT() =0
tcTime = TIME()
ENDIF
#DEFINE SECONDS_DAY 86400
#DEFINE SECONDS_HOUR 3600
#DEFINE SECONDS_MINUTE 60
#DEFINE ELAPASED_DAYS DATE() - {01/01/97}
#DEFINE ELAPSED_HOURS
*-- This function will return seconds since 1/1/97. This way, when we move from
*-- one day to another (which would cause Seconds() to recycle to 0), we are
*-- not affected.
*--
*-- One other point. I am trying to optimize the code as much as possible because this
*-- timer may run many times in a session and I want it to be unnoticeable.
LOCAL lnDays, lnHours, lnMinutes, lnSeconds, lnRetVal
lnDays = DATE() - {01/01/97}
lnHours = VAL(LEFT(tcTime,2))
lnMinutes = VAL(SUBST(tcTime,4,2))
lnSeconds = VAL(SUBST(tcTime,7))
lnRetVal = (lnDays * SECONDS_DAY) + ;
(lnHours * SECONDS_HOUR) + ;
(lnMinutes * SECONDS_MINUTE) + ;
lnSeconds
RETURN lnRetVal
ENDPROC
*-- Timeout the application
PROCEDURE timeoutapp
goProgram.OnQuit
ENDPROC
PROCEDURE TIMER
LOCAL llChange, lnInterval
WITH THIS
*-- Turn the timer off while we are in the timer event
lnInterval= .INTERVAL
.INTERVAL = 0
.nrun = .calctime()
.nmousecol = MCOL("")
.nmouserow = MROW("")
.nkey = LASTKEY()
.cactiveform = IIF(TYPE("_screen.activeform.caption") == "C", ;
_SCREEN.ACTIVEFORM.CAPTION, ;
"***DESKTOP***")
llChange = !(.nkey = .nlastkey ;
AND .nmousecol = .nlastmousecol ;
AND .nmouserow = .nlastmouserow ;
AND .cactiveform == .clastactiveform)
*-- Now, if we have a change, just record it and go on
IF llChange
.nlastchange = .nrun
ELSE
IF .nrun - .nlastchange >= .ntimeout
IF BETWEEN(TIME(),'00:00:00','07:00:00') OR BETWEEN(TIME(),'18:15:00','23:59:59')
*-- Timeout
.timeoutapp()
ENDIF
ENDIF
ENDIF
*-- Save the current state
.nlastrun = .nrun
.nlastmousecol = .nmousecol
.nlastmouserow = .nmouserow
.nlastkey = .nkey
.clastactiveform = .cactiveform
*-- And that's that
.INTERVAL = lnInterval
ENDWITH
ENDPROC
ENDDEFINE
Suivant
Répondre
Voir le fil de ce thread
Voir le fil de ce thread à partir de ce message seulement
Voir tous les messages de ce thread
Voir tous les messages de ce thread à partir de ce message seulement