資源描述:
《實(shí)驗(yàn)四mfc圖形繪制編程實(shí)驗(yàn)》由會(huì)員上傳分享,免費(fèi)在線閱讀,更多相關(guān)內(nèi)容在學(xué)術(shù)論文-天天文庫(kù)。
1、實(shí)驗(yàn)四MFC圖形繪制編程實(shí)驗(yàn)一、實(shí)驗(yàn)?zāi)康?1)熟悉VisualC++6.0開(kāi)發(fā)環(huán)境;(2)掌握MFC消息映射的操作少驟;(2)掌握MFC圖形輸出的方法;(3)理解設(shè)備環(huán)境、畫筆、畫刷的概念,掌掘常用的繪圖函數(shù)。二、實(shí)驗(yàn)內(nèi)容請(qǐng)編寫程序,要求如卜:(1)定義一支黃色M筆,繪制一條線段;(1)定義一支紫色畫筆,繪制一條多段線;(3)定義一支紅色畫筆,繪制一個(gè)正方形,并用適當(dāng)?shù)漠嬎⑻畛湄栊蝺?nèi)部;(4)定義一支綠色畫筆,繪制一個(gè)圓,并用適當(dāng)?shù)漠嬎⑻畛鋱D形內(nèi)部;(5)定義-支藍(lán)色岡筆,繪制一個(gè)正六邊形,丼川適當(dāng)?shù)膩I刷填充圖形內(nèi)部,三、實(shí)驗(yàn)報(bào)告
2、1.列出圖形繪制程序代碼清單:(1)在頭文件Demo.h中:#include"afxwin.h"classCDemoWnd:publicCFrameWnd{public:CDcmoWnd();?CDemoWnd();public:LRESULTOnPaint(WPARAMwParam,LPARAMIParam);DECLARE_MESSAGE_MAP()public:intm_nX0;intm_nY0;intm_nX1;intm_nY1;};classCDemoApp:publicCWinApp{public:BOOLInitln
3、stance();};CDemoAppThisApp;(2)在源文件Demo.cpp屮:includeutpdl.hMCDemoWnd::CDemoWnd()m_nX0=0;m_nYO=0;m_nXl=0;m_nY1=0;}CDemoWnd::?CDemoWnd(){}BEGIN_MESSAGE一MAP(CDemoWnd,CFrameWnd)ON_MESSAGE(WM_PAINT,OnPaint)END_MESSAGE_MAP()LRESULTCDemoWnd::OnPaint(WFARAMwParam,LPARAMIParam)
4、{CPaintDCdc(this);CPenPenI,*p01dPen1;Pen1.CreatePen(PS_SOLID,l0,RGB(255,255,0));pOldPen1=dc.SelectObject(&Pen1);dc.SclcctObjcct(&Pcn1);dc.MoveTo(10,10);dc.LineTo(lOOJOO);CPenPen2,*pOldPen2;Pen2.CreatePen(PS_SOLID,4,RGB(255,0,255));pOldPen2=dc.SelectObject(&Pen2);dc.Se
5、lectObject(&Pen2);POINTptl[]={{100,10},{10,180},{200,150}};dc.Polyline(ptl,3);CPenPen3,*pOldPen3;dc.SelectStockObject(BLACK_BRUSH);Pen3.CreatePen(PS_SOLID,4,RGB(255,0,0));pOldPen3=dc.SelectObject(&Pen3);dc.SclcctObjcct(&Pcn3);dc.Rectangle(300,50,400,150);CPenPen4,*pOl
6、dPen4;dc.SelectStockObject(GRAY_BRUSH);Pcn4.CrcatcPcn(PS_SOLID,4,RGB(0,255,0));pOldPen4=dc.SelectObject(&Pen4);dc.SelectObject(&Pen4);dc.Ellipse(500,200,700,400);CPenPcn5,*pOldPcn5;Pen5.CreatePen(PS_SOLID,4,RGB(0,0,255));pOldPen5=dc.SelectObject(&Pen5);dc.SclcctStockO
7、bjcct(DKGRAY_BRUSH);dc.SelectObject(&Fen5);POINTpt2U={{250,250},{400,250},{475,379},{400,509},{250,509},{175,379}};dc.Polygon(pt2,6);return0;}BOOLCDemoApp::lnitlnstance(){CDemoWnd*pMainWnd=newCDemoWnd();pMainWnd->Create(NULL,uDemoMini-MFC");pMainWnd->ShowWindow(m_nCmd
8、Show);pMainWnd->UpdateWindow();m_pMainWnd=pMainWnd;returnTRUE;}2、程序運(yùn)行結(jié)果:3、總結(jié)在MFC程序中繪制圖形的基本操作步驟:(1)獲取圖形設(shè)備接U。圖形設(shè)備接口(GDI)ft責(zé)系統(tǒng)與