Board index » cppbuilder » IPC, using Application->OnMessage
Marc
![]() CBuilder Developer |
IPC, using Application->OnMessage2007-10-28 11:58:09 PM cppbuilder64 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); } //--------------------------------------------------------------------------- |