【VC开源代码栏目提醒】:以下是网学会员为您推荐的VC开源代码-CDraw_1View.cpp,希望本篇文章对您学习有所帮助。
// CDraw_1View.cpp : implementation of the CCDraw_1View class
//
#include "stdafx.h"
#include "CDraw_1.h"
#include "CDraw_1Doc.h"
#include "CDraw_1View.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CCDraw_1View
IMPLEMENT_DYNCREATE(CCDraw_1View, CView)
BEGIN_MESSAGE_MAP(CCDraw_1View, CView)
//{{AFX_MSG_MAP(CCDraw_1View)
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()
/////////////////////////////////////////////////////////////////////////////
// CCDraw_1View construction/destruction
CCDraw_1View::CCDraw_1View()
{
// TODO: add construction code here
m_point=0;
}
CCDraw_1View::~CCDraw_1View()
{
}
BOOL CCDraw_1View::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CCDraw_1View drawing
void CCDraw_1View::OnDraw(CDC* pDC)
{
CCDraw_1Doc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
}
/////////////////////////////////////////////////////////////////////////////
// CCDraw_1View printing
BOOL CCDraw_1View::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CCDraw_1View::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CCDraw_1View::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CCDraw_1View diagnostics
#ifdef _DEBUG
void CCDraw_1View::AssertValid() const
{
CView::AssertValid();
}
void CCDraw_1View::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CCDraw_1Doc* CCDraw_1View::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CCDraw_1Doc)));
return (CCDraw_1Doc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CCDraw_1View message handlers
void CCDraw_1View::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
m_point=point; //获得起点坐标
CView::OnLButtonDown(nFlags, point);
}
void CCDraw_1View::OnLButtonUp(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
HDC hdc;
hdc=::GetDC(m_hWnd); //获得窗口的句柄
MoveToEx(hdc,m_point.x,m_point.y,NULL);
LineTo(hdc,point.x,point.y);
::ReleaseDC(m_hWnd,hdc); //释放句柄
CView::OnLButtonUp(nFlags, point);
}