The Prof-UIS grid is designed to be universal and this does not allow the grid to know exactly which data are displayed in it. That is why we did not implement the print feature in it. The printing task in this case is specific to a particular project. But it is not difficult to add MFC’ printing feature similar to that in CView
to any C++ class:
void CYourClass::Print()
{
CDC dc;
CPrintDialog dlg(FALSE);
if( dlg.DoModal() == IDCANCEL )
return;
dc.Attach( dlg.GetPrinterDC() );
dc.m_bPrinting = TRUE;
DOCINFO docInfo;
::memset( &docInfo, 0, sizeof(DOCINFO) );
docInfo.cbSize = sizeof(DOCINFO);
docInfo.lpszDocName = _T("Your title string");
BOOL bOK = dc.StartDoc( &docInfo );
CPrintInfo printInfo;
printInfo.m_rectDraw.SetRect(
0,
0,
dc.GetDeviceCaps(HORZRES),
dc.GetDeviceCaps(VERTRES)
);
OnBeginPrinting( &dc, &printInfo );
UINT nPageIndex = printInfo.GetMinPage();
for( nPageIndex <= printInfo.GetMaxPage() && bOK; nPageIndex++ )
{
dc.StartPage();
printInfo.m_nCurPage = nPageIndex;
OnPrint( &dc, &printInfo );
bOK = ( dc.EndPage() > 0 );
}
OnEndPrinting( &dc, &printInfo );
if( bOK )
dc.EndDoc();
else
dc.AbortDoc();
dc.DeleteDC();
}
void CYourClass::OnBeginPrinting( CDC * pDC, CPrintInfo * printInfo )
{
// TO DO: prepare printing here, cache GDI objects if any
}
void CYourClass::OnPrint( CDC * pDC, CPrintInfo * printInfo )
{
// TO DO: print one page
}
void CYourClass::OnEndPrinting( CDC * pDC, CPrintInfo * printInfo )
{
// TO DO: printing finished, cleanup resources if any
}
The table printing task is very specific in each particular case. Whether table headers are going to be printed on each page? Whether combo box buttons will be printed? We guess there are lots of questions with regard to this task which will have different answers for each particular project.
The cell range selection in the grid control is based on the array with
CRect
objects. Each
CRect
describes an area of selected cells. This explains the meaning of the
nAreaNumber
parameter. To select cells in some range you should add a rectangle that describes the selected range. The
SelectionSet()
methods allow you to perform this task.