A SERVICE OF

logo

DragDC = 0;
}
}
When the mouse is moved, the EvMouseMove function is called. This
function checks whether the left mouse button is pressed by checking
DragDC. If DragDC is 0, either the mouse button has not been pressed at
all or it has been pressed and released. Either way the user is not,
drawing, and the function returns. If DragDC is valid, meaning that the
left mouse button is currently pressed down, the function draws a line
from the current point to the new point using the TWindow::LineTo
function.
void TMyWindow::EvMouseMove(UINT, TPoint& point)
{
if (DragDC)
DragDC->LineTo(point);
}
Y u must make sure that DragDC is set to 0 when you construct theo
Initializing DragDC
TMyWindow object:
TMyWindow::TMyWindow(TWindow *parent)
{
Init(parent, 0, 0);
DragDC = 0;
}
Because DragDC is a pointer to a TClientDC object, and not an actual
Cleaning up after
TClientDC object, it isn’t automatically destroyed when the TMyWindow
DragDC
object is destroyed. Y u need to add a destructor to TMyWindow too
properly clean up. The only thing required is to call delete on DragDC.
TMyWindow should now look something like this:
class TMyWindow : public TWindow
{
public:
TMyWindow(TWindow *parent = 0);
~TMyWindow() {delete DragDC;}
protected:
TDC *DragDC;
// Override member function of TWindow
BOOL CanClose();
// Message response functions
void EvLButtonDown(UINT, TPoint&);
Chapter 2, Learning ObjectWindows
39