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

📄 myview.cpp

📁 VC面向对象的学习教程
💻 CPP
字号:
// MyView.cpp : implementation of the CMy1603View class
//

#include "stdafx.h"
#include "My.h"

#include "MyDoc.h"
#include "MyView.h"

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

/////////////////////////////////////////////////////////////////////////////
// CMy1603View

IMPLEMENT_DYNCREATE(CMy1603View, CScrollView)

BEGIN_MESSAGE_MAP(CMy1603View, CScrollView)
	//{{AFX_MSG_MAP(CMy1603View)
	ON_COMMAND(ID_WIDTH1, OnWidth1)
	ON_UPDATE_COMMAND_UI(ID_WIDTH1, OnUpdateWidth1)
	ON_COMMAND(ID_WIDTH3, OnWidth3)
	ON_UPDATE_COMMAND_UI(ID_WIDTH3, OnUpdateWidth3)
	ON_COMMAND(ID_WIDTH5, OnWidth5)
	ON_UPDATE_COMMAND_UI(ID_WIDTH5, OnUpdateWidth5)
	ON_COMMAND(ID_WIDTH7, OnWidth7)
	ON_UPDATE_COMMAND_UI(ID_WIDTH7, OnUpdateWidth7)
	ON_COMMAND(ID_COLOR, OnColor)
	ON_WM_LBUTTONDOWN()
	ON_WM_LBUTTONUP()
	ON_WM_MOUSEMOVE()
	//}}AFX_MSG_MAP
	// Standard printing commands
	ON_COMMAND(ID_FILE_PRINT, CScrollView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_DIRECT, CScrollView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_PREVIEW, CScrollView::OnFilePrintPreview)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CMy1603View construction/destruction

CMy1603View::CMy1603View():m_pointFrom(0,0), m_pointTo(0,0)
{
	m_bCaptured   = FALSE;
	m_colorCurr  = RGB(255, 0, 0);
	m_nCurrWidth = 3;
	// TODO: add construction code here

}

CMy1603View::~CMy1603View()
{
}

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

	return CScrollView::PreCreateWindow(cs);
}

/////////////////////////////////////////////////////////////////////////////
// CMy1603View drawing

void CMy1603View::OnDraw(CDC* pDC)
{
	CMy1603Doc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	// TODO: add draw code for native data here
	for(int i=0; i<pDoc->m_nCount; i++)
				pDoc->m_lineList[i].DrawLine(pDC);
}

/////////////////////////////////////////////////////////////////////////////
// CMy1603View printing

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

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

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

/////////////////////////////////////////////////////////////////////////////
// CMy1603View diagnostics

#ifdef _DEBUG
void CMy1603View::AssertValid() const
{
	CScrollView::AssertValid();
}

void CMy1603View::Dump(CDumpContext& dc) const
{
	CScrollView::Dump(dc);
}

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

/////////////////////////////////////////////////////////////////////////////
// CMy1603View message handlers

void CMy1603View::OnWidth1() 
{
	// TODO: Add your command handler code here
	m_nCurrWidth = 1;		
}

void CMy1603View::OnUpdateWidth1(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	pCmdUI->SetCheck(m_nCurrWidth == 1);	
}

void CMy1603View::OnWidth3() 
{
	// TODO: Add your command handler code here
	m_nCurrWidth = 3;		
}

void CMy1603View::OnUpdateWidth3(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	pCmdUI->SetCheck(m_nCurrWidth == 3);	
}

void CMy1603View::OnWidth5() 
{
	// TODO: Add your command handler code here
	m_nCurrWidth = 5;		
}

void CMy1603View::OnUpdateWidth5(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	pCmdUI->SetCheck(m_nCurrWidth == 5);	
	
}

void CMy1603View::OnWidth7() 
{
	// TODO: Add your command handler code here
	m_nCurrWidth = 7;		
}

void CMy1603View::OnUpdateWidth7(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	pCmdUI->SetCheck(m_nCurrWidth == 7);	
}

void CMy1603View::OnColor() 
{
	// TODO: Add your command handler code here
	CColorDialog dlg(m_colorCurr);
	if(dlg.DoModal() == IDOK)
				m_colorCurr = dlg.GetColor();
	
}

void CMy1603View::OnLButtonDown(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
	CScrollView::OnLButtonDown(nFlags, point);
	CClientDC dc(this);
	OnPrepareDC(&dc);
	dc.DPtoLP(&point);
	m_pointFrom = m_pointTo = point;
	SetCapture();
	m_bCaptured = TRUE;

}

void CMy1603View::OnLButtonUp(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
	CScrollView::OnLButtonUp(nFlags, point);
	if(m_bCaptured)
	{	
		CMy1603Doc* pDoc = GetDocument();
		ASSERT_VALID(pDoc);
		CClientDC dc(this);
		OnPrepareDC(&dc);
		dc.DPtoLP(&point);
		m_pointTo = point;
		m_bCaptured = FALSE;
		ReleaseCapture();
		CPoint org = GetScrollPosition();
		pDoc->m_lineList[pDoc->m_nCount] = CLine(m_pointFrom+org,
			m_pointTo+org, m_colorCurr, m_nCurrWidth);
		pDoc->m_nCount++;
		pDoc->SetModifiedFlag();
		pDoc->UpdateAllViews(this);
		Invalidate();
	}

}

void CMy1603View::OnMouseMove(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
	CScrollView::OnMouseMove(nFlags, point);
	if(m_bCaptured)
	{
		CClientDC dc(this);
		OnPrepareDC(&dc);
		dc.DPtoLP(&point);
		dc.SetROP2(R2_NOT);
		dc.MoveTo(m_pointFrom);
		dc.LineTo(m_pointTo);
		m_pointTo = point;		
		dc.MoveTo(m_pointFrom);
		dc.LineTo(m_pointTo);
	}

}

void CMy1603View::OnInitialUpdate() 
{
	CScrollView::OnInitialUpdate();
	SetScrollSizes(MM_TWIPS, CSize(11520, 15120));
	// TODO: Add your specialized code here and/or call the base class
	
}

void CMy1603View::OnPrepareDC(CDC* pDC, CPrintInfo* pInfo) 
{
	// TODO: Add your specialized code here and/or call the base class
	pDC->SetMapMode(MM_TWIPS);
	CScrollView::OnPrepareDC(pDC, pInfo);
}

⌨️ 快捷键说明

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