Print this window

void TfrmPrintSearch::printTreeView(TTreeView *treeView)
 
{
if (printDC)
{
TTreeNode *currNode;
AnsiString flName;
char printJob[MAXPATH + 12];
char progress[5];
strcpy(printJob, "Treeview: ");
strcat(printJob, Driver->getFile(0));
DOCINFO docInfo; // Needed by StartDoc, so fill it in
docInfo.cbSize = sizeof(DOCINFO);
docInfo.lpszDocName = printJob;
docInfo.lpszOutput = NULL;
docInfo.fwType = NULL;
pageCtr = lineNum = 1;
yPos = 0;
TfrmShowStatus *frmShowStatus = new TfrmShowStatus(this);
frmShowStatus->Caption = "Printing Treeview, please wait...";
frmShowStatus->Show();
StartDoc(printDC, &docInfo); // Tell windows that we are going to start the print job
StartPage(printDC); // Tell windows that we are going to start on a new page
if (bIsHeader) // Do I need to print a header
printHeader();
long i = 0;
while ((iItems->Count) && (!frmShowStatus->bDidCancelSearch))
{
sprintf(progress, "%.2f", ((float)i/MAXCOUNT));
strcpy(printJob, "Rendered: ");
strcat(printJob, progress);
strcat(printJob, "%");
frmShowStatus->setStatDisplay(printJob);
Application->ProcessMessages(); // Process any thing that the user is trying to do
currNode = treeView->Items->Item[i]; // Get the node handle of the node that we are printing
if (!FileExists(currNode->Text)) // Is this a directory or file
flName = currNode->Text;
else
flName = ExtractFileName(currNode->Text);// Just show the file name, not the whole thing
TextOut(printDC, (currNode->Level * charWidth), yPos,
flName.c_str(), strlen(flName.c_str())); // Print it out
yPos += lineHeight; // Advance to the next line
lineNum++; // Increment the line counter
if (bIsFooter && ((lineNum + 1) > linesPerPage))// Printer out a footer is wanted
printFooter();
if (lineNum > linesPerPage) // Time to go for another page, let windows know
{
EndPage(printDC); // Tell the printer that this is the end of the page
StartPage(printDC); // Tell the printer that I need a new page to start
lineNum = 1; // Start the lines all over at one
yPos = 0; // Will need to change this one
pageCtr++;
if (bIsHeader)
printHeader();
} // End the if
i++;
} // End the while
if (bIsFooter)
printFooter();
EndPage(printDC); // Tell windows that we are done printing to that page and force it the last one out
EndDoc(printDC); // Print job is done, inform windows
DeleteDC(printDC); // Get rid of the handle
delete frmShowStatus;
} // End the printDC if
else
Application->MessageBox("Could not get a printer handle", "Print failure", MB_OK);
} // End the printTreeView method