Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Close form after 30 second of no usage
Message
De
09/09/2005 14:29:26
 
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Gestionnaire d'écran & Écrans
Versions des environnements
Visual FoxPro:
VFP 9
OS:
Windows XP SP2
Database:
Visual FoxPro
Divers
Thread ID:
01048017
Message ID:
01048228
Vues:
18
>close form after 30 second when not use
>i want to close a form or run any command after 30 second when form is not using.(after using 30 secnod)
>i try with timer. but timer not start after 30 sec. Its start promat.
>How?? thanks


Khubaib,

Create the following properties in the form:
nIdleMinutes   = 0         && Number of minutes that the computer is now idle. Used by IdleMinutes() 
                           && method.
nLastInputInfo = 0         && Milliseconds the computer was on when the last keystroke or mousemove 
                           && was. Used internally by the IdleMinutes() method.
ptLastPoint    = 'xxxxxxx' && Internal to IdleMinutes() method. The pt stands for 'pointer'.
nIdleBaseline  = 0         && Used internally by the IdleMinutes() method.
Add the method IdleMinutes() to the form. Paste the code hereunder.

Call thisform.IdleMinutes( .T. ) in the form's Init() in order to initialize things.

Use an interval object to call thisform.IdleMinutes each x seconds. It will return the number of minutes that the computer is idle (not used). In the interval object you can decide to quit the application based on the returned value.

In your case, you will probably have to change the code and the method's name a bit, because you want to know the status per 30 seconds.

Good luck!
* METHOD IdleMinutes

* (C) Viafox 2005
*
*	get last input moment
*	compare with previous last input moment
*	if same, increase minute counter
*	if not same, save last input moment
*	return minute counter

lparameter tlInit

local llIdleNow

with this

	if val( os( 3 ) ) >= 5		&& if w2000 or higher, then use GetLastInputInfo()
	
		Local lnLast As Integer, plii As String, lcLast As String

		if m.tlInit
			Declare Short GetLastInputInfo In win32API String @ plii
		endif

		plii   = Chr(8) + Replicate( Chr(0), 7 )
		lcLast = GetLastInputInfo( @plii )
		lnLast = ( Asc( Substr( plii, 8, 1 ) ) * 16777216 ) + ;
				 ( Asc( Substr( plii, 7, 1 ) ) * 65536    ) + ;
				 ( Asc( Substr( plii, 6, 1 ) ) * 256      ) + ;
				   Asc( Substr( plii, 5, 1 ) )

		*	lnLast is the milliseconds the computer was on when the last keystroke or mousemove was.
		if m.lnLast = .nLastInputInfo
			*
			llIdleNow = .T.
		else
			.nLastInputInfo = m.lnLast
		endif

	else		&& if WinNT or lower, then use this less sophisticated method

		LOCAL lpPoint, llKeypress, llMouseMove, ln

		if m.tlInit
			declare short GetCursorPos     in win32api string @ lpPoint
			declare short GetAsyncKeyState In win32api integer nVirtKey
		endif
					
		lpPoint = space(8)		&& lp = local pointer
		
		*	Check mouse cursor position.
		if ( GetCursorPos( @lpPoint) # 0 AND m.lpPoint # .ptLastPoint )
			*
		    .ptLastPoint = m.lpPoint 	&& Save new pos
		    llMouseMove  = .T.
		endif
		
	 	*	Check keystate and mouse buttons.
	 	*	Also do it if llMouseMove is .T., in order to reset things. 
	 	*	That's why all 256 cycles are done anyway.
		for ln = 0 to 255
			If GetAsyncKeyState( m.ln ) # 0
				llKeypress = .T.
			endif
		next

		llIdleNow = ( not m.llMouseMove and not m.llKeypress )

	endif

	if m.llIdleNow
		*
		.nIdleMinutes = ( seconds() - .nIdleBaseline ) / 60
	else
		.nIdleBaseline  = seconds()
		.nIdleMinutes   = 0
	endif

	RETURN .nIdleMinutes
Groet,
Peter de Valença

Constructive frustration is the breeding ground of genius.
If there’s no willingness to moderate for the sake of good debate, then I have no willingness to debate at all.
Let's develop superb standards that will end the holy wars.
"There are three types of people: Alphas and Betas", said the beta decisively.
If you find this message rude or offensive or stupid, please take a step away from the keyboard and try to think calmly about an eventual a possible alternative explanation of my message.
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform