Visual C++面向?qū)ο笈c可視化程序設(shè)計;旋轉(zhuǎn)的風(fēng)車課程設(shè)計報告_第1頁
Visual C++面向?qū)ο笈c可視化程序設(shè)計;旋轉(zhuǎn)的風(fēng)車課程設(shè)計報告_第2頁
Visual C++面向?qū)ο笈c可視化程序設(shè)計;旋轉(zhuǎn)的風(fēng)車課程設(shè)計報告_第3頁
Visual C++面向?qū)ο笈c可視化程序設(shè)計;旋轉(zhuǎn)的風(fēng)車課程設(shè)計報告_第4頁
Visual C++面向?qū)ο笈c可視化程序設(shè)計;旋轉(zhuǎn)的風(fēng)車課程設(shè)計報告_第5頁
已閱讀5頁,還剩4頁未讀 繼續(xù)免費閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)

文檔簡介

1、Visual C+面向?qū)ο?與可視化程序設(shè)計 課程設(shè)計題目名稱:旋轉(zhuǎn)的風(fēng)車班級:計算機(jī)08-5姓名:Adam Roy學(xué)號:0804_利用VC+設(shè)計旋轉(zhuǎn)的風(fēng)車一 要求與分析在窗口中畫一個旋轉(zhuǎn)的風(fēng)車,風(fēng)車中有三個葉片,顏色分別為紅、黃和藍(lán),葉片外側(cè)有一個外接圓。要求在程序中能夠控制葉片的運轉(zhuǎn)與停止,當(dāng)開始運轉(zhuǎn)時,速度由0逐漸變到最高速度;當(dāng)停止時,由最高速度逐漸變?yōu)?。本課題對軟硬件平臺要求不高,操作系統(tǒng)可選擇Windows2000/Window XP。在下控件來實現(xiàn)。二 MFC介紹 MFC (Microsoft Foundation Class ) 是用來編寫Windows 應(yīng)用程序的C + 類

2、集,其中封裝了大局部Windows API 函數(shù)和Windows 控件,使用MFC 類庫和Visual C + 提供的應(yīng)用程序開發(fā)工具,可使應(yīng)用程序開發(fā)變得簡單,提高代碼的可靠性和可重用性三 界面設(shè)計界面應(yīng)滿足以下要求:1, 界面首先要出現(xiàn)一個風(fēng)車。2, 風(fēng)車葉片要分紅黃藍(lán)三種顏色,外側(cè)有一個外接圓。3在程序中能夠控制葉片的運轉(zhuǎn)與停止,當(dāng)開始運轉(zhuǎn)時,速度由0逐漸變到最高速度;當(dāng)停止時,由最高速度逐漸變?yōu)?。4根據(jù)以上描述,程序運行時效果如下圖。運行結(jié)果: 四 系統(tǒng)實現(xiàn)源程序:/ Instance_3_1_.cpp : Defines the entry point for the a

3、pplication./*在窗口中畫一個旋轉(zhuǎn)的風(fēng)車,風(fēng)車中有三個葉片,顏色分別為紅黃和藍(lán),葉片外側(cè)有一個外接圓。*/#include <windows.h>#include <math.h>/ 回調(diào)函數(shù)聲明LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam);/ 初始化窗口類聲明BOOL InitWindowsClass(HINSTANCE hInstance, char *lpszClassName);/ 初始化窗口聲明BOOL InitWindows(HINST

4、ANCE hInstance, int nCmdShow, char *lpszClassName, char *lpTitle);WNDCLASS wndclass; / 定義一個窗口類HWND hwnd; / 定義一個窗口句柄const double Pi = 3.1415926;int nMaxNumber = 20; / 葉片循環(huán)一周中繪圖的次數(shù)int nNum = 0; / 記錄當(dāng)前的順序double time0=81;bool flag=0;int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR

5、lpCmdLine, int nCmdShow)MSG Msg; / 定義消息char lpszClassName = "風(fēng)車" / 窗口的類名char lpTitle = "根本繪圖-旋轉(zhuǎn)的風(fēng)車" / 窗口標(biāo)題名/ 初始化窗口類if (!InitWindowsClass(hInstance, lpszClassName)return FALSE;/ 初始化窗口if (!InitWindows(hInstance, nCmdShow, lpszClassName, lpTitle)return FALSE;/消息循環(huán)while(GetMessage(&a

6、mp;Msg, NULL, 0, 0)TranslateMessage(&Msg);DispatchMessage(&Msg);return Msg.wParam; / 程序終止時將信息返回系統(tǒng)/ 初始化窗口類定義BOOL InitWindowsClass(HINSTANCE hInstance, char *lpszClassName)/1、窗口類定義wndclass.style = 0; / 窗口類型為默認(rèn)類型wndclass.lpfnWndProc = WndProc; / 窗口處理函數(shù)為 WNDPROCwndclass.cbClsExtra = 0; / 窗口類無擴(kuò)展w

7、ndclass.cbWndExtra = 0; / 窗口實例無擴(kuò)展wndclass.hInstance = hInstance; / 當(dāng)前實例句柄wndclass.hIcon = LoadIcon(NULL, IDI_APPLICATION); / 窗口的最小化圖標(biāo)為默認(rèn)圖標(biāo)wndclass.hCursor = LoadCursor(NULL, IDC_ARROW); / 窗口采用箭頭光標(biāo)wndclass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH); / 窗口采用白色背景 wndclass.lpszMenuName = NULL; /

8、 窗口中無菜單wndclass.lpszClassName = lpszClassName; /類名為 lpClassName/2、注冊窗口類if (!RegisterClass(&wndclass) / 如果注冊失敗那么發(fā)出警告聲音MessageBeep(0);return FALSE;return TRUE;/ 初始化窗口聲明BOOL InitWindows(HINSTANCE hInstance, int nCmdShow, char *lpszClassName, char *lpTitle)/3、創(chuàng)立窗口hwnd = CreateWindow(lpszClassName, l

9、pTitle, WS_OVERLAPPEDWINDOW,CW_USEDEFAULT, 0, 600, 450, NULL, NULL, hInstance, NULL);/4、顯示窗口ShowWindow(hwnd, nCmdShow);UpdateWindow(hwnd);return TRUE;/ 回調(diào)函數(shù)定義LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)HDC hDC; / 定義設(shè)備環(huán)境句柄HPEN hPen; / 定義畫筆句柄HBRUSH hBrush; / 定義畫刷句柄PA

10、INTSTRUCT PtStr; / 定義包含繪制信息的結(jié)構(gòu)體變量POINT pCenterPoint; / 定義一個圓盡心點的坐標(biāo)int nRadious = 50;/ 定義圓的半徑double fAngle; / 葉片的直邊與水平軸的夾角switch(message)case WM_PAINT: / 處理繪圖消息hDC = BeginPaint(hwnd, &PtStr); / 得到設(shè)備句柄SetMapMode(hDC, MM_ANISOTROPIC); / 設(shè)置映像模式SetWindowExtEx(hDC, 400, 300, NULL); / 設(shè)置窗口區(qū)域邏輯單位SetView

11、portExtEx(hDC, 600, 450, NULL); / 設(shè)置視口區(qū)域物理單位SetViewportOrgEx(hDC, 300, 200, NULL); / 設(shè)置視口原點坐標(biāo)為300, 200/ 繪制外圓hPen = (HPEN)GetStockObject(BLACK_PEN);SelectObject(hDC, hPen);Ellipse(hDC, -100, -100, 100, 100);/ 繪制風(fēng)車的葉片/ 1、畫紅色葉片hBrush = CreateSolidBrush(RGB(255, 0, 0); SelectObject(hDC, hBrush);fAngle =

12、 2 * Pi / nMaxNumber * nNum;pCenterPoint.x = (int)(nRadious * 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)(pCenterPoin

13、t.y + nRadious * sin(fAngle), (int)(pCenterPoint.x + nRadious * cos(fAngle + Pi), (int)(pCenterPoint.y + nRadious * sin(fAngle + Pi);/ 2、畫天藍(lán)色葉片hBrush = CreateSolidBrush(RGB(255, 255, 0); SelectObject(hDC, hBrush);pCenterPoint.x = (int)(nRadious * cos(fAngle + 2 * Pi / 3);pCenterPoint.y = (int)(nRadi

14、ous * sin(fAngle + 2 * Pi / 3);Pie(hDC, pCenterPoint.x - nRadious, 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

15、* cos(fAngle + Pi + 2 * Pi / 3),(int)(pCenterPoint.y + nRadious * 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

16、, 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 / 3),(int)(

17、pCenterPoint.y + nRadious * sin(fAngle + Pi + 4 * Pi / 3);nNum+; / 當(dāng)前充數(shù)增加1if(time0<=80)if(flag&&time0>30)time0-;if(!flag&&time0<=80)time0+;InvalidateRect(hwnd, NULL, 1); / 重繪窗口區(qū)域DeleteObject(hPen);DeleteObject(hBrush);EndPaint(hwnd, &PtStr);break;Case WM_LBUTTONDOWN: /點擊鼠標(biāo)左鍵開始旋轉(zhuǎn)time0=80;flag=1;InvalidateRect(hwnd, NULL, 1);break;Case WM_RBUTTONDOWN: /點擊鼠標(biāo)右鍵停止旋轉(zhuǎn)flag=0;break;case WM_

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論