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

📄 cpage.cpp

📁 Windows下打印函数库
💻 CPP
📖 第 1 页 / 共 5 页
字号:
	SaveState();    
	m_PrtDesc.rc.top=top;		
	m_PrtDesc.rc.bottom=bottom;		
	m_PrtDesc.rc.left=left;		
	m_PrtDesc.rc.right=right;		
	m_PrtDesc.Text=name;
	PrintTheBitMap(&m_PrtDesc);
	RestoreState();	
}

////////////////////////////////////////////////////////////////////////////
//	Desc:	See above
//	params:
//	Returns:
///////////////////////////////////////////////////////////////////////////
void CPage::PrintBitMap(double top,double left,double bottom,double right,LPCSTR name)
{
	extern BOOL WINAPI PrintTheBitMap(PRTTYPE *ps);
	SaveState();
	ConvertArea(top,left,bottom,right);
	m_PrtDesc.rc.top=(int)top;		
	m_PrtDesc.rc.bottom=(int)bottom;		
	m_PrtDesc.rc.left=(int)left;		
	m_PrtDesc.rc.right=(int)right;		
	m_PrtDesc.Text=name;
	PrintTheBitMap(&m_PrtDesc);
	RestoreState();	
}
////////////////////////////////////////////////////////////////////////////
//	Helper class CPrintTable here
////////////////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////////////////
//	Desc: places a value in a cell on the table defined as row,col. Do not call direct
//	params:
//	Returns:
///////////////////////////////////////////////////////////////////////////
void CPrintTable::InsertItem(LPCSTR Text,int row,int col,int PointSize,UINT TextFlags)
{                       
	int	y,SCol,ECol,Row;
	int	 sz=GetVerticalSpacing();
	if(row >= m_pTable->NumRows)        
		return;                                                                   
	if(PointSize < 1)
		PointSize=m_pTable->PointSize;		              
	// 	vertical displacement is determined by the font used by the column headers. If
	//	the font used to insert a item is larger it will look funny. So we adjust that
	//	here by assuring the font for the item is no larger than the column header
	if(PointSize > m_pTable->PointSize)
	{
		if(m_pTable->HLines==TRUE && m_pTable->HeaderOnly==FALSE)		
			PointSize=m_pTable->PointSize;		
	}			                                                
	//	determine the bounds of the print rect
	//	row	
	Row=m_pTable->NoHeader==FALSE ? (int) (m_pTable->StartRow+(m_pTable->HeaderLines*(GetVerticalSpacing(FALSE)))+( (sz)*row)):
	                                (int) (m_pTable->StartRow+( (sz)*row));			                                
	//	col
	SCol=(int) m_pTable->StartCol;
	for(y=0;y < col;++y)
		SCol+=(int) m_pTable->ColDesc[y].Width;
		
	ECol=(int)(SCol+m_pTable->ColDesc[col].Width);
	m_ps->rc.left=SCol+2;
	m_ps->rc.right=ECol-2;
	m_ps->rc.top=Row+2;
	m_ps->rc.bottom=(Row+sz)-2;
	m_ps->Text=Text;
	if(m_pTable->NumPrintLines==1)
		m_ps->uTextFlags=TextFlags|TEXT_VCENTER|TEXT_SINGLELINE;
	else
		m_ps->uTextFlags=TextFlags;
	m_ps->PointSize=PointSize;	
	p_Print->ThePrinter.PrintText(m_ps,2);			
	p_Print->m_nNextPos=m_ps->m_NextCharPos;
}

////////////////////////////////////////////////////////////////////////////
//	Desc: places a value in a cell on the table defined as row,col
//	used only with tables that are header only type. This routine does no
//	checking for valid rows only for columns
//	params:
//	Returns:
///////////////////////////////////////////////////////////////////////////
	
void CPrintTable::InsertVirtualItem(LPCSTR Text,int row,int col,int PointSize,UINT TextFlags)
{
	int	y,SCol,ECol,Row;
	//	not Noheader NoHeader means we have a grid with no column descriptors while
	//	HeaderOnly means we have a header with no table body. With header only we
	//	will still have the column descriptors to use to set margins for each field
	//	so we can add fields till we run out of room on the page
	int	 sz=GetVerticalSpacing();
	if(m_pTable->HeaderOnly==FALSE)
		return;
	if(PointSize < 1)
		PointSize=m_pTable->PointSize;		
	//	determine the bounds of the print rect
	//	row	. 
	//  The start pos + (the # Header lines * the size of line)+(row# * size)
	Row=(int) (m_pTable->StartRow+(m_pTable->HeaderLines*(GetVerticalSpacing(FALSE)))+( (sz)*row));		
	//	col
	SCol=(int) m_pTable->StartCol;
	for(y=0;y < col;++y)
		SCol+=(int) m_pTable->ColDesc[y].Width;
		
	ECol=(int) (SCol+m_pTable->ColDesc[col].Width);
	m_ps->rc.left=SCol+1;
	m_ps->rc.right=ECol-1;
	m_ps->rc.top=Row+1;
	m_ps->rc.bottom=Row+(sz)-1;
	m_ps->Text=Text;
	m_ps->uTextFlags=TextFlags;
	m_ps->PointSize=PointSize;	
	p_Print->ThePrinter.PrintText(m_ps,2);
	p_Print->m_nNextPos=m_ps->m_NextCharPos;
}

