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

📄 printerinfoex.cpp

📁 通过手机数据线连接手机
💻 CPP
字号:
// PrinterInfoEx.cpp: implementation of the CPrinterInfoEx class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "PrinterInfoEx.h"

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

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CPrinterInfoEx::CPrinterInfoEx()
{
	m_pDC = NULL;
}

CPrinterInfoEx::~CPrinterInfoEx()
{
}

BOOL CPrinterInfoEx::Init( CDC * pDC )
{
	m_pDC = NULL;
	m_continueNextPage = FALSE;

	if( pDC == NULL )
	{
		return FALSE;
	}

	if( !pDC->IsPrinting() )
	{
		return FALSE;
	}

	m_pDC = pDC;

	// 1米 = 39.37008英寸
	m_xResolution = long(pDC->GetDeviceCaps( LOGPIXELSX ) * 39.37008);
	m_yResolution = long(pDC->GetDeviceCaps( LOGPIXELSY ) * 39.37008);

	if( m_xResolution <= 0 )
	{
		m_xResolution = long(300 * 39.37008);
	}
	if( m_yResolution <= 0 )
	{
		m_xResolution = m_xResolution;
	}
	
	m_paperWidth = pDC->GetDeviceCaps( HORZSIZE ) * 10;
	m_paperHeight = pDC->GetDeviceCaps( VERTSIZE ) * 10;
	
	m_widthPixel = pDC->GetDeviceCaps( HORZRES );
	m_heightPixel = pDC->GetDeviceCaps( VERTRES );

	m_printRect = CRect( 0, 0, m_widthPixel, m_heightPixel );

	return TRUE;
}

void CPrinterInfoEx::ConvertPixelToReal(long & x, long & y)
{
	ASSERT( m_pDC != NULL );

double piX = x;
double piY = y;

	//注意:resolution单位是点/米
	piX *= 10000;
	x = long(piX / m_xResolution);
	piY *= 10000;
	y = long(piY / m_yResolution);
}

void CPrinterInfoEx::ConvertRealToPixel(long & x, long & y)
{
	ASSERT( m_pDC != NULL );
double realX = x;
double realY = y;

	//注意:resolution单位是点/米
	realX /= 10000;
	x = long(realX * m_xResolution);
	realY /= 10000;
	y = long(realY * m_yResolution);
}

BOOL CPrinterInfoEx::CanPrint()
{
	if( m_pDC == NULL )
	{
		return FALSE;
	}

	if( m_printRect.top >= m_printRect.bottom
	 || m_printRect.left >= m_printRect.right )
	{//无可用打印范围
		return FALSE;
	}

	return TRUE;
}

⌨️ 快捷键说明

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