Ejemplo de Funcion sysIdleSecs()

Ejemplo de Funcion sysIdleSecs()

Postby JoseAlvarez » Mon Nov 07, 2022 4:24 pm

Saludos.

Hace días, el Master Joao (Karinha), me solicitó que le dejara un ejemplo de la función "sysIdleSecs()"

Acá se los dejó, a él y a todo el foro, espero sea de utilidad para muchos.

NOTA: La función mide el tiempo transcurrido SIN actividad del mouse y teclado EN TODA LA PC , no es el tiempo sin actividad dentro de nuestra aplicación.

El contador de dicha función, se reinicia automaticamente a 0 cuando se realiza alguna operacion con el mouse o el teclado.

Un abrazo.



Code: Select all  Expand view
#Include "Cuentas32.ch"

// function to exit the app when default 'x' number of seconds pass with no activity
// from the keyboard or mouse.
// attention! IT IS NOT THE TIME without activity of our application, it is the inactive time of the PC

// función para salir de la aplicación cuando pasan 'x' cantidad de segundos predeterminados sin actividad
// del teclado o raton.
// ¡atención! NO ES EL TIEMPO sin actividad de nuestra aplicacion, es el tiempo inactivo de la PC

// função para sair do aplicativo quando o número padrão 'x' de segundos passa sem atividade
// do teclado ou mouse.
// atenção! NÃO É O TEMPO sem atividade do nosso aplicativo, é o tempo inativo do PC




Static oDlg, oTimerExit
Static nInterval

****************************************************************************************************************************
Function Fnct_Prueba()

    Local oGet1
    Local cVar1 := spac(10)

    Public nSecondsToOut:= 55 //(segundos)

    nInterval:=1*60000  //(1 x 60000 = 1 minuto)

    Define Dialog oDlg  resource "oDlg_Prueba"

         Redefine get oGet1 Var cVar1 Id 100  of oDlg

    Activate Dialog oDlg on init (oGet1:SetFocus(),Fnct_StartCounterTime() )

Return ( Nil )

***********************************************************************************************************************
Function Fnct_StartCounterTime ()

   Define Timer oTimerExit of oDlg Interval nInterval Action ( iif( sysIdleSecs()>nSecondsToOut,fExit(),))
   oTimerExit:Activate()

Return NIL
********************************************************************************************************************
function fExit()

    oTimerExit:Deactivate()
    oTimerExit:End()

    msgAlert('Tu Sesión Finalizó Por Inactividad.','Fin de Sesión')

    oDlg:End()
    quit

return .t.
*********************************************************************************************************************

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


NOTA: El archivo "Cuentas32.ch" que esta al inicio del código, es mi versión personalizada del "Fivewin.ch"
"Los errores en programación, siempre están entre la silla y el teclado..."

Fwh 19.06 32 bits + Harbour 3.2 + Borland 7.4 + MariaDB + TDolphin

Carora, Estado Lara, Venezuela.
User avatar
JoseAlvarez
 
Posts: 726
Joined: Sun Nov 09, 2014 5:01 pm

Re: Ejemplo de Funcion sysIdleSecs()

Postby karinha » Mon Nov 07, 2022 7:35 pm

Thanks my dear friend. Asi és bien mejor para se comprender el uso. Muchas gracias José.

Code: Select all  Expand view

// C:\FWH..\SAMPLES\SYSIDLE.PRG - By Jose Alvarez.
// MOD. EN: 07/11/2022 By kapiabafwh@gmail.com - São Paulo - Brasil.

#include "FiveWin.ch"

/*
// function to exit the app when default 'x' number of seconds pass with no activity
// from the keyboard or mouse.
// attention! IT IS NOT THE TIME without activity of our application, it is the inactive time of the PC

// función para salir de la aplicación cuando pasan 'x' cantidad de segundos predeterminados sin actividad
// del teclado o raton.
// ¡atención! NO ES EL TIEMPO sin actividad de nuestra aplicacion, es el tiempo inactivo de la PC

// função para sair do aplicativo quando o número padrão 'x' de segundos passa sem atividade
// do teclado ou mouse.
// atenção! NÃO É O TEMPO sem atividade do nosso aplicativo, é o tempo inativo do PC
*/


STATIC oDlg, oFont, oTimerExit
STATIC nInterval

MEMVAR nSecondsToOut

