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

📄 conndotview.cpp

📁 讲mfc的书
💻 CPP
字号:
// conndotView.cpp : implementation of the CConndotView class
//

#include "stdafx.h"
#include "conndot.h"
#include <afxpriv.h> // include preview window

#include "conndotDoc.h"
#include "conndotView.h"

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

/////////////////////////////////////////////////////////////////////////////
// CConndotView

IMPLEMENT_DYNCREATE(CConndotView, CView)

BEGIN_MESSAGE_MAP(CConndotView, CView)
	//{{AFX_MSG_MAP(CConndotView)
	ON_WM_LBUTTONDOWN()
	ON_WM_RBUTTONDOWN()
	ON_COMMAND(ID_FILE_PRINT_PREVIEW, OnFilePrintPreview)
	//}}AFX_MSG_MAP
	// Standard printing commands
	ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)

END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CConndotView construction/destruction

CConndotView::CConndotView()
{
	// TODO: add construction code here

}

CConndotView::~CConndotView()
{
}

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

	return CView::PreCreateWindow(cs);
}

/////////////////////////////////////////////////////////////////////////////
// CConndotView drawing

void CConndotView::OnDraw(CDC* pDC)
{
	CConndotDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	CPoint pt;
	if (pDC->IsPrinting())
	{
		CDC *vdc=GetDC();
		int n;
		n=vdc->GetDeviceCaps(LOGPIXELSX);
		pDC->SetMapMode(MM_ISOTROPIC);
		pDC->SetWindowExt(n,n);
		n=pDC->GetDeviceCaps(LOGPIXELSX);
		pDC->SetViewportExt(n,n);
	}
	pDC->MoveTo(0,0);
	for (int i=0;i<pDoc->points.GetSize();i++)
	{
		pt=pDoc->points[i];
		if (pt.x<0)
		{
			pt.x=-pt.x;
			pt.y=-pt.y;
			pDC->MoveTo(pt);
		}
		else
			pDC->LineTo(pt);
	}

}

/////////////////////////////////////////////////////////////////////////////
// CConndotView printing

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

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

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

/////////////////////////////////////////////////////////////////////////////
// CConndotView diagnostics

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

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

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

/////////////////////////////////////////////////////////////////////////////
// CConndotView message handlers

void CConndotView::OnLButtonDown(UINT nFlags, CPoint point) 
{
	CConndotDoc *doc=GetDocument();
	// Draw
	doc->points.Add(point);
	doc->UpdateAllViews(NULL);
	CView::OnLButtonDown(nFlags, point);
}

void CConndotView::OnRButtonDown(UINT nFlags, CPoint point) 
{
// move current point only
	CPoint mover=point;
	mover.x=-mover.x;
	mover.y=-mover.y;
	GetDocument()->points.Add(mover);
	CView::OnRButtonDown(nFlags, point);
}


void CConndotView::OnFilePrintPreview()
{
	    CPrintPreviewState* pState = new CPrintPreviewState;

        if (!DoPrintPreview(IDD_PREVIEW_TOOLBAR, this,
                            RUNTIME_CLASS(CPreviewView),pState))
        {
                // In derived classes, reverse special window handling here for
                // Preview failure case

                TRACE0("Error: DoPrintPreview failed.\n");
                AfxMessageBox(AFX_IDP_COMMAND_FAILURE);
                delete pState;      // preview failed to initialize, delete State
        }
}


⌨️ 快捷键说明

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