VC++程序设计大作业——熊武(共9页).doc
精选优质文档-倾情为你奉上武 汉 轻 工 大 学 VC+程序设计大作业 院系 电气与电子工程学院 班级 学号 1204 姓名 日期 2013.11.22 1题目 编写MFC下的单文档程序,通过鼠标点击选择两个点,作为矩形左上角、右下角,然后绘制矩形。(对应12题)2思路 首先点击鼠标,选中左上角,然后拖动鼠标,在右下角拿起,这样矩形就就可以实现了。3程序实现过程首先建立MFC单文档程序 然后建立类向导添加鼠标事件添加CPoint成员变量m_OrigPoint4关键代码/ RectangleView.cpp : implementation of the CRectangleView class/#include "stdafx.h"#include "Rectangle.h"#include "RectangleDoc.h"#include "RectangleView.h"#ifdef _DEBUG#define new DEBUG_NEW#undef THIS_FILEstatic char THIS_FILE = _FILE_;#endif/ CRectangleViewIMPLEMENT_DYNCREATE(CRectangleView, CView)BEGIN_MESSAGE_MAP(CRectangleView, CView)/AFX_MSG_MAP(CRectangleView)ON_WM_LBUTTONDOWN()ON_WM_LBUTTONUP()/AFX_MSG_MAP/ Standard printing commandsON_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()/ CRectangleView construction/destructionCRectangleView:CRectangleView()/ TODO: add construction code hereCRectangleView:CRectangleView()BOOL CRectangleView:PreCreateWindow(CREATESTRUCT& cs)/ TODO: Modify the Window class or styles here by modifying/ the CREATESTRUCT csreturn CView:PreCreateWindow(cs);/ CRectangleView drawingvoid CRectangleView:OnDraw(CDC* pDC)CRectangleDoc* pDoc = GetDocument();ASSERT_VALID(pDoc);/ TODO: add draw code for native data here/ CRectangleView printingBOOL CRectangleView:OnPreparePrinting(CPrintInfo* pInfo)/ default preparationreturn DoPreparePrinting(pInfo);void CRectangleView:OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)/ TODO: add extra initialization before printingvoid CRectangleView:OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)/ TODO: add cleanup after printing/ CRectangleView diagnostics#ifdef _DEBUGvoid CRectangleView:AssertValid() constCView:AssertValid();void CRectangleView:Dump(CDumpContext& dc) constCView:Dump(dc);CRectangleDoc* CRectangleView:GetDocument() / non-debug version is inlineASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CRectangleDoc);return (CRectangleDoc*)m_pDocument;#endif /_DEBUG/ CRectangleView message handlersvoid CRectangleView:OnLButtonDown(UINT nFlags, CPoint point) / TODO: Add your message handler code here and/or call default this->m_OrigPoint=point;CView:OnLButtonDown(nFlags, point);void CRectangleView:OnLButtonUp(UINT nFlags, CPoint point) / TODO: Add your message handler code here and/or call defaultCClientDC dc(this); dc.Rectangle(CRect(m_OrigPoint,point);CView:OnLButtonUp(nFlags, point);5输入输出情况及截图6总结体会 通过前期对VC+的学习和这次大作业,我对VC+有了进一步的认识,而且熟悉了如何建立单文档程序,多文档等程序,对Visual C+ 6.0 开发环境有了进一步了解,最重要的一点是我知道自己还有很多VC+知识要学,目前学到的知识只是一点皮毛而已,以后一定会更加努力,虽然VC+不是我的专业课,我们对它的要求也不是特别高,但是我觉得我以后还是会学一学这个的,多掌握一门编程语言,而且VC+在图形化编程里面用的还是比较广泛的,对我们的未来的发展只有好处,没有坏处!专心-专注-专业