MFC鼠标绘图
来源:互联网 发布:淘宝网纯皮钱包男士 编辑:程序博客网 时间:2024/04/29 05:41
最近刚开始学习Visual c++6.0
还是菜鸟级别
单击左键,画点
按住左键拖动,画线
单击右键,清除屏幕
改变画框大小,画面重画
// MyProg2bView.cpp : implementation of the CMyProg2bViewclass
//
#include "stdafx.h"
#include "MyProg2b.h"
#include "MyProg2bDoc.h"
#include "MyProg2bView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CMyProg2bView
IMPLEMENT_DYNCREATE(CMyProg2bView, CView)
BEGIN_MESSAGE_MAP(CMyProg2bView, CView)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CMyProg2bView construction/destruction
CMyProg2bView::CMyProg2bView()
{
}
CMyProg2bView::~CMyProg2bView()
{
}
BOOLCMyProg2bView::PreCreateWindow(CREATESTRUCT&cs)
{
}
/////////////////////////////////////////////////////////////////////////////
// CMyProg2bView drawing
void CMyProg2bView::OnDraw(CDC* pDC)
{
m_nPrevIndex=nPositions-1;
}
(增加变量m_nPrevIndex来保存最新画过的鼠标位置在表中的下标,画完之后,更新该成员保存的下标值以提示最新画过的鼠标的位置)
/////////////////////////////////////////////////////////////////////////////
// CMyProg2bView printing
BOOL CMyProg2bView::OnPreparePrinting(CPrintInfo* pInfo)
{
}
void CMyProg2bView::OnBeginPrinting(CDC* , CPrintInfo* )
{
}
void CMyProg2bView::OnEndPrinting(CDC* , CPrintInfo* )
{
}
/////////////////////////////////////////////////////////////////////////////
// CMyProg2bView diagnostics
#ifdef _DEBUG
void CMyProg2bView::AssertValid() const
{
}
void CMyProg2bView::Dump(CDumpContext& dc)const
{
}
CMyProg2bDoc* CMyProg2bView::GetDocument() // non-debug versionis inline
{
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CMyProg2bView message handlers
void CMyProg2bView::OnLButtonDown(UINT nFlags, CPoint point)
{
}
void CMyProg2bView::OnRButtonDown(UINT nFlags, CPointpoint)
{
}
void CMyProg2bView::ClearList()
{
}
//每个CPoint对象都是由一个new操作符从堆中分配内存的,所以与之对应,每个CPoint对象也要由一个delete来释放。m_MousePosition中所有指针指向的对象都已释放之后,调用RemoveAll()将用到的数组置空。
void CMyProg2bView::OnMouseMove(UINT nFlags, CPoint point)
{
}
void CMyProg2bView::AddList(int button, CPoint point)
{
}
BOOL CMyProg2bView::OnEraseBkgnd(CDC* pDC)
{
}
(无论何时客户区被擦除,就发送一个名为WM_REASEBKGND的消息,WM_LBUTTONDOWN和WM_MOUSEMOVE消息引起的扥更新并不擦除背景(若要跳过擦屏,调用Invalidate()时就要以FALSE作参数).一收到WM_REASEBKGND消息,就知道必须用保存的信息重画整个窗口)