Re: Is it possible to separate the event-handling part from the control?
- From: Joseph M. Newcomer <newcomer@xxxxxxxxxxxx>
- Date: Sun, 26 Nov 2006 01:52:22 -0500
The font would be set by SetFont, but that's a different issue than having the parent
respond to each event such as WM_CTLCOLORxxx. FOr example, often my parent will set the
desired background color by calling a method of the control subclass, but the actual
implementation of how that is handled is done inside the control (often by reflected
=WM_CTLCOLOR). The problem is that values are set by the parent independent of the
implementation details, while WM_CTLCOLORxxxx requires that you decode the control ID and
have some awareness of how the drawing is done. So if I replace a CStatic by a
CWnd-derived class which doesn't implement WM_CTLCOLORxxx, my interface remains constant,
but if I depend on WM_CTLCOLOR then I have to assume that the control is going to send it.
joe
On Fri, 24 Nov 2006 13:20:50 -0800, "David Ching" <dc@xxxxxxxxxxxxxxxxxxxxxx> wrote:
"Joseph M. Newcomer" <newcomer@xxxxxxxxxxxx> wrote in messageJoseph M. Newcomer [MVP]
news:54gem290jv0dfjcjv3page04q6j1jhb9rt@xxxxxxxxxx
In modern programming, you subclass the control and put all the knowledge
about the
color in the subclass, where it belongs. Otherwise, you have no
reusability. The idea
that the parent should be in control is not only not sound, it never made
any sense. It
was a kludge to avoid forcing the user to subclass the control, which was
the right
solution.
Note that the parent has to have knowledge of EVERY CONTROL in it, and
know what colors
are required for each control! How can this make sense? A modular
solution puts the
knowledge in exactly one place, the control, where it is all centralized.
I fought this problem for nearly five years before I figured out how to
avoid it. The
parent should have absolutely NO KNOWLEDGE of how a control is drawn!
This includes its
colors, fonts, styles, and all other parameters involved in drawing it.
Elementary
principles of modular decomposition should make this obvious.
I'm sorry, what you're saying makes no sense. Some behavior you want to
encapsulate in the control so you can easily re-use it, other behavior is a
parameter of the control that needs to change based on the needs of the
project embedding it. Do you really want to define:
class CCourierFontEdit : public CEdit
{
// this class is just like a CEdit excepts it prints text in the Courier
New font
};
Of course not. The proper way is for the parent to set a font property at
runtime.
-- David
email: newcomer@xxxxxxxxxxxx
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
.
- Follow-Ups:
- Re: Is it possible to separate the event-handling part from the control?
- From: David Ching
- Re: Is it possible to separate the event-handling part from the control?
- References:
- Re: Is it possible to separate the event-handling part from the control?
- From: Joseph M . Newcomer
- Re: Is it possible to separate the event-handling part from the control?
- From: David Ching
- Re: Is it possible to separate the event-handling part from the control?
- From: Joseph M . Newcomer
- Re: Is it possible to separate the event-handling part from the control?
- From: David Ching
- Re: Is it possible to separate the event-handling part from the control?
- Prev by Date: How to capture parent dialog title text into child,sub-sub...child dialogs?
- Next by Date: Re: Amazing !!!
- Previous by thread: Re: Is it possible to separate the event-handling part from the control?
- Next by thread: Re: Is it possible to separate the event-handling part from the control?
- Index(es):
Relevant Pages
|