FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin para Harbour/xHarbour Ejemplo de Funcion sysIdleSecs()
Posts: 851
Joined: Sun Nov 09, 2014 05:01 PM
Ejemplo de Funcion sysIdleSecs()
Posted: Mon Nov 07, 2022 04: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 (fw): Select all Collapse
#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.
Posts: 8523
Joined: Tue Dec 20, 2005 07:36 PM
Re: Ejemplo de Funcion sysIdleSecs()
Posted: Mon Nov 07, 2022 07:35 PM
Thanks my dear friend. Asi 茅s bien mejor para se comprender el uso. Muchas gracias Jos茅.
Code (fw): Select all Collapse
// 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
Posts: 257
Joined: Mon Jun 10, 2013 06:40 PM
Re: Ejemplo de Funcion sysIdleSecs()
Posted: Thu Nov 10, 2022 03: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.

Posts: 8523
Joined: Tue Dec 20, 2005 07:36 PM
Re: Ejemplo de Funcion sysIdleSecs()
Posted: Thu Nov 10, 2022 05: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 (fw): Select all Collapse
// SHUTDOWN DEL WINDOWS - SHUTD.PRG

// http://fivewin.com.br/index.php?/topic/30343-identificar-que-o-windows-est%C3%A1-sendo-desligado-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
Posts: 257
Joined: Mon Jun 10, 2013 06:40 PM
Re: Ejemplo de Funcion sysIdleSecs()
Posted: Thu Nov 10, 2022 05:56 PM

karinha, Gracias por tu tiempo

Lo intento y les comento.

Saludos.

Continue the discussion