武 汉 轻 工 大 学
VC++程序设计大作业
鼠标点击绘制矩形
院系 电气与电子工程学院
班级
学号 1204
姓名
日期 2013.11.22
VC++大作业
1题目
编写MFC下的单文档程序,通过鼠标点击选择两个点,作为矩形左上角、右下角,然后绘制矩形。(对应12题)
2思路
首先点击鼠标,选中左上角,然后拖动鼠标,在右下角拿起,这样矩形就就可以实现了。
3程序实现过程
首先建立MFC单文档程序
VC++大作业
然后建立类向导
添加鼠标事件
VC++大作业
添加CPoint成员变量m_OrigPoint
4关键代码
// RectangleView.cpp : implementation of the CRectangleView class //
#include \#include \
#include \#include \
VC++大作业
#ifdef _DEBUG
#define new DEBUG_NEW #undef THIS_FILE
static char THIS_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 // Standard printing commands 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()
///////////////////////////////////////////////////////////////////////////// // CRectangleView construction/destruction
CRectangleView::CRectangleView() { // TODO: add construction code here }
CRectangleView::~CRectangleView() { }
BOOL CRectangleView::PreCreateWindow(CREATESTRUCT& cs) { // TODO: Modify the Window class or styles here by modifying // the CREATESTRUCT cs return CView::PreCreateWindow(cs); }
VC++大作业