////////////////////////////////////////////////////////////////////////////
//	Desc: Draw horizontal lines for esch item on table
//	params:
//	Returns:
///////////////////////////////////////////////////////////////////////////
void CPrintTable::PrintHLines()
{
	int	y,SCol,ECol,Row;
	//	get out if needed
	int	 sz=GetVerticalSpacing();
	if(m_pTable->HLines==FALSE||m_pTable->HeaderOnly==TRUE)
	return;
	//	calc starting column and ending column
	SCol=(int) m_pTable->StartCol;
	ECol=(int) m_pTable->EndCol;                                                     
	//	if we have a header skip over it else start at start pos
	Row=m_pTable->NoHeader==FALSE ? (int) m_pTable->StartRow+ (GetVerticalSpacing(FALSE)*m_pTable->HeaderLines):
										(int) m_pTable->StartRow+sz;

	//	draw a line for each row from one side to the other									
	for(y=0;y < m_pTable->NumRows;++y)
	{
		p_Print->Line(Row,SCol,Row,ECol,m_pTable->LineSize,PEN_SOLID);
		Row+=sz;	
    }
}

////////////////////////////////////////////////////////////////////////////
//	Desc: Draws vertical line seperators for column entries
//	params:
//	Returns:
///////////////////////////////////////////////////////////////////////////
void CPrintTable::PrintVLines()
{   
	int	y,start;
	int	 sz=GetVerticalSpacing();
	//	get out if needed
	if(m_pTable->VLines==FALSE||m_pTable->HeaderOnly==TRUE)
	return;
	//	col to start drawing at
	start=(int) m_pTable->StartCol;
	int BRow,ERow;               
	//	calc the beginning and ending rows to draw lines the correct length
	if(m_pTable->NoHeader==FALSE)
	{
		//	skip header area and calc area under header for x items
		BRow=(int) m_pTable->StartRow+(m_pTable->HeaderLines*(GetVerticalSpacing(FALSE)));
		ERow=(int) m_pTable->StartRow+(m_pTable->HeaderLines*(GetVerticalSpacing(FALSE))+(sz * m_pTable->NumRows));
	}	
	else     
	{   
		//	no header so calc only for x items
		BRow=(int) m_pTable->StartRow;
		ERow=(int) m_pTable->StartRow+( sz*m_pTable->NumRows);
	}	                                                                 
	//	loop through drawing lines on the right margin except the last column
	//	the last column will have a line drawn by the border
	for(y=0;y < m_pTable->NumColumns-1;++y)		
	{                                
		start+=(int) m_pTable->ColDesc[y].Width;
		m_ps->rc.top=BRow;
		m_ps->rc.bottom=ERow;
		m_ps->rc.left=m_ps->rc.right=start;
		p_Print->ThePrinter.DrawLine(m_ps,m_pTable->LineSize);
	}
}
////////////////////////////////////////////////////////////////////////////
//	Desc:	draw the border around the data area of a table. This is not the header
//	but the area that will contain the table data
//	params:
//	Returns:
///////////////////////////////////////////////////////////////////////////
void CPrintTable::PrintBorder()
{                                                           
	int	 sz=GetVerticalSpacing();
	//	check flags and exit if needed
	int ERow;                         
	//	calc the ending row of the table                              
	if(m_pTable->NoHeader==TRUE)
		ERow=(int) m_pTable->StartRow+( sz*m_pTable->NumRows);
	else
		ERow=(int) m_pTable->StartRow+( (m_pTable->HeaderLines*GetVerticalSpacing(FALSE))+(sz * m_pTable->NumRows));

	m_pTable->EndRow=ERow;		

	if(m_pTable->Border==FALSE || m_pTable->HeaderOnly==TRUE)
		return;                                  
	
	
	//	draw a box around the table diminisions	
	p_Print->Box(
	(int)m_pTable->StartRow,
	(int)m_pTable->StartCol,
	(int)ERow,
	(int)m_pTable->EndCol,
	m_pTable->LineSize,
	FILL_NONE,
	PEN_SOLID);
	
}

////////////////////////////////////////////////////////////////////////////
//	Desc: Print the column headers for the table. The member variable HeaderLines
//	determines how many text rows are to be in the header (Default=1)
//	params:
//	Returns:
///////////////////////////////////////////////////////////////////////////

