怎样使用MFC单文档程序编写一个鼠标画线程序

来源:互联网 发布:网络语言吃草 编辑:程序博客网 时间:2024/06/07 07:27
在visual C++6.0里面 文件->新建->工程里面的MFC Appwizard [EXE]              除了第二步选单文档,基本上都是默认的。建一个文件进行一下操作   我建的文件名为ZuoBiao在CZuoBiaoView.h里面添加变量:int m;CPoint p1,p2;在构造函数里面初使化m。CZuoBiaoView::CZuoBiaoView(){// TODO: add construction code herem=0;}在资源文件Menu中的IDR_MAINFRAME中添加消息句柄OnLButtonDown,OnLButtonUp,OnMouseMove.再回到ZuoBiaoView.cpp中编译一下程序void CZuoBiaoView::OnLButtonDown(UINT nFlags, CPoint point) {// TODO: Add your message handler code here and/or call defaultCClientDC dc(this);m=1;p1=point;CView::OnLButtonDown(nFlags, point);}void CZuoBiaoView::OnLButtonUp(UINT nFlags, CPoint point) {// TODO: Add your message handler code here and/or call defaultp2=point;CClientDC dc(this);OnPrepareDC(&dc);dc.MoveTo(p1);dc.LineTo(p2);m=0;CView::OnLButtonUp(nFlags, point);}void CZuoBiaoView::OnMouseMove(UINT nFlags, CPoint point) {// TODO: Add your message handler code here and/or call defaultstatic int n=0;switch(++n){case 1:   p2=point;   break;case 2:   p1=p2;   p2=point;   n=0;   break;}CClientDC dc(this);OnPrepareDC(&dc);if(m==1){dc.MoveTo(p1);dc.LineTo(p2);}CView::OnMouseMove(nFlags, point);}
原创粉丝点击