C++ Standards, Extensions, and Interop


How to Calculate Second Page or more pages or Print Second page or more pages in MFC Print?


Hi All
i want to print datas in Table format.so i searched Net and get the following site:
http://www.ucancode.net/Visual-C-Print-Class-Library-tables.htm
Source code for Table format Page. i used these code in my project and i have issue if i using those code. suppose i want to print 80 rows of records.then default its shows 50 records only and it wont goes to next page that is from 51 to 80 .i cant find
out how to assign those datas in sencond page. and i dont know the technique how to set the pages if the data is more than one page how to calculate the required page no.
if any body well in this context please download the link and use it how to calculate the subsequent pages depending on the datas or
please give me a explanation how to print more than one page data print in mfc with example please....
Thanks in advance for explanation.
please give me a explanation how to print more than one page data print in mfc with example please....
CView::OnPrint() expects you to render only the portion of the document that corresponds to the page currently being printed. Which page to print is specified by the CPrintInfo::m_nCurPage.
In a complicated multipage printout the challenge is to know where page m_nCurPage begins. One strategy is to start every call to OnPrint() from the top of the printout but only render what is on m_nCurPage. The code below is intended as a minimal illustration
of this strategy. The code shows what is added to the code created by Application Wizard.
#define LEFT_MARGIN 30
#define RIGHT_MARGIN 10
#define TOP_MARGIN 33
#define BOTTOM_MARGIN 40
#define HEADER_MARGIN 10
class CYourView : public CView
{
UINT m_nCurPage;
CFont m_font;
virtual void OnPrint(CDC* pDC, CPrintInfo* pInfo);
virtual void OnPrepareDC(CDC* pDC, CPrintInfo* pInfo = NULL) {};
int TopMargin( CDC* pDC, CPrintInfo* pInfo );
void SetFont(CDC* pDC, int nPointSize);
};
int mmxToPixel( CDC* pDC, int mm )
{
return MulDiv(pDC->GetDeviceCaps(HORZRES), mm, pDC->GetDeviceCaps(HORZSIZE));
}
int mmyToPixel( CDC* pDC, int mm )
{
return MulDiv(pDC->GetDeviceCaps(VERTRES), mm, pDC->GetDeviceCaps(VERTSIZE));
}
void CYourView::SetFont(CDC* pDC, int nPointSize)
{
pDC->SelectStockObject(DEVICE_DEFAULT_FONT);
m_font.DeleteObject();
m_font.CreatePointFont(nPointSize, _T("Arial"), pDC);
pDC->SelectObject( &m_font );
}
void CYourView::OnPrint(CDC* pDC, CPrintInfo* pInfo)
{
m_nCurPage = 0;
int y = -1;
CString cSize;
TEXTMETRIC tm;
for ( int nPointSize = 80; nPointSize < 600; nPointSize += 10 )
{
if ( y < 0 || y >= pDC->GetDeviceCaps(PHYSICALHEIGHT) -
mmyToPixel( pDC, TOP_MARGIN + BOTTOM_MARGIN ) )
{
y = TopMargin( pDC, pInfo );
if ( m_nCurPage > pInfo->m_nCurPage)
return;
}
cSize.Format(_T("Pointsize: %d"), nPointSize/10 );
SetFont( pDC, nPointSize);
if ( m_nCurPage == pInfo->m_nCurPage )
pDC->TextOut(0, y, cSize);
pDC->GetTextMetrics(&tm);
y += tm.tmHeight;
}
pInfo->SetMaxPage(m_nCurPage);
}
int CYourView::TopMargin( CDC* pDC, CPrintInfo* pInfo )
{
m_nCurPage++;
pDC->SetWindowOrg( mmxToPixel( pDC, -LEFT_MARGIN) + pDC->GetDeviceCaps(PHYSICALOFFSETX),
- (mmyToPixel(pDC, HEADER_MARGIN) - pDC->GetDeviceCaps(PHYSICALOFFSETY)) );
if ( m_nCurPage == pInfo->m_nCurPage )
{
SetFont( pDC, 120);
CString cPageNo;
cPageNo.Format(_T("Page %d"), pInfo->m_nCurPage);
UINT nOldAlign = pDC->SetTextAlign( TA_RIGHT );
pDC->TextOut( pDC->GetDeviceCaps(PHYSICALWIDTH) -
mmxToPixel(pDC, LEFT_MARGIN + RIGHT_MARGIN), 0, cPageNo );
pDC->SetTextAlign( nOldAlign );
}
pDC->SetWindowOrg( mmxToPixel(pDC, -LEFT_MARGIN) + pDC->GetDeviceCaps(PHYSICALOFFSETX),
-(mmyToPixel(pDC, TOP_MARGIN) - pDC->GetDeviceCaps(PHYSICALOFFSETY)) );
return 0;
}
Hi hgn
Thanks for your great help i used your code i changed as my requirement and still now i have a problem to see second page i dont know why its not generated i tried to debug also its hard to find out why not show
or generate here i attached my code so please go through my code and find out the error.thanks a lot
my code snippet is:
///////////////////Balaji 17 09 10 start
BOOL CSoftwareView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CSoftwareView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CSoftwareView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
int mmxToPixel( CDC* pDC, int mm )
{
return MulDiv(pDC->GetDeviceCaps(HORZRES), mm, pDC->GetDeviceCaps(HORZSIZE));
}
int mmyToPixel( CDC* pDC, int mm )
{
return MulDiv(pDC->GetDeviceCaps(VERTRES), mm, pDC->GetDeviceCaps(VERTSIZE));
}
void CSoftwareView::SetFont(CDC* pDC, int nPointSize)
{
pDC->SelectStockObject(DEVICE_DEFAULT_FONT);
m_font.DeleteObject();
m_font.CreatePointFont(nPointSize, _T("Arial"), pDC);
pDC->SelectObject( &m_font );
}
void CSoftwareView::OnPrint(CDC* pDC, CPrintInfo* pInfo)
{
m_nCurPage = 0;
int nPointSize=100;
int y = -1;
int nNoofRecordsToPrint=10;
CString cSize;
TEXTMETRIC tm;
REPORTINFO Report;
CString scount,act,dev,comment;
CString Sp0=" ";
CString Sp1="
";
CString Sp2="
";
CString Sp3=" ";
SetFont( pDC, nPointSize);
////////////// Balaji 18 09 10 Start
pDC->Rectangle(50,50,2500,3250);
pDC->MoveTo(50,120); pDC->LineTo(2500,120);
pDC->TextOut(130,60,"Reference");
pDC->MoveTo(400,50); pDC->LineTo(400,3250);
pDC->TextOut(480,60,"Nominal");
pDC->MoveTo(750,50); pDC->LineTo(750,3250);
pDC->TextOut(830,60,"Actual");
pDC->MoveTo(1100,50);pDC->LineTo(1100,3250);
pDC->TextOut(1200,60,"Tol-");
pDC->MoveTo(1450,50);pDC->LineTo(1450,3250);
pDC->TextOut(1550,60,"Tol+");
pDC->MoveTo(1800,50);pDC->LineTo(1800,3250);
pDC->TextOut(1900,60,"Dev.");
pDC->MoveTo(2150,50);pDC->LineTo(2150,3250);
pDC->TextOut(2230,60,"Trend");
////////////// Balaji 18 09 10 End
for ( int nCurrentRecord = 1; nCurrentRecord <=nNoofRecordsToPrint; nCurrentRecord++ )
{
if ( y < 0 || y >= pDC->GetDeviceCaps(PHYSICALHEIGHT) -
mmyToPixel( pDC, TOP_MARGIN + BOTTOM_MARGIN ) )
{
y = TopMargin( pDC, pInfo );
if ( m_nCurPage > pInfo->m_nCurPage)
return;
}
if(y<=2300)
{
if ( m_nCurPage == pInfo->m_nCurPage )
{
readFromDisk (0,nCurrentRecord,&Report);
for(int i=0;i<6;i++)
{
if (i==0)
{
y+=5;
pDC->TextOut(-250, y, Report.fName[0]);
comment=Report.Comments;
comment=Sp0+comment+Sp1+Sp2+Sp3;
pDC->TextOut(40, y, comment);
y += tm.tmHeight;
}
pDC->TextOut(-250, y, Report.sym[i]);
act.Format("%f",Report.act[i]);
dev.Format("%f",Report.dev[i]);
pDC->TextOut(800, y, act);
pDC->TextOut(1000, y, Report.nom[i]);
pDC->TextOut(1300, y, Report.uTol[i]);
pDC->TextOut(1500, y, Report.lTol[i]);
pDC->TextOut(1900, y, dev);
pDC->GetTextMetrics(&tm);
y += tm.tmHeight;
} //for i;
}//if ( m_nCurPage == pInfo->m_nCurPage )
y+=30;
pDC->MoveTo(-300,y);
pDC->LineTo(2146,y);
}// if (y<=2300)
else
{
y=0;
m_nCurPage++;
pInfo->SetMaxPage(m_nCurPage);
}//if (y<=2300)
}// for nCurrentRecord
pInfo->SetMaxPage(m_nCurPage);
}
int CSoftwareView::TopMargin( CDC* pDC, CPrintInfo* pInfo )//print new page no at the (2078,0) location
{
m_nCurPage++;
pDC->SetWindowOrg( mmxToPixel( pDC, -LEFT_MARGIN) + pDC->GetDeviceCaps(PHYSICALOFFSETX),
- (mmyToPixel(pDC, HEADER_MARGIN) - pDC->GetDeviceCaps(PHYSICALOFFSETY)) );
if ( m_nCurPage == pInfo->m_nCurPage )
{
SetFont( pDC, 100);
CString cPageNo;
cPageNo.Format(_T("Page %d"), pInfo->m_nCurPage);
UINT nOldAlign = pDC->SetTextAlign( TA_RIGHT );
pDC->TextOut( pDC->GetDeviceCaps(PHYSICALWIDTH) -
mmxToPixel(pDC, LEFT_MARGIN + RIGHT_MARGIN), 0, cPageNo );
pDC->SetTextAlign( nOldAlign );
}
pDC->SetWindowOrg( mmxToPixel(pDC, -LEFT_MARGIN) + pDC->GetDeviceCaps(PHYSICALOFFSETX),
-(mmyToPixel(pDC, TOP_MARGIN) - pDC->GetDeviceCaps(PHYSICALOFFSETY)) );
return 0;
}
Here it print record upto 7th afterwards 8 to 10 its go to second page.i just give the default record size to print function it may change at run time.please clarify the error
Thanks in advance for help
All increments of y must be located outside the selection “if ( m_nCurPage == pInfo->m_nCurPage )”. Otherwise page 2 will not start where page 1 ends. All actual rendering on the other hand, must take place
inside the selection.
Sorry i cant get in please explore briefly where is the error please locate the line and give me a solution please...

