Monday, November 9, 2009

Line Draw Program Using MouseMove Event With CPen Class

void CTryView::OnMouseMove(UINT nFlags, CPoint point)
{
//RedrawWindow();
// TODO: Add your message handler code here and/or call default

CClientDC *pDC = new CClientDC(this);

CPen p1;
if(m_i<100)
{

p1.CreatePen(PS_SOLID,2,RGB(255,235,65));
pDC->SelectObject(&p1);

pDC->MoveTo(m_start);
pDC->LineTo(point);
m_start=point;
}
else if(m_i<200)
{

p1.CreatePen(PS_SOLID,2,RGB(100,230,82));
pDC->SelectObject(&p1);

pDC->MoveTo(m_start);
pDC->LineTo(point);
m_start=point;
}
else if(m_i<300)
{

p1.CreatePen(PS_SOLID,2,RGB(50,130,182));
pDC->SelectObject(&p1);

pDC->MoveTo(m_start);
pDC->LineTo(point);
m_start=point;
}
else if(m_i<400)
{

p1.CreatePen(PS_SOLID,2,RGB(255,0,0));
pDC->SelectObject(&p1);

pDC->MoveTo(m_start);
pDC->LineTo(point);
m_start=point;
}
else
{

p1.CreatePen(PS_SOLID,2,RGB(10,30,242));
pDC->SelectObject(&p1);

pDC->MoveTo(m_start);
pDC->LineTo(point);
m_start=point;

}

if(m_i==0)
{
m_start=point;
}
if(m_i==400)
{
m_i=0;
}
else
{
pDC->MoveTo(m_start);
pDC->LineTo(point);
m_start=point;
}

m_i++;

CView::OnMouseMove(nFlags, point);
}

No comments:

Post a Comment