Re: MFC and c++ problems

Tech-Archive recommends: Fix windows errors by optimizing your registry



Hi Doug,

I would think the parent would define which messages the child could send
and then the child would use those messages. Isn't this how most of the
controls on a dialog work?

Tom

"Doug Harrison [MVP]" <dsh@xxxxxxxx> wrote in message
news:9u0au197q2vbg2rk33ot0o7g16ko0pg7ad@xxxxxxxxxx

The thing about SendMessage is that it's not type-safe, and the target
window has to agree to interpret the number identified by WM_WHATEVER the
same way as the sender. Now, if it isn't a standard message, and the
target
window didn't define the message itself, and you didn't design the classes
to work together, then you have to use RegisterWindowMessage to negotiate
a
message you can both agree on. Using "interfaces" as suggested elsewhere
in
this thread solves these problems. A more general approach is exemplified
by the .NET event facility, in which objects interested in an event
register themselves with the object that generates the event; this is an
implementation of the Observer pattern. In C++, the primary (legitimate)
reason to use Windows messages instead of an OOP approach is to enable use
of the window from other languages. A secondary (not so legitimate) reason
is that it's quicker (and dirtier), especially when you're designing the
window classes together and can set up a common header file that defines
the message they'll both use.

--
Doug Harrison
Visual C++ MVP


.


Quantcast