A SERVICE OF

logo

void TMyWindow::SetPenSize(int newSize)
{
delete Pen;
PenSize = newSize;
Pen = new TPen(TColor(0,0,0), PenSize);
}
Because P n is a pointer to a TP n object, and not an actual TP n object, ite e e
Cleaning up after
isn’t automatically destroyed when the TMyWindow object is destroyed.
P ne
Y u need to explicitly destroy P n in the TMyWindow destructor too e
properly clean up. The only thing required is to call delete on P n.e
TMyWindow should now look something like this:
class TMyWindow : public TWindow
{
public:
TMyWindow(TWindow *parent = 0);
~TMyWindow() {delete DragDC; delete Pen;}
void SetPenSize(int newSize);
protected:
TDC *DragDC;
int PenSize;
TPen *Pen;
// Override member function of TWindow
BOOL CanClose();
// Message response functions
void EvLButtonDown(UINT, TPoint&);
void EvRButtonDown(UINT, TPoint&);
void EvMouseMove(UINT, TPoint&);
void EvLButtonUp(UINT, TPoint&);
DECLARE_RESPONSE_TABLE(TMyWindow);
};
Here’ a guide to where you can find more information on the topicss
Where to find
introduced in this step:
more information
Device contexts and the TDC classes are discussed in Chapter 13.
The TP n class is discussed in Chapter 13.e
The TInputDialog class and dialogs in general are discussed in Chapter 8.
44
OWL P ogrammer’ Guider s