Jump to content
Fivewin Brasil

Fechar o programa após 30 min sem uso


Jmsilva

Recommended Posts


* 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
*************

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


Link to comment
Share on other sites

  • 1 year later...
  • 2 years later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...