i like to close DBF /App after "Timeout" but how

when using a TIMER how can i "stop TIMER" when i got a Keyboard or Mouse Event

Moderator: Rathinagiri
Code: Select all
#include "hmg.ch"
#include "i_MsgBox.ch"
*************
FUNCTION Main
*************
Local nIdleTimeToClose := 10
define window sample at 0,0 width 640 height 480 ;
title "Demo idle timeout"
@12, 10 LABEL Label_1 VALUE "Text_1" width 80 RIGHTALIGN
@10, 95 TEXTBOX Text_1 ;
VALUE 10 ;
NUMERIC
@42, 10 LABEL Label_2 VALUE "Text_2" width 80 RIGHTALIGN
@40, 95 TEXTBOX Text_2 ;
VALUE 20 ;
NUMERIC
@72, 10 LABEL Label_3 VALUE "Text_3" width 80 RIGHTALIGN
@70, 95 TEXTBOX Text_3 ;
VALUE 30 ;
NUMERIC
DEFINE TIMER IdleTimeOut INTERVAL 1000 ACTION CheckIdleTimeout( nIdleTimeToClose )
end window
sample.Text_1.setfocus
center window sample
activate window sample
RETURN Nil
Function CheckIdleTimeout( nIdleTimeToClose )
IF SysIdleSecs() >= nIdleTimeToClose
sample.IdleTimeout.Release
MessageBoxTimeout ( "The idle time has been reached, the application will be closed in 3 seconds.", "Idle state", MB_ICONWARNING + MB_TOPMOST, 3 * 1000 )
ReleaseAllWindows()
ELSE
sample.Title := "Demo idle timeout Idle timeout remains: " + StrZero ( nIdleTimeToClose - SysIdleSecs(), 3 )
ENDIF
RETURN Nil
//----------------------------------------------------------------------
#pragma BEGINDUMP
#include "windows.h"
#include "time.h"
#include "hbapi.h"
HB_FUNC( SYSIDLESECS )
{
LASTINPUTINFO lpi;
lpi.cbSize = sizeof (LASTINPUTINFO);
GetLastInputInfo (&lpi);
hb_retnd( ( DOUBLE ) ( GetTickCount() - lpi.dwTime ) / CLOCKS_PER_SEC );
}
#pragma ENDDUMP
as i understand you use a TIMER to get into Function CheckIdleTimeout()
Code: Select all
IF GetInputState() > 0
// RESET TIMER
ELSE
MessageBoxTimeout()
ReleaseAllWindows()
ENDIF
Code: Select all
#include "hmg.ch"
#include "i_MsgBox.ch"
*************
FUNCTION Main
*************
Local nIdleTimeToClose := 10
define window sample at 0,0 width 640 height 480 ;
title "Demo idle timeout"
@12, 10 LABEL Label_1 VALUE "Text_1" width 80 RIGHTALIGN
@10, 95 TEXTBOX Text_1 ;
VALUE 10 ;
NUMERIC
@42, 10 LABEL Label_2 VALUE "Text_2" width 80 RIGHTALIGN
@40, 95 TEXTBOX Text_2 ;
VALUE 20 ;
NUMERIC
@72, 10 LABEL Label_3 VALUE "Text_3" width 80 RIGHTALIGN
@70, 95 TEXTBOX Text_3 ;
VALUE 30 ;
NUMERIC
@130, 10 LABEL Label_Idle VALUE "Idle time: " + StrZero ( SysIdleSecs(), 4 ) width 600
DEFINE TIMER IdleTimeOut INTERVAL 1000 ACTION CheckIdleTimeout( nIdleTimeToClose )
end window
sample.Text_1.setfocus
center window sample
activate window sample
RETURN Nil
Function CheckIdleTimeout( nIdleTimeToClose )
Local nIdleTime
IF SysIdleSecs() >= nIdleTimeToClose
sample.IdleTimeout.Enabled := .F.
Do while (nIdleTime := SysIdleSecs()) > 0
sample.Label_Idle.Value := "Idle timeout reached!!! Try moving your mouse. Idle time:" + StrZero ( nIdleTime, 4 )
//DO Events
ENDDO
sample.Label_Idle.FontBold := .T.
sample.Label_Idle.Value := "SysIdleSecs() has been reset!"
sample.IdleTimeout.Enabled := .T.
// sample.IdleTimeout.Release
// MessageBoxTimeout ( "The idle timeout has been reached, the application will be closed in 3 seconds.", "Idle state", MB_ICONWARNING + MB_TOPMOST, 3 * 1000 )
// ReleaseAllWindows()
ELSE
sample.Label_Idle.FontBold := .F.
sample.Label_Idle.Value := "Idle time: " + StrZero ( SysIdleSecs(), 4 )
sample.Title := "Demo idle timeout Idle timeout remains: " + StrZero ( nIdleTimeToClose - SysIdleSecs(), 3 )
ENDIF
RETURN Nil
//----------------------------------------------------------------------
#pragma BEGINDUMP
#include "windows.h"
#include "time.h"
#include "hbapi.h"
HB_FUNC( SYSIDLESECS )
{
LASTINPUTINFO lpi;
lpi.cbSize = sizeof (LASTINPUTINFO);
GetLastInputInfo (&lpi);
hb_retnd( ( DOUBLE ) ( GetTickCount() - lpi.dwTime ) / CLOCKS_PER_SEC );
}
#pragma ENDDUMP