Article View: borland.public.cppbuilder.nativeapi
Article #1139IPC, using Application->OnMessage
From: Marc
Date: Sun, 28 Oct 2007 15:58
Date: Sun, 28 Oct 2007 15:58
73 lines
3467 bytes
3467 bytes
Hi all
After another sleepless night here another question:
I try to implement IPC between my two processes.
For a test I implemented a simple form with one button that sends a message
PostMessage(HWND_BROADCAST, msgTEST, 0, 0);
and a OnMessage handle that receives this message.
if (Msg.message == msgTEST)
{
OutputDebugString("Message received");
Handled=true;
}
I use HWND_BROADCAST because in future the sender and receiver will be in
two separate processes.
msgTEST is registered using
msgTEST = RegisterWindowMessage("msgTest");
If I run the application like this and press the button, I receive one
OutputDebugString. This is what I expected.
But when I create a second form, and place a TTimer component on it, I
receive the OutputDebugString twice. If I place two TTimer component on it,
I receive the OutputDebugString three times. The second form is not event
referenced in my first form.
Curious enough this does not happen with a TButton component, so it depends
on the component I place on this second form.
Does this make sense ?
Is not the "Handled=true" statement supposed to prevent the message from
being sent to another Window ?
Rds
Marc
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
UINT msgTest;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::AppMessage(tagMSG &Msg, bool &Handled)
{
if (Msg.message == msgTest)
{
OutputDebugString("Message received");
Handled=true;
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormCreate(TObject *Sender)
{
msgTest = RegisterWindowMessage("msgTest");
Application->OnMessage = AppMessage;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
PostMessage(HWND_BROADCAST, msgTest, 0, 0);
}
//---------------------------------------------------------------------------
Technical Details
Message-ID:
<4724b19d$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news2.google.com!news3.google.com!feeder3.cambrium.nl!feeder1.cambrium.nl!feed.tweaknews.nl!news2.euro.net!newsfeed.freenet.de!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,4f22b81ff465f675,start X-Google-Attributes: gid10cc67,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Reply-To: "Marc" <info@mawnet.com> From: "Marc" <info@mawnet.com> Newsgroups: borland.public.cppbuilder.nativeapi Subject: IPC, using Application->OnMessage Date: Sun, 28 Oct 2007 16:58:09 +0100 Lines: 78 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.3138 X-RFC2646: Format=Flowed; Original X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.3198 NNTP-Posting-Host: 83.77.32.136 Message-ID: <4724b19d$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1193587101 83.77.32.136 (28 Oct 2007 08:58:21 -0700) Path: arc1-ca.pugleaf.net!g2news2.google.com!news3.google.com!feeder3.cambrium.nl!feeder1.cambrium.nl!feed.tweaknews.nl!news2.euro.net!newsfeed.freenet.de!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail