code:
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
const int HOTKEY_ID = 0x5555;
bool Stop=false;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
RegisterHotKey(Handle, HOTKEY_ID, 0, VK_F8); // Registra F8
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
for (int i=0;i<50000;i++)
{
ProgressBar1->Position = i; // tu operacion larga
if (i%1000)
{
Application->ProcessMessages();
if (Stop)
{
Stop=false;
break;
}
}
} // for
}
//---------------------------------------------------------------------------
void __fastcall TForm1::WMHotKey(TMessage& Msg)
{
if (Msg.WParam == HOTKEY_ID)
{
Stop=true;
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormClose(TObject *Sender, TCloseAction &Action)
{
UnregisterHotKey(Handle, HOTKEY_ID);
}
//---------------------------------------------------------------------------
Declara en el .h en la seccion private y protected lo siguiente:
code:
private: // User declarations
void __fastcall WMHotKey(TMessage& Msg);
public: // User declarations
__fastcall TForm1(TComponent* Owner);
protected:
BEGIN_MESSAGE_MAP
VCL_MESSAGE_HANDLER(WM_HOTKEY, TMessage, WMHotKey)
END_MESSAGE_MAP(TForm)
Saludos