Re: Is it possible to separate the event-handling part from the control?

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



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 message
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
Joseph M. Newcomer [MVP]
email: newcomer@xxxxxxxxxxxx
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
.



Relevant Pages

  • Re: CView::OnCtlColor to change font on a single CStatic
    ... have 1 CStatic control in the corner which displays the current scaling ... I would like to reduce the font size on it. ... This was all inherrited code and a very large class at that. ... necessary in a CStatic subclass instead. ...
    (microsoft.public.vc.mfc)
  • Re: Can I Merge Card Symbols (Clubs, Diamonds, etc) with a Font that doesnt have them
    ... that would mean the parent of the control did the drawing. ... Arial font. ... Subclass the CListCtrl ... In a CListCtrl I draw the lines of text but the card symbols show up as ...
    (microsoft.public.vc.mfc)
  • Re: Catching Spin Control Events From CEdit
    ... I'm just allowing several formats of numbers and so I needed code to ... I didn't need to subclass the UDC for my purposes, ... > subclass the parent in order to intercept the ... I have several instances of this control on several dialog boxes, ...
    (microsoft.public.vc.mfc)
  • Re: MFC and c++ problems
    ... You say that a control must make no assumptions about its parent. ... messages to its parent will compile and run ... ... One could write an interface class that supported the methodneeded by ...
    (microsoft.public.vc.mfc)
  • Re: BUG is in Combobox.Font ?
    ... type of control is the parent in this situation? ... When setting the Font to a ... When I change font of combobox also size of combobox ... >> I am assuming that the parent is a Form. ...
    (microsoft.public.dotnet.framework.windowsforms)