资源描述:
《Visual-C++课后习题参考答案.docx》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、4-5参考答案:#include#include#include#include#definePi3.1415926longWINAPIWndProc(HWNDhWnd,UINTiMessage,UINTwParam,LONGlParam);//消息处理函数声明.BOOLInitWindowsClass(HINSTANCEhInstance);//初始化窗口类声明BOOLInitWindows(HINSTANCEhInstance,intnCmdS
2、how);//初始化窗口声明.HWNDhWndMain;intWINAPIWinMain(HINSTANCEhInstance,HINSTANCEhPrevInstance,LPSTRlpCmdLine,intnCmdShow)//主函数{MSGMessage;if(!InitWindowsClass(hInstance))//初始化窗口类.returnFALSE;if(!InitWindows(hInstance,nCmdShow))//初始化窗口.returnFALSE;while(GetMessage(&Mes
3、sage,0,0,0)){TranslateMessage(&Message);//消息循环.DispatchMessage(&Message);}returnMessage.wParam;}longWINAPIWndProc(HWNDhWnd,UINTiMessage,UINTwParam,LONGlParam)//消息处理函数.{HDChDC;//定义设备环境句柄.HBRUSHhBrush;//定义画刷句柄HPENhPen;//定义画笔句柄PAINTSTRUCTPtStr;//定义包含绘图信息的结构体变量doubled
4、fRadious0=100.0,dfRadious1;//定义外部和内部正五边形外接圆半径POINTlpOuterPoints[5],lpInnerPoints[5];//定义外,内正五边形点结构数组.POINTlpTriangle[3];//定义三角形点结构数组..dfRadious1=dfRadious0*sin(0.1*Pi)/sin(126.0/180*Pi);//根据外圆半径计算内园半径.//计算内外正五边形的点坐标.for(inti=0;i<5;i++){lpOuterPoints[i].x=(long)(dfRad
5、ious0*cos(i*72.0/180*Pi));lpOuterPoints[i].y=(long)(dfRadious0*sin(i*72.0/180*Pi));lpInnerPoints[i].x=(long)(dfRadious1*cos(i*72.0/180*Pi+36.0/180*Pi));lpInnerPoints[i].y=(long)(dfRadious1*sin(i*72.0/180*Pi+36.0/180*Pi));}switch(iMessage){caseWM_PAINT://处理绘图消息.hDC=Beg
6、inPaint(hWnd,&PtStr);//得到设备环境句柄SetMapMode(hDC,MM_ANISOTROPIC);//设置映射模式SetWindowOrgEx(hDC,-100,-100,NULL);//设置坐标原点..hPen=CreatePen(PS_SOLID,1,RGB(255,0,0));SelectObject(hDC,hPen);//创新红色画笔.//将画笔选入.Polygon(hDC,lpOuterPoints,5);//画正五边形.//填充正五边形的不同区域.for(i=0;i<5;i++){
7、lpTriangle[0]=lpOuterPoints[i%5];//生成图形中的三角形区域的坐标.lpTriangle[1]=lpInnerPoints[i%5];lpTriangle[2]=lpOuterPoints[(i+1)%5];//创新新画刷.hBrush=CreateSolidBrush(RGB(i*10,i*20,i*30));SelectObject(hDC,hBrush);//选入新画刷.Polygon(hDC,lpTriangle,3);//画三角形区域.lpTriangle[2]=lpInnerPoints
8、[(i+4)%5];//生成图形中的三角形区域的坐标.hBrush=CreateSolidBrush(RGB(i*40,i*30,i*20));//创新画刷.SelectObject(hDC,hBrush);Polygon(hDC,lpTriang