C++
void __fastcall TMainInputF::PrintPreviewButtonClick(TObject
*Sender)
{
TList *ChildPrint;
int Count,i,Count2;
bool done =
false,Pass = true,done2;
TPrinter *Prntr = Printer();
TRect r;
StartingX = Prntr->PageWidth*0.095;
StartingY = 750;
Count =
MedPageControl->PageCount;
if (Count == 0)
{
ShowMessage("No pages to
print");
return;
}
CleanseSetup();
CleanseParentPrint();
GenerateSetup();
Form2->ParentPrint
= new TList();
//------
TMetafile *pMetafile = new
TMetafile;
pMetafile->Enhanced = true;
pCanvas = new
TMetafileCanvas(pMetafile, Prntr->Handle);
pMetafile->Width =
Prntr->PageWidth;
pMetafile->Height =
Prntr->PageHeight;
pCanvas->Font->PixelsPerInch =
GetDeviceCaps(Prntr->Handle, LOGPIXELSY);
pCanvas->Font->Name =
"Arial";
pCanvas->Font->Size = 8;
TextLineSpace =
pCanvas->TextHeight("Hy");
DrawFirstPage();
delete
pCanvas;
ChildPrint = new
TList();
ChildPrint->Add(pMetafile);
Form2->ParentPrint->Add(ChildPrint);
Form2->pMetafile
= (TMetafile *)ChildPrint->Items[0];
//------
for (i = 0 ;
i<=Count ; i++)
{
TMetafile *pMetafile = new TMetafile;
pMetafile->Enhanced =
true;
pCanvas = new TMetafileCanvas(pMetafile,
Prntr->Handle);
pMetafile->Width =
Prntr->PageWidth;
pMetafile->Height =
Prntr->PageHeight;
pCanvas->Font->PixelsPerInch =
GetDeviceCaps(Prntr->Handle, LOGPIXELSY); pCanvas->Font->Name =
"Arial";
pCanvas->Font->Size = 8;
TextLineSpace =
pCanvas->TextHeight("Hy");
SetupPrintGrid(i);
CalcStartingX();
GenerateMetafiles(i);
DrawGrid();
AddAditionalPrint(i);
delete
pCanvas;
ChildPrint = new
TList();
ChildPrint->Add(pMetafile);
Form2->ParentPrint->Add(ChildPrint);
}
Form2->ShowModal();
}
About
the code: This is intended to demonstrate my familiarity with TCanvas,
TMetafiles and object orientation. This is basically the print preview control
code for a reporting system, it uses complex abstract data structures.
TTestBenchInterface::TTestBenchInterface(AnsiString IPAddress, int IPPort)
{
RxTimeout = 1000;
queue_init(&RxQ);
MySocket = new TClientSocket(NULL);
MySocket->Host = IPAddress;
MySocket->Port = IPPort;
MySocket->OnRead = SocketRead;
}
char TTestBenchInterface::ReceiveChar(int &Timeout)
{
while (true)
{
if (queue_status(&RxQ))
{
return (char)queue_extract(&RxQ);
}
else
{
Application->ProcessMessages();
Sleep(10);
Timeout -= 10;
if (Timeout < 0)
{
}
}
}
}
About the code: This code is part of the client side of a Socket connection which employed an Engineering protocol. Using this server object I was able efficiently move data between machines.
Copyright © 2000 - Hans Krige
All Rights Reserved
Webmaster: Hans -
hanskrige@hotmail.com