|
-
October 29th, 2004, 12:57 AM
#1
OnMouseMove in CView derived class
i have written a gdi application to draw some graphics. i have mapped the OnMouseMove() message handler to draw the selected shape as the mouse is dragged. the problem in this code execution is it creates multiple rectangles, after selecting the rectangle, even with the LBM clicked. How to avoid this problem?
the code is
void CJPG1View::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
// CREATE THE DEVICE CONTEXT .
m_cPoint = point;
CClientDC dc(this);
//select the pen of green color
CPen myPen(PS_SOLID,1,RGB(102,222,102));
// select a brush
CBrush myBrush(RGB(0,0,0));
// select a cursor similar to that of mspaint.
HCURSOR hCursor;
hCursor = AfxGetApp()->LoadStandardCursor(IDC_CROSS);
m_bCursor = TRUE;
SetCursor(hCursor);
dc.SetROP2(R2_NOTXORPEN);
dc.SelectObject(&myPen);
SetCapture();
if(nFlags == MK_LBUTTON )//|| (this->m_LBtnDown && m_MousePoint != point) )
{
switch(m_nMenuOption)
{
case DRAW_LINE:
dc.MoveTo(m_MousePoint.x,m_MousePoint.y);
dc.LineTo(point.x,point.y);
break;
case DRAW_RECT:
dc.Rectangle(m_MousePoint.x, point.x, m_MousePoint.y, point.y);
break;
case DRAW_CIRCLE:
dc.Ellipse(m_MousePoint.x, point.x, m_MousePoint.y, point.y);
break;
}
}
ReleaseCapture();
m_MousePoint = point;
CView::OnMouseMove(nFlags, point);
}
Last edited by uma_rohini; October 29th, 2004 at 01:23 AM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|