實(shí)驗(yàn)八MFC鼠標(biāo)作圖編程實(shí)驗(yàn)_第1頁(yè)
實(shí)驗(yàn)八MFC鼠標(biāo)作圖編程實(shí)驗(yàn)_第2頁(yè)
實(shí)驗(yàn)八MFC鼠標(biāo)作圖編程實(shí)驗(yàn)_第3頁(yè)
實(shí)驗(yàn)八MFC鼠標(biāo)作圖編程實(shí)驗(yàn)_第4頁(yè)
實(shí)驗(yàn)八MFC鼠標(biāo)作圖編程實(shí)驗(yàn)_第5頁(yè)
已閱讀5頁(yè),還剩6頁(yè)未讀 繼續(xù)免費(fèi)閱讀

下載本文檔

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

文檔簡(jiǎn)介

實(shí)驗(yàn)八MFC鼠標(biāo)作圖編程實(shí)驗(yàn)電氣1002班 李震 學(xué)號(hào)10053212實(shí)驗(yàn)?zāi)康氖煜isualC++6.0開發(fā)環(huán)境;掌握應(yīng)用MFC類庫(kù)編寫鼠標(biāo)繪圖程序的方法;掌握MFC環(huán)境中繪圖函數(shù)的使用方法。實(shí)驗(yàn)內(nèi)容創(chuàng)建一個(gè)單文檔應(yīng)用程序,實(shí)現(xiàn)鼠標(biāo)的繪圖功能。要求:創(chuàng)建一個(gè)工具欄,有線段、矩形、橢圓三個(gè)按鈕;繪圖前,選擇工具欄上的按鈕,確定圖形的形狀。按下鼠標(biāo)左鍵,開始繪圖,結(jié)合鼠標(biāo)光標(biāo)的坐標(biāo)值,來(lái)確定圖形的形狀和大小,并隨著鼠標(biāo)的移動(dòng)在屏幕上實(shí)時(shí)繪制圖形,放開鼠標(biāo)左鍵,確定最后的圖形,繪制在屏幕上。程序清單//DemoView.cpp:implementationoftheCDemoViewclass#include"stdafx.h"#include"Demo.h"#include"DemoDoc.h"#include"DemoView.h"#ifdef_DEBUG#definenewDEBUG_NEW#undefTHIS_FILEstaticcharTHIS_FILE[]=__FILE__;#endif///////////////////////////////////////////////////////////////////////////////CDemoViewIMPLEMENT_DYNCREATE(CDemoView,CView)BEGIN_MESSAGE_MAP(CDemoView,CView) //{{AFX_MSG_MAP(CDemoView) ON_WM_LBUTTONDOWN() ON_WM_MOUSEMOVE() ON_WM_LBUTTONUP() ON_COMMAND(ID_FILEOP_OPEN,OnFileopOpen) ON_UPDATE_COMMAND_UI(ID_FILEOP_OPEN,OnUpdateFileopOpen) ON_COMMAND(ID_FILEOP_SAVE,OnFileopSave) ON_UPDATE_COMMAND_UI(ID_FILEOP_SAVE,OnUpdateFileopSave) //}}AFX_MSG_MAP //Standardprintingcommands ON_COMMAND_RANGE(ID_DRAW_LINE,ID_DRAW_ELLIPSE,OnDrawType) ON_UPDATE_COMMAND_UI_RANGE(ID_DRAW_LINE,ID_DRAW_ELLIPSE,OnDrawTypeUI) ON_COMMAND(ID_FILE_PRINT,CView::OnFilePrint) ON_COMMAND(ID_FILE_PRINT_DIRECT,CView::OnFilePrint) ON_COMMAND(ID_FILE_PRINT_PREVIEW,CView::OnFilePrintPreview)END_MESSAGE_MAP()///////////////////////////////////////////////////////////////////////////////CDemoViewconstruction/destructionCDemoView::CDemoView(){ //TODO:addconstructioncodehere m_nPicNum=0; m_nDrawType=0;}CDemoView::~CDemoView(){}BOOLCDemoView::PreCreateWindow(CREATESTRUCT&cs){ //TODO:ModifytheWindowclassorstylesherebymodifying //theCREATESTRUCTcs returnCView::PreCreateWindow(cs);}///////////////////////////////////////////////////////////////////////////////CDemoViewdrawingvoidCDemoView::OnDraw(CDC*pDC){ CDemoDoc*pDoc=GetDocument(); ASSERT_VALID(pDoc); //TODO:adddrawcodefornativedatahere CPenBluePen,*pOldPen; BluePen.CreatePen(PS_SOLID,3,RGB(0,0,255)); pOldPen=pDC->SelectObject(&BluePen); for(inti=0;i<m_nPicNum;i++) { switch(m_Pic[i].m_nDrawType) { case0: pDC->MoveTo(m_Pic[i].m_nX0,m_Pic[i].m_nY0); pDC->LineTo(m_Pic[i].m_nX1,m_Pic[i].m_nY1); break; case1: pDC->Rectangle(m_Pic[i].m_nX0,m_Pic[i].m_nY0, m_Pic[i].m_nX1,m_Pic[i].m_nY1); break; case2: pDC->Ellipse(m_Pic[i].m_nX0,m_Pic[i].m_nY0, m_Pic[i].m_nX1,m_Pic[i].m_nY1); break; } } pDC->SelectObject(pOldPen);}///////////////////////////////////////////////////////////////////////////////CDemoViewprintingBOOLCDemoView::OnPreparePrinting(CPrintInfo*pInfo){ //defaultpreparation returnDoPreparePrinting(pInfo);}voidCDemoView::OnBeginPrinting(CDC*/*pDC*/,CPrintInfo*/*pInfo*/){ //TODO:addextrainitializationbeforeprinting}voidCDemoView::OnEndPrinting(CDC*/*pDC*/,CPrintInfo*/*pInfo*/){ //TODO:addcleanupafterprinting}///////////////////////////////////////////////////////////////////////////////CDemoViewdiagnostics#ifdef_DEBUGvoidCDemoView::AssertValid()const{ CView::AssertValid();}voidCDemoView::Dump(CDumpContext&dc)const{ CView::Dump(dc);}CDemoDoc*CDemoView::GetDocument()//non-debugversionisinline{ ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CDemoDoc))); return(CDemoDoc*)m_pDocument;}#endif//_DEBUG///////////////////////////////////////////////////////////////////////////////CDemoViewmessagehandlersvoidCDemoView::OnLButtonDown(UINTnFlags,CPointpoint){ //TODO:Addyourmessagehandlercodehereand/orcalldefault m_nX0=m_nX1=point.x; m_nY0=m_nY1=point.y; CView::OnLButtonDown(nFlags,point);}voidCDemoView::OnMouseMove(UINTnFlags,CPointpoint){ //TODO:Addyourmessagehandlercodehereand/orcalldefault CClientDCdc(this); CPenWhitePen,RedPen,*pOldPen; WhitePen.CreatePen(PS_SOLID,1,RGB(255,255,255)); RedPen.CreatePen(PS_DASH,1,RGB(255,0,0)); if(nFlags&MK_LBUTTON) { switch(m_nDrawType) { case0: pOldPen=dc.SelectObject(&WhitePen); dc.MoveTo(m_nX0,m_nY0); dc.LineTo(m_nX1,m_nY1); m_nX1=point.x; m_nY1=point.y; dc.SelectObject(&RedPen); dc.MoveTo(m_nX0,m_nY0); dc.LineTo(m_nX1,m_nY1); dc.SelectObject(pOldPen); break; case1: pOldPen=dc.SelectObject(&WhitePen); dc.Rectangle(m_nX0,m_nY0,m_nX1,m_nY1); m_nX1=point.x; m_nY1=point.y; dc.SelectObject(&RedPen); dc.Rectangle(m_nX0,m_nY0,m_nX1,m_nY1); dc.SelectObject(pOldPen); break; case2: pOldPen=dc.SelectObject(&WhitePen); dc.Ellipse(m_nX0,m_nY0,m_nX1,m_nY1); m_nX1=point.x; m_nY1=point.y; dc.SelectObject(&RedPen); dc.Ellipse(m_nX0,m_nY0,m_nX1,m_nY1); dc.SelectObject(pOldPen); break; } } CView::OnMouseMove(nFlags,point);}voidCDemoView::OnLButtonUp(UINTnFlags,CPointpoint){ //TODO:Addyourmessagehandlercodehereand/orcalldefault CClientDCdc(this); CPenWhitePen,BluePen,*pOldPen; WhitePen.CreatePen(PS_SOLID,1,RGB(255,255,255)); BluePen.CreatePen(PS_SOLID,3,RGB(0,0,255)); switch(m_nDrawType) { case0: pOldPen=dc.SelectObject(&WhitePen); dc.MoveTo(m_nX0,m_nY0); dc.LineTo(m_nX1,m_nY1); m_nX1=point.x; m_nY1=point.y; dc.SelectObject(&BluePen); dc.MoveTo(m_nX0,m_nY0); dc.LineTo(m_nX1,m_nY1); dc.SelectObject(pOldPen); break; case1: pOldPen=dc.SelectObject(&WhitePen); dc.Rectangle(m_nX0,m_nY0,m_nX1,m_nY1); m_nX1=point.x; m_nY1=point.y; dc.SelectObject(&BluePen); dc.Rectangle(m_nX0,m_nY0,m_nX1,m_nY1); dc.SelectObject(pOldPen); break; case2: pOldPen=dc.SelectObject(&WhitePen); dc.Ellipse(m_nX0,m_nY0,m_nX1,m_nY1); m_nX1=point.x; m_nY1=point.y; dc.SelectObject(&BluePen); dc.Ellipse(m_nX0,m_nY0,m_nX1,m_nY1); dc.SelectObject(pOldPen); break; } m_Pic[m_nPicNum].m_nDrawType=m_nDrawType; m_Pic[m_nPicNum].m_nX0=m_nX0; m_Pic[m_nPicNum].m_nY0=m_nY0; m_Pic[m_nPicNum].m_nX1=m_nX1; m_Pic[m_nPicNum].m_nY1=m_nY1; m_nPicNum++; CView::OnLButtonUp(nFlags,point);}voidCDemoView::OnFileopOpen(){ //TODO:Addyourcommandhandlercodehere CFileDialogdlg(TRUE); if(dlg.DoModal()==IDOK) { CStringszPathName; szPathName=dlg.GetPathName(); CFilefile(szPathName,CFile::modeRead); file.Read(&m_nPicNum,sizeof(int)); for(inti=0;i<m_nPicNum;i++) { file.Read(&m_Pic[i],sizeof(CPic)); } file.Close(); Invalidate(); }}voidCDemoView::OnUpdateFileopOpen(CCmdUI*pCmdUI){ //TODO:AddyourcommandupdateUIhandlercodehere}voidCDemoView::OnFileopSave(){ //TODO:Addyourcommandhandlercodehere CFileDialogdlg(FALSE)

溫馨提示

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

最新文檔

評(píng)論

0/150

提交評(píng)論