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

📄 mydrawboardview.cpp

📁 一个用c++编写的画图板程序,
💻 CPP
字号:
// MyDrawBoardView.cpp : implementation of the CMyDrawBoardView class
//

#include "stdafx.h"
#include "MyDrawBoard.h"

#include "MyDrawBoardDoc.h"
#include "MyDrawBoardView.h"
#include "MyLine.h"
#include "PenStyle.h"
 
 
 

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

/////////////////////////////////////////////////////////////////////////////
// CMyDrawBoardView

IMPLEMENT_DYNCREATE(CMyDrawBoardView, CView)

BEGIN_MESSAGE_MAP(CMyDrawBoardView, CView)
	//{{AFX_MSG_MAP(CMyDrawBoardView)
	ON_COMMAND(ID_PenStyle, OnPenStyle)
	ON_WM_LBUTTONDOWN()
	ON_WM_LBUTTONUP()
	ON_WM_MOUSEMOVE()
	ON_COMMAND(ID_EDIT_BACK, OnEditBack)
	ON_COMMAND(ID_EDIT_CLEARALL, OnEditClearall)
	//}}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()

/////////////////////////////////////////////////////////////////////////////
// CMyDrawBoardView construction/destruction

CMyDrawBoardView::CMyDrawBoardView()
{
	// TODO: add construction code here
    m_StartPoint=(0,0);
	m_EndPoint=(0,0);
	m_flag=FALSE;
	m_PenWidth = 1;
	m_PenColor = RGB(0,0,0);
}

CMyDrawBoardView::~CMyDrawBoardView()
{
}

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

	return CView::PreCreateWindow(cs);
}

/////////////////////////////////////////////////////////////////////////////
// CMyDrawBoardView drawing

void CMyDrawBoardView::OnDraw(CDC* pDC)
{
	CMyDrawBoardDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	//CMyDrawBoardDoc *pDoc=GetDocument();
	CMyLine *pline;
	for(int i=0;i<pDoc->m_LineArray.GetSize ();i++)
	{
	  pline= pDoc->GetLine(i);
	  pline->CDrawLine(pDC);
	}
	
	// TODO: add draw code for native data here
}

/////////////////////////////////////////////////////////////////////////////
// CMyDrawBoardView printing

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

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

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

/////////////////////////////////////////////////////////////////////////////
// CMyDrawBoardView diagnostics

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

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

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

/////////////////////////////////////////////////////////////////////////////
// CMyDrawBoardView message handlers

void CMyDrawBoardView::OnPenStyle() 
{
	CPenStyle  dlg;
	dlg.DoModal();
	m_PenWidth = dlg.m_PenWidth;
	m_PenColor = dlg.m_PenColor;
	// TODO: Add your command handler code here
	
}

void CMyDrawBoardView::OnLButtonDown(UINT nFlags, CPoint point) 
{
	m_StartPoint=point;
	m_EndPoint=point;
	m_flag=TRUE;

 
	// TODO: Add your message handler code here and/or call default
	
	CView::OnLButtonDown(nFlags, point);
}

void CMyDrawBoardView::OnLButtonUp(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
	m_flag=FALSE;
    m_EndPoint=point;
    CMyDrawBoardDoc *pDoc=GetDocument();
	pDoc->AddLine(m_StartPoint,m_EndPoint,m_PenWidth,m_PenColor);
	Invalidate(false);
	CView::OnLButtonUp(nFlags, point);
}

void CMyDrawBoardView::OnMouseMove(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
	if(m_flag)
	{
	 CClientDC dc(this);
	 dc.SetROP2(R2_NOT);
	 CPen newpen,*oldpen;

	 newpen.CreatePen(0,m_PenWidth,m_PenColor);
	 oldpen=dc.SelectObject(&newpen);
     
	 dc.MoveTo(m_StartPoint);
	 dc.LineTo(m_EndPoint);
	 m_EndPoint=point;
	 dc.MoveTo(m_StartPoint);
	 dc.LineTo(m_EndPoint);
     
	 dc.SelectObject(oldpen);
	}
	


	CView::OnMouseMove(nFlags, point);
}

void CMyDrawBoardView::OnEditBack() 
{
	// TODO: Add your command handler code here
	CMyDrawBoardDoc* pDoc = GetDocument();
	 pDoc->DeleteOneLine();
	 Invalidate(TRUE);
}

void CMyDrawBoardView::OnEditClearall() 
{
	 CMyDrawBoardDoc* pDoc = GetDocument();
	 pDoc->DeleteAllLine();
	 Invalidate(TRUE);	 
	// TODO: Add your command handler code here
	
}

⌨️ 快捷键说明

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