Mensaje    Asunto: Detectar Inactividad de la Aplicacion Responder citando

Este codigo permite detectar, la inactividad del la aplicacion cuando ha pasado cierto, tiempo (5 seg, por ejemplo)

Crea un Proyecto nuevo, y dentro del primer TForm1
establece el siguiente codigo..

archivo.cpp

Código:

//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "Unit1.h"
#include "Unit2.h"
//---------------------------------------------------------------------------
#pragma resource "*.dfm"
TForm1 *Form1;
TForm2 *pF; //un Form para mostrar algo
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
    : TForm(Owner)
{
    this->Tiempo=1;
    Application->OnMessage = ActividadCES;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::ActividadCES(tagMSG &Msg, bool &Handled)
{
    switch(Msg.message)
    {
        case WM_KEYDOWN:
        case WM_MBUTTONDOWN:
        case WM_LBUTTONDOWN:
        case WM_RBUTTONDOWN:
            Caption = Msg.wParam;
            if(Msg.wParam)
            {
                this->Timer1->Enabled=false;
                Tiempo=1;
            }
            break;
        default:
            this->Timer1->Enabled=true;
            break;
    }
}
// MENSAGE WM_ACTIVATE
void __fastcall TForm1::MyActivationCES(Messages::TWMActivate &Msg) //MESSAGE WM_ACTIVATE
{
    inherited::Dispatch( (void*)&Msg);
    if(Msg.Active)
    {
      this->Timer1->Enabled=false;
      Tiempo=1;
    }else{
        this->Timer1->Enabled=true;
    }

}
//---------------------------------------------------------------------------
void __fastcall TForm1::Timer1Timer(TObject *Sender)
{
    this->Tiempo++; // incrementamos el tiempo
    if(Tiempo>5) // 5 segundos
    {
        this->Timer1->Enabled=false; // apagamos para que no siga
        if(pF==NULL)
        {
            pF= new TForm2(this);
            pF->ShowModal();
            Tiempo=1;
            pF=NULL;
        }
    }

}
//---------------------------------------------------------------------------


Dentro del Archivo.h
Código:

//---------------------------------------------------------------------------

#ifndef Unit1H
#define Unit1H
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
#include <ComCtrls.hpp>
#include <ExtCtrls.hpp>
//---------------------------------------------------------------------------
class TForm1 : public TForm
{
__published:   // IDE-managed Components
    TStatusBar *StatusBar1;
    TEdit *Edit1;
    TMemo *Memo1;
    TTimer *Timer1;
    TButton *Button1;
    void __fastcall Timer1Timer(TObject *Sender);
private:   // User declarations
//-------------------------------------------------
int Tiempo;
//--------------------------------------------------------------------
void __fastcall ActividadCES(tagMSG &Msg, bool &Handled);
void __fastcall MyActivationCES(Messages::TWMActivate &Msg); //MESSAGE WM_ACTIVATE
//-----------------------------------------------------------
BEGIN_MESSAGE_MAP
    // NO LA ENCONTRE, en la VCL, no se donde esta
    MESSAGE_HANDLER(WM_ACTIVATE,  Messages::TWMActivate,MyActivationCES);
END_MESSAGE_MAP(inherited);
//-------------------------------------------------
public:      // User declarations
    __fastcall TForm1(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TForm1 *Form1;
//---------------------------------------------------------------------------
#endif

Los componentes, Edit, y memo de este formulario, solo sirven para detectar los estados de teclas que se presionan, dentro de ellos,

y dentro del TForm2, solo creas un form vacio, con un boton, en mi caso,
aparece el mensaje, "Volver a Conectar", dentro del boton, es una muestra.
saludos
_________________
Cool