⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 draw_lineview.cpp

📁 关于使用VC编程的代码
💻 CPP
字号:
// Draw_LineView.cpp : implementation of the CDraw_LineView class
//

#include "stdafx.h"
#include "Draw_Line.h"

#include "Draw_LineDoc.h"
#include "Draw_LineView.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CDraw_LineView

IMPLEMENT_DYNCREATE(CDraw_LineView, CView)

BEGIN_MESSAGE_MAP(CDraw_LineView, CView)
	//{{AFX_MSG_MAP(CDraw_LineView)
	ON_WM_LBUTTONDOWN()
	ON_WM_MOUSEMOVE()
	ON_WM_LBUTTONUP()
	ON_COMMAND(ID_DRAW_TRIANGLE, OnDrawTriangle)
	ON_UPDATE_COMMAND_UI(ID_DRAW_TRIANGLE, OnUpdateDrawTriangle)
	//}}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)
	ON_MESSAGE(WM_TRIANGLE_COMPLETED, CDraw_LineView::OnTriangleCompleted)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CDraw_LineView construction/destruction

CDraw_LineView::CDraw_LineView()
{
	// TODO: add construction code here
	m_bDraw = FALSE;
	m_bTriangle = FALSE;

}

CDraw_LineView::~CDraw_LineView()
{
}

BOOL CDraw_LineView::PreCreateWindow(CREATESTRUCT& cs)
{
	// TODO: Modify the Window class or styles here by modifying
	//  the CREATESTRUCT cs

	return CView::PreCreateWindow(cs);
}

/////////////////////////////////////////////////////////////////////////////
// CDraw_LineView drawing

void CDraw_LineView::OnDraw(CDC* pDC)
{
	CDraw_LineDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	// TODO: add draw code for native data here
}

/////////////////////////////////////////////////////////////////////////////
// CDraw_LineView printing

BOOL CDraw_LineView::OnPreparePrinting(CPrintInfo* pInfo)
{
	// default preparation
	return DoPreparePrinting(pInfo);
}

void CDraw_LineView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add extra initialization before printing
}

void CDraw_LineView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add cleanup after printing
}

/////////////////////////////////////////////////////////////////////////////
// CDraw_LineView diagnostics

#ifdef _DEBUG
void CDraw_LineView::AssertValid() const
{
	CView::AssertValid();
}

void CDraw_LineView::Dump(CDumpContext& dc) const
{
	CView::Dump(dc);
}

CDraw_LineDoc* CDraw_LineView::GetDocument() // non-debug version is inline
{
	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CDraw_LineDoc)));
	return (CDraw_LineDoc*)m_pDocument;
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CDraw_LineView message handlers

void CDraw_LineView::OnLButtonDown(UINT nFlags, CPoint point) 
{
	if(m_bDraw == FALSE)
	{
		m_bDraw = TRUE;
		m_OrgPoint = point;
		m_NewPoint = point;
		SetCapture();
	}
	
	CView::OnLButtonDown(nFlags, point);
}

void CDraw_LineView::OnMouseMove(UINT nFlags, CPoint point) 
{
	CDC *pDC = GetDC();

	if(m_bDraw == TRUE)
	{
		pDC->MoveTo(m_OrgPoint);	
		pDC->SetROP2(R2_NOT);
		pDC->LineTo(m_NewPoint);
		pDC->MoveTo(m_OrgPoint);	
		pDC->LineTo(point);
		m_NewPoint = point;
	}
	CView::OnMouseMove(nFlags, point);
}

void CDraw_LineView::OnLButtonUp(UINT nFlags, CPoint point) 
{
	m_bDraw = FALSE;
	ReleaseCapture();
	CView::OnLButtonUp(nFlags, point);
}

void CDraw_LineView::OnDrawTriangle() 
{
	if( m_bTriangle == FALSE)
	{
		m_bTriangle = TRUE;
		CDC* pDC = 	GetDC();
		pDC->MoveTo(10,10);
		pDC->LineTo(10,100);
		pDC->LineTo(100,100);
		pDC->LineTo(10,10);
		SendMessage(WM_TRIANGLE_COMPLETED);
	}
}

void CDraw_LineView::OnUpdateDrawTriangle(CCmdUI* pCmdUI) 
{
	pCmdUI->Enable( m_bTriangle == FALSE );	
}

LRESULT CDraw_LineView::OnTriangleCompleted(WPARAM wParam, LPARAM lParam)
{
	AfxMessageBox("triangle completed!");
	return 0L;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -