Article View: borland.public.cppbuilder.nativeapi
Article #6977Sending and receiving custom messages between applications (code included)
From: Giatto Cardiacci
Date: Wed, 30 Mar 2005 13:57
Date: Wed, 30 Mar 2005 13:57
58 lines
2742 bytes
2742 bytes
Using RegisterWindowMessage / WndProc(..) / and
SendMessage(HWND_BROADCAST,...) is one of the way sending "custom" message
to one or multiple applications. The following code and a better on at [1]
show how to use these API functions. This approach seems work "fine" but
SLOW!...
The following code sends 100 message to other applications in approxiatelly
2.8 sec on a 2GHz notebook running WinXP.
Is there a "trick" to make it faster OR better way to send/receive messages
among multiple applications?
const AnsiString PrivateMessageID =
"{7395314D-3A02-4887-A60F-BD029D1FF009}";
int N =0;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
PrivateMessage = RegisterWindowMessage(PrivateMessageID.c_str());
}
//---------------------------------------------------------------------------
void __fastcall TForm1::WndProc(Messages::TMessage& Message)
{
if (Message.Msg == PrivateMessage) {
if (Message.WParam ==0){ // Display only the first message
AnsiString S;
S.sprintf("%d - WParam: %.05d LParam: %.05d at %s",
N, Message.WParam,
Message.LParam, AnsiString(Now()).c_str()
);
Memo1->Lines->Add(S);
}
N++;
}
TForm::WndProc(Message);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
TDateTime T0, T1;
T0 = Now();
for (int i=0; i<100; i++)
SendMessage(HWND_BROADCAST,PrivateMessage,i,i*10);
T1 = Now();
AnsiString S;
DateTimeToString(S, "ss:zzz",T1-T0);
Caption = S; // <--- It display around 02.804 sec on 2GHz notebook PC
}
[1] "Sending and receiving custom messages" by Hens Zimmerman URL:
http://cc.borland.com/ccWeb.exe/listing?id=15251
Technical Details
Message-ID:
<424ab04c$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!news.glorb.com!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,775f7f4787da1067,start X-Google-Attributes: gid10cc67,public X-Google-Language: ENGLISH,ASCII-7-bit From: <Giatto Cardiacci> Newsgroups: borland.public.cppbuilder.nativeapi Subject: Sending and receiving custom messages between applications (code included) Date: Wed, 30 Mar 2005 23:57:21 +1000 Lines: 60 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.2180 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180 X-RFC2646: Format=Flowed; Original NNTP-Posting-Host: 211.30.60.151 Message-ID: <424ab04c$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1112191052 211.30.60.151 (30 Mar 2005 05:57:32 -0800) Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!news.glorb.com!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail