Visual C++面向对象与可视化程序设计;旋转的风车课程设计报告_第1页
Visual C++面向对象与可视化程序设计;旋转的风车课程设计报告_第2页
Visual C++面向对象与可视化程序设计;旋转的风车课程设计报告_第3页
Visual C++面向对象与可视化程序设计;旋转的风车课程设计报告_第4页
Visual C++面向对象与可视化程序设计;旋转的风车课程设计报告_第5页
已阅读5页,还剩4页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、visual c+面向对象 与可视化程序设计 课程设计题目名称:旋转的风车班级:计算机08-5姓名:adam roy学号:0804_利用vc+设计旋转的风车一 要求与分析在窗口中画一个旋转的风车,风车中有三个叶片,颜色分别为红、黄和蓝,叶片外侧有一个外接圆。要求在程序中能够控制叶片的运转与停止,当开始运转时,速度由0逐渐变到最高速度;当停止时,由最高速度逐渐变为0。本课题对软硬件平台要求不高,操作系统可选择windows2000/window xp。在visual c+ 6.0下控件来实现。二 mfc介绍 mfc (microsoft foundation class ) 是用来编写windo

2、ws 应用程序的c + 类集,其中封装了大部分windows api 函数和windows 控件,使用mfc 类库和visual c + 提供的应用程序开发工具,可使应用程序开发变得简单,提高代码的可靠性和可重用性三 界面设计界面应满足以下要求:1, 界面首先要出现一个风车。2, 风车叶片要分红黄蓝三种颜色,外侧有一个外接圆。3在程序中能够控制叶片的运转与停止,当开始运转时,速度由0逐渐变到最高速度;当停止时,由最高速度逐渐变为0。4根据以上描述,程序运行时效果如图所示。运行结果:四 系统实现源程序:/ instance_3_1_.cpp : defines the entry point f

3、or the application./*在窗口中画一个旋转的风车,风车中有三个叶片,颜色分别为红黄和蓝,叶片外侧有一个外接圆。*/#include #include / 回调函数声明lresult callback wndproc(hwnd hwnd, uint message, wparam wparam, lparam lparam);/ 初始化窗口类声明bool initwindowsclass(hinstance hinstance, char *lpszclassname);/ 初始化窗口声明bool initwindows(hinstance hinstance, int ncm

