The OnLButtonDown
member function is called via the message map when Windows sends a WM_LBUTTONDOWN message to the view object. The function begins a new stroke, adding the current location of the mouse to the stroke and adding the stroke to the document’s stroke list. Then OnLButtonDown
captures the mouse — until the left mouse button is released to end the stroke.
To add code for OnLButtonDown
CScribbleView
’s member function OnLButtonDown
in ScribbleView.cpp.// Pressing the mouse button in the view window
// starts a new stroke.
m_pStrokeCur = GetDocument( )->NewStroke( );
// Add first point to the new stroke
m_pStrokeCur->m_pointArray.Add(point);
SetCapture( ); // Capture the mouse until button up
m_ptPrev = point; // Serves as the MoveTo( ) anchor point
// for the LineTo() the next point, as
// the user drags the mouse
return;
Note This version of OnLButtonDown
doesn’t include a call to the base class version. It completely replaces the inherited behavior.