|
///////////////////////////////////////////////////////////////////////
//
//PrintInfo.cpp file is part of Code Counter Tool
//Copyright (c) Prashanth Uppunda
//Contact prashum@yahoo.com for any queries
//
//////////////////////////////////////////////////////////////////////
//PrintInfo information
#include "stdafx.h"
#define _PrintInfoSRC
#include "PrintInfo.h"
void PrintInfoRead(void)
{
g_dPrintInfoStdFontSz =7.2;
g_strPrintInfoStdFont =_T("Courier New");
}
int PrintString(LPCTSTR pszString, char cFlag, HDC hdcPrn,int nFieldNo,BOOL bAutoFlag)
{
static CFont MyFont;
static CDC *pdcPrn;
static CFont *pOldFont;
static int nLines=0;
static int iPixelHeight;
static int iPixelWidth;
TEXTMETRIC textMetric;
double dDpiHeight;
CString strFontName;
int iX, iY;
switch(cFlag)
{
case PRINT_NEW_DOC:
pdcPrn=new CDC;
pdcPrn->Attach(hdcPrn);
dDpiHeight=(double)pdcPrn->GetDeviceCaps(LOGPIXELSY);
iPixelHeight=(int)((dDpiHeight/72)*g_dPrintInfoStdFontSz);
LOGFONT logFont;
::ZeroMemory(&logFont, sizeof(LOGFONT));
logFont.lfHeight=iPixelHeight;
logFont.lfCharSet=DEFAULT_CHARSET;
logFont.lfPitchAndFamily=FIXED_PITCH | FF_DONTCARE;
lstrcpy(logFont.lfFaceName, g_strPrintInfoStdFont);
MyFont.CreateFontIndirect(&logFont);
pdcPrn->StartDoc(pszString);
pOldFont=(CFont *)(pdcPrn->SelectObject(&MyFont));
pdcPrn->SetMapMode(MM_TEXT);
nLines=0;
pdcPrn->GetTextMetrics(&textMetric);
iPixelWidth = textMetric.tmAveCharWidth+1;
break;
case PRINT_NEW_PAGE:
pdcPrn->StartPage() ;
pdcPrn->SelectObject(&MyFont);
pdcPrn->SetMapMode(MM_TEXT);
nLines=0;
break;
case PRINT_END_PAGE:
pdcPrn->EndPage();
nLines=0;
break;
case PRINT_STRING:
iX=PRINT_LEFT_MARGIN;
iY=PRINT_TOP_MARGIN;
if(nLines>PRINT_LINES_PER_PAGE)
{
pdcPrn->EndPage();
pdcPrn->StartPage() ;
pdcPrn->SelectObject(&MyFont);
pdcPrn->SetMapMode(MM_TEXT);
nLines=0;
}
iY+=(nLines*iPixelHeight);
if(pszString!=NULL) // Print one line string or else empty line
pdcPrn->TextOut((iX+(nFieldNo*iPixelWidth)), iY, pszString);
if(bAutoFlag == TRUE)
nLines++; // Auto line no. addition
break;
case PRINT_END_DOC:
pdcPrn->EndDoc();
pdcPrn->SelectObject(pOldFont) ;
pdcPrn->Detach() ;
delete pdcPrn;
MyFont.DeleteObject();
nLines=0;
break;
default:
break;
}
return nLines;
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.
A list of licenses authors might use can be found here
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.