void CPrintTable::PrintHeader()
{   
	int start,y;
	CString s;               
	COLORREF OldColor;                          
	//	check flag and exit if needed
	if(m_pTable->NoHeader==TRUE)
		return;     
	p_Print->SetFontSize(m_pTable->PointSize);		
	int	 sz=GetVerticalSpacing(FALSE);

	//	draw the box the correct size forgetting about the columns right now
	p_Print->Box((int)m_pTable->StartRow,
	              (int)m_pTable->StartCol,
				   (int)(m_pTable->StartRow+(m_pTable->HeaderLines*( sz))),
	              (int)m_pTable->EndCol,
	              m_pTable->LineSize,
	              FILL_NONE,
	              PEN_SOLID);
	//	adjust the width of the last column so it finishes out the header
	//	if the total of the widths is different from the total width of the
	//	table
	start=(int) m_pTable->StartCol;
	for(y=0;y < m_pTable->NumColumns;++y)
		start+=(int) m_pTable->ColDesc[y].Width;
	if(start < m_pTable->EndCol)
		m_pTable->ColDesc[m_pTable->NumColumns-1].Width+=m_pTable->EndCol-start;
	if(start > m_pTable->EndCol)
		m_pTable->ColDesc[m_pTable->NumColumns-1].Width-=start-m_pTable->EndCol;
		
	//	now do the columns drawing a box around each one and centering the text
	//	and applying and shading if needed also set the font size here
	
	start=(int) m_pTable->StartCol;
	for(y=0;y < m_pTable->NumColumns;++y)
	{
		//	the column text
		s=m_pTable->ColDesc[y].Text;
		//	change this to change default behavior for untiltled columns
		if(s.IsEmpty())
			s.Format("Col %d",y+1);
		//	create a print rectangle with the diminsions of the table item	
		m_ps->rc.left=start;
		m_ps->rc.right=(int) (m_ps->rc.left+m_pTable->ColDesc[y].Width);
		m_ps->rc.top=(int) m_pTable->StartRow;
	    m_ps->rc.bottom=(int) m_pTable->StartRow+(sz*m_pTable->HeaderLines);
		m_ps->Text=s;
		m_ps->uTextFlags=TEXT_CENTER|TEXT_BOLD|TEXT_RECT|TEXT_VCENTER;
		//	if the shading is dark set the color to white so it will show up
		if(m_pTable->FillFlag >= FILL_LTGRAY)
			OldColor= p_Print->SetColor(COLOR_WHITE); 		
		m_ps->uFillFlags=m_pTable->FillFlag;
		//	print the text
		p_Print->ThePrinter.PrintText(m_ps,2);
		p_Print->m_nNextPos=m_ps->m_NextCharPos;
		//	restore the old color scheme
		if(m_pTable->FillFlag >= FILL_LTGRAY)
			p_Print->SetColor(OldColor);
		//	move to start of next column	
		start=m_ps->rc.right;
	}	          
}
	
////////////////////////////////////////////////////////////////////////////
//	Desc:	Returns the # of vertical units to seperate rows in the table. The
//	distance is dependant on the selected point size and map mode. The scaling factor
//	of 1.5 was determined by trial and error to look best. If space is ata premium
//	this can be reduced but should be no smaller than 1.25 or the results are UGLY
//	params:
//	Returns: the vertical size for a logical row of print to occupy
///////////////////////////////////////////////////////////////////////////
int CPrintTable::GetVerticalSpacing(BOOL Correct)	
{
	int offset= Correct==TRUE ? m_pTable->NumPrintLines:1;
	if(Correct==TRUE)
	{
		if(p_Print->m_PrtDesc.pDC->GetMapMode()==MM_ANISOTROPIC)                     
			return (int)(m_pTable->PointSize*1.50)* offset;
		else
			return  (int) (((m_pTable->PointSize/72.0)* p_Print->m_PixPerInchY)*1.50)* offset;    
	}
	else
	{
		if(p_Print->m_PrtDesc.pDC->GetMapMode()==MM_ANISOTROPIC)                     
		{
			if(m_pTable->HeaderLines==1)
				return (int)(m_pTable->PointSize*1.5);
			else
				return (int)(m_pTable->PointSize*1.0);
		}
		else
		{		
			if(m_pTable->HeaderLines==1)
				return  (int) (((m_pTable->PointSize/72.0)* p_Print->m_PixPerInchY)*1.5);    
			else
				return  (int) (((m_pTable->PointSize/72.0)* p_Print->m_PixPerInchY)*1.0);    
		}
	}
}

////////////////////////////////////////////////////////////////////////////
//	Desc:
//	params:
//	Returns:
///////////////////////////////////////////////////////////////////////////
CPrintTable::CPrintTable(TABLEHEADER* pTable,CPage* pPrint)
{
	m_ps=&pPrint->m_PrtDesc;;
	m_pTable=pTable;
	p_Print=pPrint;
}

CPrintTable::~CPrintTable()
{

}

////////////////////////////////////////////////////////////////////////////
//	Desc:	Called to actually display the table on the display
//	params:
//	Returns:
///////////////////////////////////////////////////////////////////////////
void CPrintTable::PrintTable()
{   
	p_Print->SaveState();
	//	if autosize calc the size of each column and set the desciptor                             
	if(m_pTable->AutoSize==TRUE)          
	{
		//	(end-start) / number of col = average width of each column
		//	and roun

⌨️ 快捷键说明

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