FUNCTION Fnct_Prueba()

   LOCAL oGet1, oBtnX2, cTitle, aGrad, oSay
   LOCAL cVar1 :=  [SYSIDLE.PRG: BY JOSE ALVAREZ.     ]

   HB_GCALL( .F. )

   nSecondsToOut := 55 // (segundos)

   nInterval := 1 * 60000  //(1 x 60000 = 1 minuto)

   aGrad  := { { 0.30, CLR_WHITE, CLR_HCYAN },{ 0.30, CLR_WHITE, CLR_HCYAN } }

   cTitle := "MOVE MOUSE: PRUEBA DE SYSIDLE.PRG: BY JOSE ALVAREZ"

   DEFINE FONT oFont NAME "TAHOMA" SIZE 0, - 14

   DEFINE DIALOG oDlg SIZE 600, 200  PIXEL TRUEPIXEL RESIZABLE      ;
      TITLE cTitle GRADIENT aGrad FONT oFont

   @ 050, 10 GET oGet1 VAR cVar1 bitmap "..\bitmaps\chkyes.bmp" ;
      OF oDlg PIXEL SIZE 300, 24 FONT oFont                     ;
      ACTION( NIL )
   
   oGet1:lBtnTransparent := .T.       // transparent button get oGet1
   oGet1:lAdjustBtn      := .T.       // Button Get Adjust Witdh oGet3
   oGet1:lDisColors      := .F.       // Deactive disable color
   oGet1:nClrTextDis     := CLR_WHITE // Color text disable status
   oGet1:nClrPaneDis     := CLR_BLUE  // Color Pane disable status

   @ 095, 10 SAY oSay PROMPT "This a Test: No Move Mouse Wait 1 Minute." ;
      OF oDlg SIZE 150, 14 COLOR CLR_BLACK, CLR_WHITE PIXEL FONT oFont   ;
      TRANSPARENT ADJUST

   @ 120, 250 BTNBMP oBtnx2 SIZE 60, 60 PIXEL OF oDlg FLAT NOBORDER ;
      PROMPT "Exit" FILENAME "..\bitmaps\16x16\Exit.bmp" BOTTOM     ;
      COLOR CLR_BLACK, nRgb( 238, 236, 219 ) ACTION( oDlg:End() )

   oBtnX2:lCancel := .T.

   ACTIVATE DIALOG oDlg CENTERED ;
      ON INIT ( oGet1:SetFocus(), Fnct_StartCounterTime() )

RETURN NIL

FUNCTION Fnct_StartCounterTime ()

   DEFINE TIMER oTimerExit OF oDlg INTERVAL nInterval ;
      ACTION ( IIF( sysIdleSecs() > nSecondsToOut, fExit(), ) )

   oTimerExit:Activate()

RETURN NIL

FUNCTION fExit()

   oTimerExit:Deactivate()
   oTimerExit:End()

   MsgAlert( 'Tu Sesión Finalizó Por Inactividad.', 'Fin de Sesión' )

   oDlg:End()
   RELEASE FONT oFont

   FreeResources()
   Release All
   SysRefresh()
   HB_GCALL( .T. )

   CLEAR MEMORY

   PostQuitMessage( 0 )

   QUIT

RETURN NIL

// typedef struct tagLASTINPUTINFO {
//    UINT cbSize;
//    DWORD dwTime;
// } LASTINPUTINFO, *PLASTINPUTINFO;

#pragma BEGINDUMP

#include "windows.h"

#include "hbapi.h"

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

// FIN / END
 


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

Re: Ejemplo de Funcion sysIdleSecs()

Postby VitalJavier » Thu Nov 10, 2022 3:48 pm

Hola, que tal
Se podría hacer, que al terminar el sistema
mande un "apagado de computadora"
Tomando en cuenta el dia y hora ?

Saludos.
VitalJavier
 
Posts: 228
Joined: Mon Jun 10, 2013 6:40 pm

Re: Ejemplo de Funcion sysIdleSecs()

Postby karinha » Thu Nov 10, 2022 5:53 pm

VitalJavier wrote:Hola, que tal
Se podría hacer, que al terminar el sistema
mande un "apagado de computadora"
Tomando en cuenta el dia y hora ?

Saludos.


Simples,

Code: Select all  Expand view

// SHUTDOWN DEL WINDOWS - SHUTD.PRG

// http://fivewin.com.br/index.php?/topic/ ... resolvido/

FUNCTION u_Teste()

   Local cFile := "c:\teste.txt"
 
   While LastKey() # 27 .and. !IsShutDown()

      MemoWrit(cFile, "terminado forçadamente")

      Inkey(.1)

   EndDo
 
   MemoWrit(cFile, "terminado de maneira normal")

RETURN NIL
 
#pragma BEGINDUMP
#include "windows.h"
#include "hbapi.h"
#include <stdio.h>
 
#define SM_SHUTTINGDOWN 0x2000
 
HB_FUNC( ISSHUTDOWN )
{
    BOOL  bRetorno = GetSystemMetrics(SM_SHUTTINGDOWN) != 0;;
    hb_retl( bRetorno );
}
#pragma ENDDUMP

// FIN / END
 



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

Re: Ejemplo de Funcion sysIdleSecs()

Postby VitalJavier » Thu Nov 10, 2022 5:56 pm

karinha, Gracias por tu tiempo
Lo intento y les comento.

Saludos.
VitalJavier
 
Posts: 228
Joined: Mon Jun 10, 2013 6:40 pm


Return to FiveWin para Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 112 guests