Page 1 of 2
Timeout to close App
Posted: Thu Aug 08, 2024 5:32 am
by AUGE_OHR
hi,
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

Re: Timeout to close App
Posted: Thu Aug 08, 2024 9:45 am
by AUGE_OHR
AUGE_OHR wrote: ↑Thu Aug 08, 2024 5:32 am
hi,
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 and REACTIVATE TIMER when there was any Event

Re: Timeout to close App
Posted: Thu Aug 08, 2024 12:53 pm
by edk
Re: Timeout to close App
Posted: Thu Aug 08, 2024 2:27 pm
by AUGE_OHR
hi Edward,
THX for help.
HB_FUNC SYSIDLESECS() work fine and will interrupt TIMER Countdown
but when reach Msgstop it need a Click or Keyboard to continue, how can i use SYSIDLESECS() instead to continue
Re: Timeout to close App
Posted: Thu Aug 08, 2024 3:06 pm
by edk
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
Re: Timeout to close App
Posted: Thu Aug 08, 2024 3:41 pm
by AUGE_OHR
hi Edward,
THX for new SAMPLE, but you misunderstood how i want it working
it work right upto TIMEOUT, but than i like to RE-Activate TIMER when just MOVE Mouse.
NO CLICK or KEYBOARD Input, like when other TEXTBOX get Focus
Re: Timeout to close App
Posted: Thu Aug 08, 2024 4:15 pm
by edk
I don't understand why you want to reactivate the timer. After all, when you move the mouse it resets the idle time in SysIdleSecs and the idle time check starts running from the beginning.
Re: Timeout to close App
Posted: Thu Aug 08, 2024 5:02 pm
by AUGE_OHR
hi,
edk wrote: ↑Thu Aug 08, 2024 4:15 pm
I don't understand why you want to reactivate the timer.
After all, when you move the mouse it resets the idle time in SysIdleSecs and the idle time check starts running from the beginning.
as i understand you use a TIMER to get into Function CheckIdleTimeout()
in Function CheckIdleTimeout( nIdleTimeToClose ) you compare it with SysIdleSecs()
but is does NOT reset the idle time in SysIdleSecs, when MOVE Mouse in THAT Function, only before i got into Function CheckIdleTimeout()
so i need something like
Code: Select all
IF GetInputState() > 0
// RESET TIMER
ELSE
MessageBoxTimeout()
ReleaseAllWindows()
ENDIF
IN Function CheckIdleTimeout()
Re: Timeout to close App
Posted: Thu Aug 08, 2024 5:48 pm
by edk
You can't reset the idle time value, because that's done by the system. I disagree with you that SysIdleSecs doesn't reset the value on mouse movement, when it's in the CheckIdleTimeout() function. See the following example:
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
I don't know which timer you want to reset: SysIdleSecs() or TIMER IdleTimeOut ?
Re: Timeout to close App
Posted: Thu Aug 08, 2024 6:12 pm
by AUGE_OHR
hi,
i like to build 2 Level Timeout
1st. Level is from DIalog into Screen Save while close DBF when TIMEOUT
2nd. Level is from Screen Saver to Quit App when TIMEOUT
but when press any or MOVE Mouse within 2nd Level i want to Return into 1st Level Dialog
1st. Level already work perfect, but i still have Problem in 2nd. Level when only MOVE Mouse to Return into 1st. Level Dialog