VC程序设计大作业熊武.doc
《VC程序设计大作业熊武.doc》由会员分享,可在线阅读,更多相关《VC程序设计大作业熊武.doc(9页珍藏版)》请在冰豆网上搜索。
武汉轻工大学
VC++程序设计大作业
院系电气与电子工程学院
班级
学号1204
姓名
日期2013.11.22
1题目
编写MFC下的单文档程序,通过鼠标点击选择两个点,作为矩形左上角、右下角,然后绘制矩形。
(对应12题)
2思路
首先点击鼠标,选中左上角,然后拖动鼠标,在右下角拿起,这样矩形就就可以实现了。
3程序实现过程
首先建立MFC单文档程序
然后建立类向导
添加鼠标事件
添加CPoint成员变量m_OrigPoint
4关键代码
//RectangleView.cpp:
implementationoftheCRectangleViewclass
//
#include"stdafx.h"
#include"Rectangle.h"
#include"RectangleDoc.h"
#include"RectangleView.h"
#ifdef_DEBUG
#definenewDEBUG_NEW
#undefTHIS_FILE
staticcharTHIS_FILE[]=__FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
//CRectangleView
IMPLEMENT_DYNCREATE(CRectangleView,CView)
BEGIN_MESSAGE_MAP(CRectangleView,CView)
//{{AFX_MSG_MAP(CRectangleView)
ON_WM_LBUTTONDOWN()
ON_WM_LBUTTONUP()
//}}AFX_MSG_MAP
//Standardprintingcommands
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()
/////////////////////////////////////////////////////////////////////////////
//CRectangleViewconstruction/destruction
CRectangleView:
:
CRectangleView()
{
//TODO:
addconstructioncodehere
}
CRectangleView:
:
~CRectangleView()
{
}
BOOLCRectangleView:
:
PreCreateWindow(CREATESTRUCT&cs)
{
//TODO:
ModifytheWindowclassorstylesherebymodifying
//theCREATESTRUCTcs
returnCView:
:
PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
//CRectangleViewdrawing
voidCRectangleView:
:
OnDraw(CDC*pDC)
{
CRectangleDoc*pDoc=GetDocument();
ASSERT_VALID(pDoc);
//TODO:
adddrawcodefornativedatahere
}
/////////////////////////////////////////////////////////////////////////////
//CRectangleViewprinting
BOOLCRectangleView:
:
OnPreparePrinting(CPrintInfo*pInfo)
{
//defaultpreparation
returnDoPreparePrinting(pInfo);
}
voidCRectangleView:
:
OnBeginPrinting(CDC*/*pDC*/,CPrintInfo*/*pInfo*/)
{
//TODO:
addextrainitializationbeforeprinting
}
voidCRectangleView:
:
OnEndPrinting(CDC*/*pDC*/,CPrintInfo*/*pInfo*/)
{
//TODO:
addcleanupafterprinting
}
/////////////////////////////////////////////////////////////////////////////
//CRectangleViewdiagnostics
#ifdef_DEBUG
voidCRectangleView:
:
AssertValid()const
{
CView:
:
AssertValid();
}
voidCRectangleView:
:
Dump(CDumpContext&dc)const
{
CView:
:
Dump(dc);
}
CRectangleDoc*CRectangleView:
:
GetDocument()//non-debugversionisinline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CRectangleDoc)));
return(CRectangleDoc*)m_pDocument;
}
#endif//_DEBUG
/////////////////////////////////////////////////////////////////////////////
//CRectangleViewmessagehandlers
voidCRectangleView:
:
OnLButtonDown(UINTnFlags,CPointpoint)
{
//TODO:
Addyourmessagehandlercodehereand/orcalldefault
this->m_OrigPoint=point;
CView:
:
OnLButtonDown(nFlags,point);
}
voidCRectangleView:
:
OnLButtonUp(UINTnFlags,CPointpoint)
{
//TODO:
Addyourmessagehandlercodehereand/orcalldefault
CClientDCdc(this);
dc.Rectangle(CRect(m_OrigPoint,point));
CView:
:
OnLButtonUp(nFlags,point);
}
5输入输出情况及截图
6总结体会
通过前期对VC++的学习和这次大作业,我对VC++有了进一步的认识,而且熟悉了如何建立单文档程序,多文档等程序,对VisualC++6.0开发环境有了进一步了解,最重要的一点是我知道自己还有很多VC++知识要学,目前学到的知识只是一点皮毛而已,以后一定会更加努力,虽然VC++不是我的专业课,我们对它的要求也不是特别高,但是我觉得我以后还是会学一学这个的,多掌握一门编程语言,而且VC++在图形化编程里面用的还是比较广泛的,对我们的未来的发展只有好处,没有坏处!
熊武——VC++大作业