Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
THISFORM.Release if idle?
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
Gestionnaire d'écran & Écrans
Divers
Thread ID:
00064783
Message ID:
00064919
Vues:
39
>I want to close down a form after it has been inactive for a certain period of time. I'm assuming I should use a timer but I'm not sure how to use it properly to capture this situation. Any ideas?
Colin,

You can use a timer for this. There are two problems to track, one is the keyboard and it is the easy one. Use a baseformclass that has KeyPreview set to .T. and in the form's keypress set a custom form property (Named FormSeconds) to the return of Seconds() as in;

* Form class keypress
THISFORM.FormSeconds = SECONDS()

then in the timer's timer event you can;

IF Seconds() - THISFORM.Seconds > THIS.Interval
THISFORM.Release()
ENDIF

Now for the more difficult part, the second problem is the mouse. Keypress is not fired when the mouse moves and the user may be moving the mouse outside of the form so the mousemove for the form won't do either. I solved this one the following way. I gave the timer two custom properties named OldMRow and OldMCol and in the Init of the timer I did this;

THIS.OldMCol = MCOL("SCREEN")
THIS.OldMRow = MROW("SCREEN")

This record the current mouse position in respect to the entire Fox screen. Then in the timer event I do this;

IF ABS( THIS.OldMCol - MCOL("SCREEN")) > 1 OR ;
ABS( THIS.OldMRow - MROW("SCREEN")) > 1
THIS.OldMCol = MCOL("SCREEN")
THIS.OldMRow = MROW("SCREEN")
RETURN
ENDIF
THIS.OldMCol = MCOL("SCREEN")
THIS.OldMRow = MROW("SCREEN")
IF Seconds() - THISFORM.Seconds > THIS.Interval
THISFORM.Release()
ENDIF

Hope this helps get you started.
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform