I've modified your code in OnMouseMove to support SDI applications. It
seems to be working fine. Please reply otherwise.
"Charles Tam" <CharlesTam@discussions.microsoft.com> wrote in message
news:8CA07CA7-F2AE-432F-9D81-15C5FC42C04E@microsoft.com...
In MFC 6, how do I draw a rectangle via a mouse drag?
Is there any example code I could look at?
Here's a minimal example:
void CSDIView::OnLButtonDown(UINT nFlags, CPoint point)
{
m_ptStart = point;
m_ptEnd = point;
SetCapture();
}
void CSDIView::OnMouseMove(UINT nFlags, CPoint point)
{
if (GetCapture() == this)
{ m_ptEnd = point;
Invalidate();
}
}
void CSDIView::OnLButtonUp(UINT nFlags, CPoint point)
{
if (GetCapture() == this)
{ ReleaseCapture();
m_ptEnd = point;
Invalidate();
}
}
void CSDIView::OnDraw(CDC* pDC)
{
CRect r(m_ptStart, m_ptEnd);
pDC->Rectangle(&r);
}
--
Scott McPhillips [VC++ MVP]