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

📄 line.cpp

📁 mfc例题与练习第二版 例题与练习第二版
💻 CPP
字号:
// Line.cpp: implementation of the CLine class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "exp32_2.h"
#include "Line.h"

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

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
IMPLEMENT_SERIAL(CLine,CObject,1)

CLine::CLine():m_ptStart(0,0),m_ptEnd(0,0)
{
	m_color = RGB(0,0,0);
}
CLine::CLine(int x1,int y1,int x2,int y2):m_ptStart(x1,y1),m_ptEnd(x2,y2)
{

}

CLine::~CLine()
{

}

void CLine::Serialize(CArchive& ar)
{
	if (ar.IsStoring())
	{
		// TODO: add storing code here
		ar<<m_ptStart<<m_ptEnd<<m_color;
	}
	else
	{
		// TODO: add loading code here
		ar>>m_ptStart>>m_ptEnd>>m_color;
	}
}

void CLine::Draw(CDC* pDC)
{
	CPen pen(PS_SOLID,0,m_color);
	CPen *oldPen;
	oldPen = pDC->SelectObject(&pen);

	pDC->MoveTo(m_ptStart);
	pDC->LineTo(m_ptEnd);
	pDC->SelectObject(oldPen);
}

void CLine::Show(CDC* pDC,int y)
{
	TEXTMETRIC tm;
	pDC->GetTextMetrics(&tm);
	int cx,l,x = 0;
	cx = tm.tmAveCharWidth;
	pDC->SetTextColor(m_color);
	char st[15],ed[15];
	wsprintf(st,"%d  %d",m_ptStart.x,m_ptStart.y);
	wsprintf(ed,"%d  %d",m_ptEnd.x,m_ptEnd.y);
	pDC->TextOut(x,y,"Line,start:",l=strlen("Line,start:"));
	x += (l+1)*cx;
	pDC->TextOut(x,y,st,l=strlen(st));
	x += (l+1)*cx;
	pDC->TextOut(x,y," End:",l=strlen(" End:"));
	x += (l+1)*cx;
	pDC->TextOut(x,y,ed,l=strlen(ed));
}

⌨️ 快捷键说明

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