求助关于VC++图形学,窗口重绘怎么解决
// 形状View.cpp : implementation of the CMyView class
//
#include "stdafx.h"
#include "形状.h"
#include "形状Doc.h"
#include "形状View.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CMyView
IMPLEMENT_DYNCREATE(CMyView, CView)
BEGIN_MESSAGE_MAP(CMyView, CView)
//{{AFX_MSG_MAP(CMyView)
ON_COMMAND(ID_CIRCLE, OnCircle)
ON_COMMAND(ID_HAND, OnHand)
ON_COMMAND(ID_RECT, OnRect)
ON_WM_LBUTTONDOWN()
ON_WM_LBUTTONUP()
ON_WM_MOUSEMOVE()
//}}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()
/////////////////////////////////////////////////////////////////////////////
// CMyView construction/destruction
CMyView::CMyView()
{
// TODO: add construction code here
m_hand=m_circle=m_rect=false;
}
CMyView::~CMyView()
{
}
BOOL CMyView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CMyView drawing
void CMyView::OnDraw(CDC* pDC)
{
CMyDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
}
/////////////////////////////////////////////////////////////////////////////
// CMyView printing
BOOL CMyView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CMyView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CMyView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CMyView diagnostics
#ifdef _DEBUG
void CMyView::AssertValid() const
{
CView::AssertValid();
}
void CMyView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CMyDoc* CMyView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CMyDoc)));
return (CMyDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CMyView message handlers
void CMyView::OnCircle()
{
// TODO: Add your command handler code here
m_circle=true;
m_rect=m_hand=false;
}
void CMyView::OnHand()
{
// TODO: Add your command handler code here
m_hand=true;
m_circle=m_rect=false;
}
void CMyView::OnRect()
{
// TODO: Add your command handler code here
m_rect=true;
m_circle=m_hand=false;
}
void CMyView::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
if(m_hand)
{
spt=point;
}
if(m_circle||m_rect)
{
SetCapture();
spt=point;
ept=point;
}
CView::OnLButtonDown(nFlags, point);
}
void CMyView::OnLButtonUp(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
ReleaseCapture();
CView::OnLButtonUp(nFlags, point);
}
void CMyView::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
CDC *pDC=GetDC();
if(m_hand&&(nFlags&&MK_LBUTTON))
{
pDC->MoveTo(spt);
pDC->LineTo(point);
spt=point;
}
if(m_rect&&(nFlags&&MK_LBUTTON))
{
CGdiObject *old=pDC->SelectStockObject(NULL_BRUSH);
int drawmode=pDC->GetROP2();//保存原有的绘图模式
pDC->SetROP2(R2_NOTCOPYPEN);//设置新的绘图模式
pDC->Rectangle(ept.x,ept.y,spt.x,spt.y);
pDC->SetROP2(drawmode);
pDC->Rectangle(spt.x,spt.y,point.x,point.y);
pDC->SelectObject(old);
ept=point;
}
if(m_circle&&(nFlags&&MK_LBUTTON))
{
CGdiObject *old=pDC->SelectStockObject(NULL_BRUSH);
int drawmode=pDC->GetROP2();//保存原有的绘图模式
pDC->SetROP2(R2_NOTCOPYPEN);//设置新的绘图模式
pDC->Ellipse(ept.x,ept.y,spt.x,spt.y);
pDC->SetROP2(drawmode);
pDC->Ellipse(spt.x,spt.y,point.x,point.y);
pDC->SelectObject(old);
ept=point;
}
CView::OnMouseMove(nFlags, point);
}