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 ?
Jimmy
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 ?
Hi,
When App inactivity ?
When App inactivity ?i like to close App when there is NO INPUT from User or other Events
Hi,
In my case I close automatically the application after a (parameterized) time when the program has no activity. 1st try soft close (closing dialogs and windows) 2nd. try hard close.
What do I consider activity? Activity is that there is no keyboard or mouse input or the App is an automatic process without user intervention, which is detected by observing if a dbf table was opened or if its pointer has changed from the existing ones. For this I use a Timer.
This is what you need ?
Salu2
paquitohm wrote:This is what you need ?YES, that is exact what i mean, but i don´t know how to detect "no User input" using a TIMER and how to REACTIVATE TIMER when there was any Event.
// How to create a screensaver that will be executed when a GET is not used for some time
#include "FiveWin.ch"
static nTime := 0
function Main()
local oDlg, oSay, oGet, cTest := Space( 10 )
DEFINE DIALOG oDlg TITLE "Test"
@ 0.5, 8 SAY oSay PROMPT "Elapsed time: " + AllTrim( Str( nTime ) ) + " secs."
@ 3, 7 GET oGet VAR cTest PASSWORD
ACTIVATE DIALOG oDlg CENTERED ;
ON INIT BuildTimer( oDlg, oSay, oGet )
return nil
function BuildTimer( oDlg, oSay, oGet )
local oTmr
DEFINE TIMER oTmr OF oDlg ;
ACTION ( nTime++, oSay:Refresh(), If( nTime > 14, ScreenSaver(),)) INTERVAL 1000
ACTIVATE TIMER oTmr
oGet:bKeyDown = { | nKey | nTime := 0, nKey }
return nil
function ScreenSaver()
static oDlg
nTime = 0
if oDlg == nil
ShowWindow( FindWindow( "Shell_TrayWnd", "" ), 0 ) // Taskbar
ShowWindow( FindWindow( "Button", "Start" ), 0 ) // Vista round button
DEFINE DIALOG oDlg STYLE WS_VISIBLE COLOR "W/B" SIZE GetSysMetrics( 0 ), GetSysMetrics( 1 )
@ 10, 10 SAY "This is a screensaver" COLOR "W/B"
oDlg:bKeyDown = { || oDlg:End() }
ACTIVATE DIALOG oDlg ;
ON CLICK oDlg:End()
ShowWindow( FindWindow( "Shell_TrayWnd", "" ), 1 )
ShowWindow( FindWindow( "Button", "Start" ), 1 )
oDlg = nil
nTime = 0
endif
return nilSysIdleSecs()#pragma BEGINDUMP
#include "windows.h"
#include "hbapi.h"
// typedef struct tagLASTINPUTINFO {
// UINT cbSize;
// DWORD dwTime;
// } LASTINPUTINFO, *PLASTINPUTINFO;
WINUSERAPI BOOL WINAPI GetLastInputInfo(PLASTINPUTINFO);
typedef BOOL (WINAPI *GETLASTINPUTINFO_)(PLASTINPUTINFO);
HB_FUNC( SYSIDLESECS )
{
HINSTANCE handle= LoadLibrary("user32.dll");
if ( handle)
{
GETLASTINPUTINFO_ pFunc;
pFunc = GetProcAddress( handle,"GetLastInputInfo" );
if (pFunc)
{
LASTINPUTINFO lpi;
lpi.cbSize = sizeof(LASTINPUTINFO);
if (!pFunc(&lpi))
{
hb_retni(0);
}
else
{
hb_retnd( ( DOUBLE ) ( GetTickCount() - lpi.dwTime ) * 0.001 );
}
}
else
{
hb_retni(0);
}
}
if (handle)
{
FreeLibrary( handle);
}
}
#pragma ENDDUMP// tinativo.prg - By William Adami
// exemplo do uso da classe Tinativo
// Apos um tempo de inatividade do mouse
// e do teclado chama uma funcao qualquer.
#include "fivewin.ch"
STATIC oWnd
//************
FUNCTION Main()
LOCAL nTempo_espera, cNome_funcao, lTimercontinua
// Tempo a ser esperado ate chamar a funcao
// -> 1 hora tem 3600 segundos.
nTempo_espera := 10 // segundos.
// nome da funcao a ser chamada quando
// chegar no tempo de espera
cNome_funcao := "LOGOFF()"
// se apos executar a funcao , continua
// monitorando a inatividade do mouse e teclado.
lTimercontinua := .F.
DEFINE WINDOW oWnd TITLE "Teste de teclado e mouse"
ACTIVATE WINDOW oWnd CENTERED ;
ON INIT tinativo():new( nTempo_espera, cNome_funcao, lTimerContinua )
RETURN NIL
FUNCTION LOGOFF()
// msgalert( "LOGOFF !", "AVISO" )
/*
IF MsgYesNo( OemToAnsi( "ATEN€ÇO USUµRIO: " )+CRLF+ ;
OemToAnsi( "PROTEJA OS BANCOS DE DADOS DO PROGRAMA." )+CRLF+ ;
OemToAnsi( "SE NÇO ESTIVER USANDO O WINORCAM.EXE, " )+CRLF+ ;
OemToAnsi( "DESLIGUE-O PARA NÇO CORRER RISCOS. " )+CRLF+ ;
OemToAnsi( "POSSO DESLIGAR O PROGRAMA? <S> ou <N>??" ), ;
OemToAnsi( "AVISO PARA DESLIGAR O WINORCAM.EXE... " ) )
//--Fecha o Programa Definitivamente
LIBERA_TUDO() // ESTA EM WINORCAM.PRG
// QUIT
ENDIF
*/
MsgRun( 'ATENÇÃO:', "LEIA Antes - Aguarde ...", { | o | EsperarMsgRun( o ) } )
RETURN NIL
FUNCTION EsperarMsgRun( o )
LOCAL nSec, cTitle
nSec := 20
cTitle := o:cTitle
WHILE nSec >= 0
SYSREFRESH()
o:cTitle := cTitle + ' ' + StrZero( nSec--, 2 )
WaitSeconds( 1 )
ENDDO
RETURN NIL
// tinativo.prg - By William Adami
// #include "fivewin.ch"
CLASS TINATIVO
DATA nTimeInpAntes
DATA nTimeInpDepois
DATA cTimeAtu
DATA nTempo
DATA oTimerTime
DATA cFunc
DATA lContinuar
METHOD NEW( nTime, cFuncao, lContinua ) CONSTRUCTOR
METHOD ver_tempo()
ENDCLASS
METHOD new( ntime, cFuncao, lContinua ) CLASS TINATIVO
::cfunc := cfuncao
::ntempo := ntime
::lContinuar := lContinua
::oTimerTime := TTimer():New( 1000, { || ::VER_TEMPO() } )
::oTimerTime:Activate()
::cTimeAtu := time()
::nTimeInpAntes := getInputState() // 0 = erro
RETURN self
METHOD VER_TEMPO CLASS TINATIVO
LOCAL AUX
::nTimeInpDepois := getInputState()
IF ( ::nTimeInpDepois - ::nTimeInpAntes ) > 0
::nTimeInpAntes := getInputState()
::cTimeAtu := time()
ENDIF
IF ( CONVTIME( time() ) - CONVTIME( ::cTimeAtu ) ) > ::ntempo
::oTimerTime:DeActivate()
aux := ::cfunc
// aqui executa a funcao
&aux
if ::lContinuar
::oTimerTime:Activate()
::cTimeAtu := time()
ENDIF
ENDIF
RETURN NIL
FUNCTION CONVTIME( ZZ )
LOCAL Z
Z := ( VAL( LEFT(ZZ,2 ) ) * 360 ) + ( VAL( SUBSTR(ZZ,4,2 ) ) * 60 ) + ;
VAL( RIGHT( ZZ,2 ) )
RETURN Z
//*----------------------------------------------------------------------
#pragma BEGINDUMP
#define _WIN32_WINNT 0x0500
#define WINVER 0x0500
#include "windows.h"
#include "hbapi.h"
HB_FUNC( GETINPUTSTATE )
{
LASTINPUTINFO lpi;
lpi.cbSize = sizeof(LASTINPUTINFO);
if (!GetLastInputInfo(&lpi))
{
hb_retni(0);
}
hb_retni(lpi.dwTime);
}
#pragma ENDDUMP
// FIN / END oDlg:bRClicked := { |r,c,f,o| oDlg:End() }oDlg:bRClicked := { |r,c,f,o| oDlg:End() }but that still need a right CLICK, i just want to MOVE Mouse to END()
Jimmy, make a window with your cross (bitmap button) and hang bMMoved on it
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
Probably, you can do this
Make a TIMER
Make your own Handleevent() method and catch the mouse movement event in it (the TIMER is reset)
Natter wrote:1. Make a TIMERYES, that seems to work using GetInputState(), but how to Reset Result of GetInputState() :?:
2. Make your own Handleevent() method and catch the mouse movement event in it (the TIMER is reset)
FUNCTION Main
Local nIdleTimeToClose := 10
DEFINE WINDOW sample at 0,0 WIDTH 640 HEIGHT 480 ;
TITLE "Demo idle timeout"
...
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
// work when MOVE Mouse
if GetInputState() > 0
// Long TIMEOUT
IF ( nIdleTimeToClose - SysIdleSecs() ) < -99
sample.IdleTimeout.Release
MessageBoxTimeout ( "The TIMEOUT has been reached, the application will be closed in 3 seconds.", "Idle state", MB_ICONWARNING + MB_TOPMOST, 3 * 1000 )
ReleaseAllWindows()
ELSE
sample.Title := "Return timeout remains: " + StrZero ( nIdleTimeToClose - SysIdleSecs(), 4 )
ENDIF
ELSE
// never get here
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()
ENDIF
ENDIF
**********************************************************************************************
#pragma BEGINDUMP
#include "windows.h"
#include "time.h"
#include "hbapi.h"
HB_FUNC( GETINPUTSTATE )
{
LASTINPUTINFO lpi;
lpi.cbSize = sizeof(LASTINPUTINFO);
if (!GetLastInputInfo(&lpi))
{
hb_retni(0);
}
hb_retni(lpi.dwTime);
}
HB_FUNC( SYSIDLESECS )
{
LASTINPUTINFO lpi;
lpi.cbSize = sizeof (LASTINPUTINFO);
GetLastInputInfo (&lpi);
hb_retnd( ( DOUBLE ) ( GetTickCount() - lpi.dwTime ) / CLOCKS_PER_SEC );
}
#pragma ENDDUMP