Related Links

ActiveX Deployment: VC 2005 Redistributable Issues
LNK2001 ?
AFX_MANAGE_STATE() macro disturbs the startup position of the ATL dialog
how to change the "Language support for non-Unicode language" in VC
STL vector sizing question
Using Direct2D how would i fill a font with a gradient or radial brush?
Beginner c++ question--Bitwise enumerations
int i = 2; Is this the Assingment Operator here ?
How do you define a template class's constructor outside the class
MSVCRTD.lib(crtexew.obj) : error LNK2019: unresolved external symbol _WinMain#16 referenced in function ___tmainCRTStartup
How to use another variable from another Form in VisualC++
Accessing a member through a pointer
How to copy one char* array into another one?
definition of dllimport static data member not allowed
LockFile problem
mspdbsrv.exe consuming over 1.4GB

Categories

MSDN
SharePoint
Architecture
Commerce Server
Windows Server
Bing
Bing Maps
Project Server
Exchange Server
Silverlight
Microsoft Azure
Archived Forums C-D
Archived Forums T-U
Microsoft R
Cortana
Visual Studio Setup an...
Tools for Apache Cordova
Store Engagement Frame...
Peer-to-Peer Networkin...
Windows Hardware Testi...
Developing Apps for Of...
General Office Develop...
Excel for Developers
Developing Apps for Sh...
SharePoint 2013 - Search
SharePoint Legacy Vers...
Azure SQL Database
Azure BizTalk Services
Azure Marketplace
Azure Key Vault
Azure Stream Analytics
Azure Security Center
Azure Functions
.NET Framework Setup a...
Team Foundation Server...
The Architect Role
HealthVault Developer
Microsoft Translator H...
Small Basic
Transact-SQL
SQL Server High Availa...
SQL Server Notificatio...
SQL Server Express
Microsoft StreamInsight
Standard 2009: Embedde...
Standard 2009: Misc
Standard 7: Tools
SQL Server 2012 Spatia...
SQL Server 2012 Report...
Windows Server 2008 Ap...
Windows Live General: ...
CRM Deployment
Script Junkie Discussion
The Samsung Windows De...
Office Protocols
Project Server General...
Project Customization ...
Microsoft Unified Comm...
Microsoft Lync Persist...
Hosting and Streaming ...
Report a Silverlight Bug
Managed Extensibility ...
Expression Web and Sup...
Retired SharePoint Ent...
Retired SharePoint Acc...
Retired SharePoint Col...
.NET Framework 4: Wind...
Casablanca
Crystal Reports for Vi...
Direct3D 10
Chart Controls for .NE...
Game Technologies: Aud...
Game Technologies: Dir...
Office Live Small Busi...
Popfly Bugs and Sugges...
Silverlight (formerly ...
SQL Server 2014 Self-S...
SQL Server 2014 Report...
TFS Deployment to Azure
Visual Basic 2008 (Pre...
Visual Basic Express 2...
Visual Basic for Appli...
Visual C# Express 2008...
Visual C# Express Edition
Visual C++ Express 200...
Visual J# General (Ret...
Web Development in Vis...
Windows CardSpace ('In...
Kinect for Windows v1 SDK
Azure N-Series Virtual...
Skype Web SDK

Resources

Encrypt Message



code
soft
python
ios
c
html
jquery
cloud
mobile