初学者 求解一个问题
下面是简单的 用鼠标绘制一条直线 的代码 运行过程中 绘制直线反映很慢 谁能帮忙看看啊 谢谢诶#include "stdafx.h"
#include "sffg.h"
#include "sffgDoc.h"
#include "sffgView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CSffgView
IMPLEMENT_DYNCREATE(CSffgView, CView)
BEGIN_MESSAGE_MAP(CSffgView, CView)
//{{AFX_MSG_MAP(CSffgView)
ON_COMMAND(ID_LINE, OnLine)
ON_COMMAND(ID_NLINE, OnNline)
ON_WM_LBUTTONDOWN()
ON_UPDATE_COMMAND_UI(ID_LINE, OnUpdateLine)
//}}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()
/////////////////////////////////////////////////////////////////////////////
// CSffgView construction/destruction
CSffgView::CSffgView()
{
// TODO: add construction code here
m_bLine=FALSE;
m_startX=m_startY=0;
m_step=0;
}
CSffgView::~CSffgView()
{
}
BOOL CSffgView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CSffgView drawing
void CSffgView::OnDraw(CDC* pDC)
{
CSffgDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
}
/////////////////////////////////////////////////////////////////////////////
// CSffgView printing
BOOL CSffgView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CSffgView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CSffgView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CSffgView diagnostics
#ifdef _DEBUG
void CSffgView::AssertValid() const
{
CView::AssertValid();
}
void CSffgView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CSffgDoc* CSffgView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CSffgDoc)));
return (CSffgDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CSffgView message handlers
void CSffgView::OnLine()
{
// TODO: Add your command handler code here
CClientDC dc(this);
m_bLine=TRUE;
//dc.TextOut(100,100,"shif");
}
void CSffgView::OnNline()
{
// TODO: Add your command handler code here
CClientDC dc(this);
m_bLine=FALSE;
}
void CSffgView::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
CClientDC dc(this);
if(m_bLine)
{
if(m_step==0)
{
m_startX=point.x;
m_startY=point.y;
m_step++;
}
else
{
dc.MoveTo(m_startX,m_startY);
dc.LineTo(point.x,point.y);
m_step=0;
}
}
CView::OnLButtonDown(nFlags, point);
}
void CSffgView::OnUpdateLine(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->SetRadio(m_bLine);
}