Board index » cppbuilder » HWND_BROADCAST handle

HWND_BROADCAST handle


2006-02-15 04:42:58 AM
cppbuilder97
Hello. I defined a new windows message as
WM_MY_MESSAGE = RegisterWindowsMessage("WM_MY_MESSAGE") in two
applications that must work at once. One application intended to send this
message and another to catch.
The problem is that i cant catch this message if it has been sent with
HWND_BROADCAST parameter in SendMessage (...) or PostMessage(...) function.
The mainform class of receiving application is populated with begin_message
macros (i used WndProc functions as well) but no result comes out of it.
The broadcast message seems to be not working.
Where is the problem?
Andrew.
 
 

Re:HWND_BROADCAST handle

"Andrew Fedoseev" < XXXX@XXXXX.COM >wrote in message
Quote
The problem is that i cant catch this message if it has been
sent with HWND_BROADCAST parameter in SendMessage (...)
or PostMessage(...) function.
Yes, you can. See below.
Quote
The mainform class of receiving application is populated with
begin_message macros (i used WndProc functions as well) but
no result comes out of it.
That is because you are catching the message in the wrong window. You need
to catch it from the TApplication window, not the TForm window. Call the
TApplication::HookMainWindow() method in order to catch messages that are
processed by the TApplication window, ie:
__fastcall TForm1::TForm1(TComponent *Owner)
: TForm(Owner)
{
Application->HookMainWindow(MyAppHook);
}
__fastcall TForm1::TForm1(TComponent *Owner)
: TForm(Owner)
{
Application->UnhookMainWindow(MyAppHook);
}
bool __fastcall TForm1::MyAppHook(TMessage &Message)
{
if( Message.Msg == WM_MY_MESSAGE )
{
// ...
return true;
}
else
return (Message.Msg == WM_INITDIALOG);
}
Gambit
 

Re:HWND_BROADCAST handle

It worked, thank you.
"Remy Lebeau (TeamB)" < XXXX@XXXXX.COM >сообщи?сообщила ?новостях
следующе? news: XXXX@XXXXX.COM ...
Quote

"Andrew Fedoseev" < XXXX@XXXXX.COM >wrote in message
news: XXXX@XXXXX.COM ...

>The problem is that i cant catch this message if it has been
>sent with HWND_BROADCAST parameter in SendMessage (...)
>or PostMessage(...) function.

Yes, you can. See below.

>The mainform class of receiving application is populated with
>begin_message macros (i used WndProc functions as well) but
>no result comes out of it.

That is because you are catching the message in the wrong window. You
need
to catch it from the TApplication window, not the TForm window. Call the
TApplication::HookMainWindow() method in order to catch messages that are
processed by the TApplication window, ie:

__fastcall TForm1::TForm1(TComponent *Owner)
: TForm(Owner)
{
Application->HookMainWindow(MyAppHook);
}

__fastcall TForm1::TForm1(TComponent *Owner)
: TForm(Owner)
{
Application->UnhookMainWindow(MyAppHook);
}

bool __fastcall TForm1::MyAppHook(TMessage &Message)
{
if( Message.Msg == WM_MY_MESSAGE )
{
// ...
return true;
}
else
return (Message.Msg == WM_INITDIALOG);
}


Gambit


 

{smallsort}

Re:HWND_BROADCAST handle

I'm sure "Remy Lebeau (TeamB)" ment to say destructor:
Quote
...
__fastcall TForm1::TForm1(TComponent *Owner)
: TForm(Owner)
{
Application->UnhookMainWindow(MyAppHook);
}
...
 

Re:HWND_BROADCAST handle

"Boba" < XXXX@XXXXX.COM >сообщи?сообщила ?новостях следующе?
Quote
I'm sure "Remy Lebeau (TeamB)" ment to say destructor:
Most likely.
 

Re:HWND_BROADCAST handle

what is:
сообщи?сообщила ?новостях следующе?
?