4、dshow, char *lpszclassname, char *lptitle);wndclass wndclass; / 定义一个窗口类hwnd hwnd; / 定义一个窗口句柄const double pi = 3.1415926;int nmaxnumber = 20; / 叶片循环一周中绘图的次数int nnum = 0; / 记录当前的顺序double time0=81;bool flag=0;int winapi winmain(hinstance hinstance, hinstance hprevinstance, lpstr lpcmdline, int ncmdshow

5、)msg msg; / 定义消息char lpszclassname = 风车; / 窗口的类名char lptitle = 基本绘图-旋转的风车; / 窗口标题名/ 初始化窗口类if (!initwindowsclass(hinstance, lpszclassname)return false;/ 初始化窗口if (!initwindows(hinstance, ncmdshow, lpszclassname, lptitle)return false;/消息循环while(getmessage(&msg, null, 0, 0)translatemessage(&msg);dispatc

6、hmessage(&msg);return msg.wparam; / 程序终止时将信息返回系统/ 初始化窗口类定义bool initwindowsclass(hinstance hinstance, char *lpszclassname)/1、窗口类定义wndclass.style = 0; / 窗口类型为默认类型wndclass.lpfnwndproc = wndproc; / 窗口处理函数为 wndprocwndclass.cbclsextra = 0; / 窗口类无扩展wndclass.cbwndextra = 0; / 窗口实例无扩展wndclass.hinstance = hin

7、stance; / 当前实例句柄wndclass.hicon = loadicon(null, idi_application); / 窗口的最小化图标为默认图标wndclass.hcursor = loadcursor(null, idc_arrow); / 窗口采用箭头光标wndclass.hbrbackground = (hbrush)getstockobject(white_brush); / 窗口采用白色背景 wndclass.lpszmenuname = null; / 窗口中无菜单wndclass.lpszclassname = lpszclassname; /类名为 lpcla

8、ssname/2、注册窗口类if (!registerclass(&wndclass) / 如果注册失败则发出警告声音messagebeep(0);return false;return true;/ 初始化窗口声明bool initwindows(hinstance hinstance, int ncmdshow, char *lpszclassname, char *lptitle)/3、创建窗口hwnd = createwindow(lpszclassname, lptitle, ws_overlappedwindow,cw_usedefault, 0, 600, 450, null,

9、null, hinstance, null);/4、显示窗口showwindow(hwnd, ncmdshow);updatewindow(hwnd);return true;/ 回调函数定义lresult callback wndproc(hwnd hwnd, uint message, wparam wparam, lparam lparam)hdc hdc; / 定义设备环境句柄hpen hpen; / 定义画笔句柄hbrush hbrush; / 定义画刷句柄paintstruct ptstr; / 定义包含绘制信息的结构体变量point pcenterpoint; / 定义一个圆尽心

10、点的坐标int nradious = 50;/ 定义圆的半径double fangle; / 叶片的直边与水平轴的夹角switch(message)case wm_paint: / 处理绘图消息hdc = beginpaint(hwnd, &ptstr); / 得到设备句柄setmapmode(hdc, mm_anisotropic); / 设置映像模式setwindowextex(hdc, 400, 300, null); / 设置窗口区域(逻辑单位)setviewportextex(hdc, 600, 450, null); / 设置视口区域(物理单位)setviewportorgex(h

11、dc, 300, 200, null); / 设置视口原点坐标为(300, 200)/ 绘制外圆hpen = (hpen)getstockobject(black_pen);selectobject(hdc, hpen);ellipse(hdc, -100, -100, 100, 100);/ 绘制风车的叶片/ 1、画红色叶片hbrush = createsolidbrush(rgb(255, 0, 0); selectobject(hdc, hbrush);fangle = 2 * pi / nmaxnumber * nnum;pcenterpoint.x = (int)(nradious

12、* cos(fangle);pcenterpoint.y = (int)(nradious * sin(fangle);pie(hdc, pcenterpoint.x - nradious, pcenterpoint.y - nradious, pcenterpoint.x + nradious, pcenterpoint.y + nradious, (int)(pcenterpoint.x + nradious * cos(fangle),(int)(pcenterpoint.y + nradious * sin(fangle), (int)(pcenterpoint.x + nradiou

13、s * cos(fangle + pi), (int)(pcenterpoint.y + nradious * sin(fangle + pi);/ 2、画天蓝色叶片hbrush = createsolidbrush(rgb(255, 255, 0); selectobject(hdc, hbrush);pcenterpoint.x = (int)(nradious * cos(fangle + 2 * pi / 3);pcenterpoint.y = (int)(nradious * sin(fangle + 2 * pi / 3);pie(hdc, pcenterpoint.x - nra

14、dious, pcenterpoint.y - nradious, pcenterpoint.x + nradious, pcenterpoint.y + nradious, (int)(pcenterpoint.x + nradious * cos(fangle + 2 * pi / 3), (int)(pcenterpoint.y + nradious * sin(fangle + 2 * pi / 3), (int)(pcenterpoint.x + nradious * cos(fangle + pi + 2 * pi / 3),(int)(pcenterpoint.y + nradi

15、ous * sin(fangle + pi + 2 * pi / 3);/ 2、画黄色叶片hbrush = createsolidbrush(rgb(0, 255, 255); selectobject(hdc, hbrush);pcenterpoint.x = (int)(nradious * cos(fangle + 4 * pi / 3);pcenterpoint.y = (int)(nradious * sin(fangle + 4 * pi / 3);pie(hdc, pcenterpoint.x - nradious, pcenterpoint.y - nradious, pcenterpoint.x + nradious, pcenterpoint.y + nradious, (int)(pcenterpoint.x + nradious * cos(fangle + 4 * pi / 3), (int)(pcenterpoint.y + nradious * sin(fangle + 4 * pi / 3), (int)(pcenterpoint.x + nradious * cos(fangle + pi + 4 * pi /

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论