//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include <stdio.h>
#include "WinProcMain.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TfrmMain *frmMain;
//---------------------------------------------------------------------------
__fastcall TfrmMain::TfrmMain(TComponent* Owner) : TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TfrmMain::FormCreate(TObject *Sender)
{
mmoMessages->Align = alClient;
// Register your callback method here so that Windows knows that
// you want this to be called for each iteration of the message loop.
Application->OnMessage = MyMessageProc;
//Application->OnIdle = MyIdleProc;
}
//---------------------------------------------------------------------------
void __fastcall TfrmMain::MyIdleProc(TObject *sender, bool &Handled)
{
static unsigned count = 0;
count++;
if (btnToggleMessages->Down)
{
char buf[256];
sprintf(buf, "On idle %i", count);
mmoMessages->Lines->Add(buf);
// This is where you could put your own code that needs to
// execute for each iteration of the Windows message loop
}
// If you handle a specific message, set this to true so that Windows
// doesn't try to handle it again.
Handled = false;
}
void __fastcall TfrmMain::MyMessageProc(tagMSG &Msg, bool &Handled)
{
if (btnToggleMessages->Down)
{
//if (Msg.message != WM_MOUSEMOVE)
{
char buf[256];
// If you need to respond to a specific message, you can query
// the Msg parameter and get information from it.
sprintf(buf, "HWND: %6X, Msg ID: %6ul, WParam: %12i, LParam: %12i, Time: %8ul, Mouse: (%4i,%4i)",
Msg.hwnd, Msg.message, Msg.wParam, Msg.lParam, Msg.time, Msg.pt.x, Msg.pt.y);
mmoMessages->Lines->Add(buf);
}
// This is where you could put your own code that needs to
// execute for each iteration of the Windows message loop
}
// If you handle a specific message, set this to true so that Windows
// doesn't try to handle it again.
Handled = false;
}