Timeout to close App

Timeout to close App

Postby Jimmy » Thu Aug 08, 2024 4:58 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 ?
greeting,
Jimmy
User avatar
Jimmy
 
Posts: 1732
Joined: Thu Sep 05, 2019 5:32 am
Location: Hamburg, Germany

Re: Timeout to close App

Postby paquitohm » Thu Aug 08, 2024 7:26 am

Hi,

When App inactivity ?
paquitohm
 
Posts: 266
Joined: Fri Jan 14, 2022 8:37 am

Re: Timeout to close App

Postby Jimmy » Thu Aug 08, 2024 9:10 am

hi,
When App inactivity ?

i like to close App when there is NO INPUT from User or other Events
and REACTIVATE "TIMEOUT THREAD" after User have made some Input or move Mouse like Windows Screen Saver.
greeting,
Jimmy
User avatar
Jimmy
 
Posts: 1732
Joined: Thu Sep 05, 2019 5:32 am
Location: Hamburg, Germany

Re: Timeout to close App

Postby paquitohm » Thu Aug 08, 2024 9:32 am

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
 
Posts: 266
Joined: Fri Jan 14, 2022 8:37 am

Re: Timeout to close App

Postby Jimmy » Thu Aug 08, 2024 9:43 am

hi,
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.
can you please show me a CODE Snip how you did it ?
greeting,
Jimmy
User avatar
Jimmy
 
Posts: 1732
Joined: Thu Sep 05, 2019 5:32 am
Location: Hamburg, Germany

Re: Timeout to close App

Postby Jimmy » Thu Aug 08, 2024 10:01 am

hi,

found a Sample
Code: Select all  Expand view
// 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    
greeting,
Jimmy
User avatar
Jimmy
 
Posts: 1732
Joined: Thu Sep 05, 2019 5:32 am
Location: Hamburg, Germany

Re: Timeout to close App

Postby paquitohm » Thu Aug 08, 2024 10:25 am

Hi

Please, use
Code: Select all  Expand view
SysIdleSecs()
with Timer

Regards

Code: Select all  Expand view
#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
paquitohm
 
Posts: 266
Joined: Fri Jan 14, 2022 8:37 am

Re: Timeout to close App

Postby karinha » Thu Aug 08, 2024 11:52 am

Code: Select all  Expand view

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


Regards, saludos.
João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
User avatar
karinha
 
Posts: 7824
Joined: Tue Dec 20, 2005 7:36 pm
Location: São Paulo - Brasil

Re: Timeout to close App

Postby Jimmy » Thu Aug 08, 2024 1:08 pm

hi,

my Sample seems to work but it need a Keyboard Event (oDlg:bKeyDown = { || oDlg:End() } ) or a CLICK ( ON CLICK oDlg:End() ) to END().
how can i END() when just MOVE Mouse :?:
greeting,
Jimmy
User avatar
Jimmy
 
Posts: 1732
Joined: Thu Sep 05, 2019 5:32 am
Location: Hamburg, Germany

Re: Timeout to close App

Postby karinha » Thu Aug 08, 2024 2:01 pm

Try,

Code: Select all  Expand view

   oDlg:bRClicked := { |r,c,f,o| oDlg:End() }
 


Regards, saludos.
João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
User avatar
karinha
 
Posts: 7824
Joined: Tue Dec 20, 2005 7:36 pm
Location: São Paulo - Brasil

Re: Timeout to close App

Postby Jimmy » Thu Aug 08, 2024 4:11 pm

hi,

THX for Answer
oDlg:bRClicked := { |r,c,f,o| oDlg:End() }

but that still need a right CLICK, i just want to MOVE Mouse to END()

Function getInputState() seems me right, but i can´t figure out how to use it for END() to RE-Activate TIMER
greeting,
Jimmy
User avatar
Jimmy
 
Posts: 1732
Joined: Thu Sep 05, 2019 5:32 am
Location: Hamburg, Germany

Re: Timeout to close App

Postby Natter » Thu Aug 08, 2024 4:31 pm

Jimmy, make a window with your cross (bitmap button) and hang bMMoved on it
Natter
 
Posts: 1221
Joined: Mon May 14, 2007 9:49 am

Re: Timeout to close App

Postby Jimmy » Thu Aug 08, 2024 6:13 pm

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
greeting,
Jimmy
User avatar
Jimmy
 
Posts: 1732
Joined: Thu Sep 05, 2019 5:32 am
Location: Hamburg, Germany

Re: Timeout to close App

Postby Natter » Thu Aug 08, 2024 7:36 pm

Probably, you can do this
1. Make a TIMER
2. Make your own Handleevent() method and catch the mouse movement event in it (the TIMER is reset)
Natter
 
Posts: 1221
Joined: Mon May 14, 2007 9:49 am

Re: Timeout to close App

Postby Jimmy » Fri Aug 09, 2024 4:50 am

hi,
Natter wrote:1. Make a TIMER
2. Make your own Handleevent() method and catch the mouse movement event in it (the TIMER is reset)

YES, that seems to work using GetInputState(), but how to Reset Result of GetInputState() :?:
Code: Select all  Expand view
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
greeting,
Jimmy
User avatar
Jimmy
 
Posts: 1732
Joined: Thu Sep 05, 2019 5:32 am
Location: Hamburg, Germany

Next

Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 83 guests

cron