6、BOTTOM;elseif(y>WT)c=c
7、TOP;*code=c;
8、}intCCode_ClipView::C_S_Line(CDC*pDC,intx1,inty1,intx2,inty2){//CDC*pDC=GetDC();intcode1,code2,code,x,y;encode(x1,y1,&code1);//(x1,y1)处的编码encode(x2,y2,&code2);//(x2,y2)处的编码while(code1!=0
9、
10、code2!=0)//当code1不等于0或code2不等于0{if((code1&code2)!=0)return0;//当code1与code2不等于0,
11、在同侧;code=code1;if(code1==0)code=code2;if((LEFT&code)!=0)//求交点{x=WL;y=y1+(y2-y1)*(WL-x1)/(x2-x1);}elseif((RIGHT&code)!=0){x=WR;y=y1+(y2-y1)*(WR-x1)/(x2-x1);}elseif((BOTTOM&code)!=0){y=WB;x=x1+(x2-x1)*(WB-y1)/(y2-y1);}elseif((TOP&code)!=0){y=WT;x=x1+(x2-x1)*(WT-y1)/(y2
12、-y1);}if(code==code1){x1=x;y1=y;encode(x,y,&code1);}else{x2=x;y2=y;encode(x,y,&code2);}}//endwhile,表示code1,code2都为0,其中的线段为可视部分pDC->MoveTo(x1,y1);pDC->LineTo(x2,y2);}步骤6:编写OnDraw()程序voidCCode_ClipView::OnDraw(CDC*pDC){CCode_ClipDoc*pDoc=GetDocument();ASSERT_VALID(pDoc
13、);//TODO:adddrawcodefornativedatahere//定义三条直线的坐标intx11,y11,x21,y21,x12,y12,x22,y22,x13,y13,x23,y23;x11=50;y11=150;x21=450;y21=250;x12=150;y12=150;x22=350;y22=240;x13=50;y13=400;x23=500;y23=350;//定义画笔CPenPenRed(PS_SOLID,1,RGB(255,0,0));//定义红色笔CPenPenBlue(PS_SOLID,1,RG
14、B(0,0,255));//定义蓝色笔//先画出窗口,用蓝色pDC->SelectObject(&PenBlue);pDC->Rectangle(WL,WB,WR,WT);//先画出三条直线,用红线pDC->TextOut(x11,y11,"line1:");p