怎样用MFC编程实现画图板?
展开全部
建立一个单文档的MFC 添加三个消息响应,WM_LButtonDown WM_LButtonUp WM_MouseMove
在消息响应函数里面添加代码如下即可:
void CDrawView::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
Origin_Point=point;
flag=1;
CView::OnLButtonDown(nFlags, point);
}
void CDrawView::OnLButtonUp(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
flag=0;
CView::OnLButtonUp(nFlags, point);
}
void CDrawView::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
CClientDC dc(this);
CPen pen(PS_SOLID,2,RGB(0,255,0));
CPen *oldpen=dc.SelectObject(&pen);
if(flag==1)
{
dc.MoveTo(Origin_Point);
dc.LineTo(point);
Origin_Point=point;
}
dc.SelectObject(oldpen);
CView::OnMouseMove(nFlags, point);
}
在消息响应函数里面添加代码如下即可:
void CDrawView::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
Origin_Point=point;
flag=1;
CView::OnLButtonDown(nFlags, point);
}
void CDrawView::OnLButtonUp(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
flag=0;
CView::OnLButtonUp(nFlags, point);
}
void CDrawView::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
CClientDC dc(this);
CPen pen(PS_SOLID,2,RGB(0,255,0));
CPen *oldpen=dc.SelectObject(&pen);
if(flag==1)
{
dc.MoveTo(Origin_Point);
dc.LineTo(point);
Origin_Point=point;
}
dc.SelectObject(oldpen);
CView::OnMouseMove(nFlags, point);
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询