FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour Quit the program when time out (like screen saver)
Posts: 1598
Joined: Fri Oct 07, 2005 05:56 PM
Quit the program when time out (like screen saver)
Posted: Sat Mar 10, 2012 03:44 PM

Dear All,

My customer ask for automatic quit or logout after specific time (like screen saver).

How can I do it? Any idea most welcome..

Regards,
Dutch

Regards,

Dutch



FWH 2304 / xHarbour Simplex 1.2.3 / BCC73 / Pelles C / UEStudio

FWPPC 10.02 / Harbour for PPC (FTDN)

ADS V.9 / MySql / MariaDB

R&R 12 Infinity / Crystal Report XI R2

(Thailand)
Posts: 68
Joined: Tue Apr 14, 2009 09:26 PM
Re: Quit the program when time out (like screen saver)
Posted: Sat Mar 10, 2012 04:10 PM
hello, see my class tinativo()

William Adami


Code (fw): Select all Collapse
* 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
*************

nTempo_espera:=10 //Tempo a ser esperado ate chamar a funcao

cNome_funcao:="LOGOFF()" //nome da funcao a ser chamada quando 
//chegar no tempo de espera

lTimercontinua:=.f. //se apos executar a funcao , continua monitorando 
//a inatividade do mouse e teclado.

define window oWnd title "Teste de teclado e mouse"

activate window oWnd on init tinativo():new(nTempo_espera,cNome_funcao, lTimerContinua)

return NIL


function logoff

msgalert("AQUI ENTRA SUA FUNCAO DE LOGOFF !","AVISO")

return nil


*****TINATIVO.PRG
*****************************************
* CLASSE PARA DETECTAR SE O SISTEMA ESTA 
* INATIVO POR (N) SEGUNDOS, E SE ESTIVER, 
* CHAMA UMA FUNCAO (PODE SER UMA FUNCAO 
* DE LOGOFF , DESCANSO DE TELA , ETC..)
*****************************************
* AUTOR DA FUNۂO ORIGINAL :
* POMPEO (GUARATINGUETA)
* MIGRAۂO DA FUNۂO PARA CLASSE:
* WILLIAM DE BRITO 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
*************************
::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)
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
Posts: 1598
Joined: Fri Oct 07, 2005 05:56 PM
Re: Quit the program when time out (like screen saver)
Posted: Mon Mar 12, 2012 04:55 AM

Dear William,

Thanks for nice class and example. It's really useful for me.

Regards,
Dutch

Regards,

Dutch



FWH 2304 / xHarbour Simplex 1.2.3 / BCC73 / Pelles C / UEStudio

FWPPC 10.02 / Harbour for PPC (FTDN)

ADS V.9 / MySql / MariaDB

R&R 12 Infinity / Crystal Report XI R2

(Thailand)
Posts: 7317
Joined: Thu Oct 18, 2012 07:17 PM
Re: Quit the program when time out (like screen saver)
Posted: Sat Apr 11, 2020 05:29 PM
WilliamAdami wrote:hello, see my class tinativo()

William Adami


Code (fw): Select all Collapse
* 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
*************

nTempo_espera:=10 //Tempo a ser esperado ate chamar a funcao

cNome_funcao:="LOGOFF()" //nome da funcao a ser chamada quando 
//chegar no tempo de espera

lTimercontinua:=.f. //se apos executar a funcao , continua monitorando 
//a inatividade do mouse e teclado.

define window oWnd title "Teste de teclado e mouse"

activate window oWnd on init tinativo():new(nTempo_espera,cNome_funcao, lTimerContinua)

return NIL


function logoff

msgalert("AQUI ENTRA SUA FUNCAO DE LOGOFF !","AVISO")

return nil


*****TINATIVO.PRG
*****************************************
* CLASSE PARA DETECTAR SE O SISTEMA ESTA 
* INATIVO POR (N) SEGUNDOS, E SE ESTIVER, 
* CHAMA UMA FUNCAO (PODE SER UMA FUNCAO 
* DE LOGOFF , DESCANSO DE TELA , ETC..)
*****************************************
* AUTOR DA FUNۂO ORIGINAL :
* POMPEO (GUARATINGUETA)
* MIGRAۂO DA FUNۂO PARA CLASSE:
* WILLIAM DE BRITO 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
*************************
::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)
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


cuando hay actividad es posible insertar una imagen o imágenes que caminan en la pantalla como si fuera un anuncio?
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)

I use : FiveWin for Harbour March-April 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
Posts: 8515
Joined: Tue Dec 20, 2005 07:36 PM
Re: Quit the program when time out (like screen saver)
Posted: Sun Apr 12, 2020 01:45 AM
João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
Posts: 1467
Joined: Mon Oct 10, 2005 11:26 AM
Re: Quit the program when time out (like screen saver)
Posted: Mon Apr 13, 2020 01:51 PM

Why making it so difficult.

It's quite easy.

Just start a timer. This timer checks for example every 30 seconds if a certain time has passed.
If so, just quit the program.

Not that difficult.

Regards,

Michel D.
Genk (Belgium)


_____________________________________________________________________________________________

I use : FiveWin for (x)Harbour v. 25.12 - Harbour 3.2.0 (May 2025) - xHarbour Builder (January 2020) - Bcc773

Continue the discussion