Monday, November 9, 2009

Draw a line in every movement of mouse with different color

void CSdi1View::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
count+=1;

start.x=point.x;
start.y=point.y;
if(count%5==0)
{
i=0;
j=255;
k=0;
newb.DeleteObject();
newb.CreatePen(PS_SOLID,1,RGB(i,j,k));
}
else if(count%3==0)
{
i=255;
j=0;
k=0;
newb.DeleteObject();
newb.CreatePen(PS_SOLID,1,RGB(i,j,k));
}
else if(count%2==0)
{
i=0;
j=0;
k=255;
newb.DeleteObject();
newb.CreatePen(PS_SOLID,1,RGB(i,j,k));
}
CView::OnLButtonDown(nFlags, point);
}





void CSdi1View::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
end.x=point.x;
end.y=point.y;

CClientDC * pcd=new CClientDC(this);
pcd->MoveTo(start.x,start.y);


pcd->SelectObject(&newb);

pcd->LineTo(end.x,end.y);


CView::OnMouseMove(nFlags, point);
}

No comments:

Post a Comment