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 ?
When App inactivity ?
paquitohm wrote:This is what you need ?
// 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 nil
SysIdleSecs()
#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() }
Natter wrote:1. Make a TIMER
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
Return to FiveWin for Harbour/xHarbour
Users browsing this forum: No registered users and 65 guests