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

📄 dplpview.cpp

📁 vc++程序设计与技巧中第8章“图形图像编程”部分的VC++原代码
💻 CPP
字号:
// DPLPView.cpp : implementation of the CDPLPView class
//

#include "stdafx.h"
#include "DPLP.h"

#include "DPLPDoc.h"
#include "DPLPView.h"

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

/////////////////////////////////////////////////////////////////////////////
// CDPLPView

IMPLEMENT_DYNCREATE(CDPLPView, CView)

BEGIN_MESSAGE_MAP(CDPLPView, CView)
	//{{AFX_MSG_MAP(CDPLPView)
		// NOTE - the ClassWizard will add and remove mapping macros here.
		//    DO NOT EDIT what you see in these blocks of generated code!
	//}}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()

/////////////////////////////////////////////////////////////////////////////
// CDPLPView construction/destruction

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

}

CDPLPView::~CDPLPView()
{
}

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

	return CView::PreCreateWindow(cs);
}

/////////////////////////////////////////////////////////////////////////////
// CDPLPView drawing

void CDPLPView::OnDraw(CDC* pDC)
{
	CDPLPDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	// TODO: add draw code for native data here
	CPoint DeviceP1(130,40), DeviceP2(230,190);
	CString string1,string2;
	//记录先前的映射模式
	int nMapmode;
	
	//使用设备坐标绘制矩形
	pDC->Rectangle(DeviceP1.x,DeviceP1.y,DeviceP2.x,DeviceP2.y);
	
	//输出矩形两个端点的设备坐标,名称分别为DeviceP1和DeviceP2
	string1.Format("DP1(%d,%d)",DeviceP1.x,DeviceP1.y); 
	pDC->TextOut(DeviceP1.x-90,DeviceP1.y,string1);
	string2.Format("DP2(%d,%d)",DeviceP2.x,DeviceP2.y); 
	pDC->TextOut(DeviceP2.x,DeviceP2.y,string2);
	
	//设置映射模式为MM_LOENGLISH
	nMapmode = pDC->SetMapMode(MM_LOENGLISH);
	
	//将矩形的两个端点坐标转换为该映射模式下逻辑坐标
	pDC->DPtoLP(&DeviceP1);
	pDC->DPtoLP(&DeviceP2);
	
	//输出矩形两个端点的逻辑坐标,为了便于观察将名称分别改为Lp1和Lp2
	string1.Format("LP1(%d,%d)",DeviceP1.x,DeviceP1.y); 
	pDC->TextOut(DeviceP1.x-95,DeviceP1.y-30,string1);
	string2.Format("LP2(%d,%d)",DeviceP2.x,DeviceP2.y); 
	pDC->TextOut(DeviceP2.x,DeviceP2.y-30,string2);
	
	//使用逻辑坐标绘制矩形
	pDC->Rectangle(DeviceP1.x,DeviceP1.y,DeviceP2.x,DeviceP2.y);
	
	//恢复到先前的映射模式
	pDC->SetMapMode(nMapmode);
	
}

/////////////////////////////////////////////////////////////////////////////
// CDPLPView printing

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

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

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

/////////////////////////////////////////////////////////////////////////////
// CDPLPView diagnostics

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

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

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

/////////////////////////////////////////////////////////////////////////////
// CDPLPView message handlers

⌨️ 快捷键说明

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