.
调试程序: 运行结果: .
.
中点画线算法: 添加成员函数 1.展开Wangyanyan classes—>右击CWangyanyanView—>选择Add Member Funtion(添加成员函数)—>函数类型定义为void,函数描述为:MidpointLine—>点击确定
2.展开classes—>CWangyanyanview,在MidpointLine函数里添加形参int x0,int y0,int x1,int y1,int color,CClientDC & dc
3.双击CWangyanyanView,在public中添加代码: void CWangyanyanView::MidpointLine(int x0,int y0,int x1,int y1,int color,CClientDC & dc);最后加分号 4.展开CWangyanyanView—>双击OnDraw—>添加代码: .
.
MidpointLine(20,15,200,485,RGB(80,120,255), dc); 5.双击MidpointLine,在函数体编写如下代码: CPen newpen(PS_SOLID,1,color); dc.SelectObject(&newpen); int a,b,delta1,delta2,d,x,y; a=y0-y1; b=x1-x0; d=2*a+b; delta1=2*a; delta2=2*(a+b); x=x0; y=y0; dc.SetPixel(x,y,color); while(x