Re: Custom CRect Question
You shouldn't even need RectBase function.
CRect has an operator that converts a CRect class into a LPRECT or LPCRECT.
in other words
CCustomRect Rect;
GetWindowRect(&Rect);
should compile without a single message from the compiler.
Anyway, as far as inherting from a CRect or containing a CRect object goes,
it all depends on what you are doing, and what is CCustomRect used for.
What is CCustomRect used for?
If you are enhacing CRect then inherit from it. If you need an object that
happens to have a Rectangle as an attribute then contain is the way to go.
class CCustomRect
{
private:
CPoint m_maxPt;
COLORREF m_color;
TCHAR text[50];
CRect Rect;
public:
CCustomRect(const RECT *source, CPoint pt, COLORREF rgb);
CCustomRect(const RECT &source, CPoint pt, COLORREF rgb);
const RECT& RectBase() { return Rect; }
void Update(const RECT &r);
void Update(const RECT *r);
}
AliR.
"jp2code" <poojo.com/mail> wrote in message
news:OEaelZuyHHA.3564@TK2MSFTNGP04.phx.gbl...
I have a custom rectangle class that inherits from CRect:
class CCustomRect : public CRect
{
private:
CPoint m_maxPt;
COLORREF m_color;
TCHAR text[50];
public:
CCustomRect(RECT* source, CPoint pt, COLORREF rgb);
RECT* RectBase();
void Update(RECT* r);
}
Inheritance has worked well until I found myself needing to create the
RectBase function (above) to return the rectangle dimensions.
CRect does not seem to have any methods that can be called to return the
base class's RECT value.
I could take CRect::Size and construct a rectangle to return, but this
seems a bit much.
My other alternative seems to be to not inherit from CRect, but rather
include it as a member variable. I don't really like this idea, though.
Is there a simple way to write the code for RectBase? CRect has several
operators, including the "operator =" that copies the dimensions of a
rectangle to CRect. Could my custom class use this operator in some way,
or did I negate that ability whenever I inherited the CRect class?
Any thoughts? Suggestions?