1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
|
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "Unit1.h"
#include "Printers.hpp"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
TRect R;
String S;
int P;
P = GetDeviceCaps(Printer()->Handle, LOGPIXELSX);
TMetafile *pMetafile;
TMetafileCanvas *pCanvas;
TList *LPages = new TList();
for(int I = 0; I <=2; I++)
{
pMetafile = new TMetafile;
pMetafile->Width = Printer()->PageWidth;
pMetafile->Height = Printer()->PageHeight;
LPages->Add(pMetafile);
}
// if(pMetafile){ delete pMetafile; pMetafile=0; }
pCanvas = new TMetafileCanvas((TMetafile *)LPages->Items[0], 0);
// ecriture d'une premiere chaine
pCanvas->Font->PixelsPerInch = P;
pCanvas->Font->Size = 18;
pCanvas->TextOut(10, 10, "Vous etes sur la page 1");
// ecriture d'une seconde chaine
pCanvas->Font->Size = 22;
S = "Ce texte est centre sur la page";
R = Rect(0, (Printer()->PageHeight) / 2, Printer()->PageWidth, Printer()->PageHeight);
DrawText(pCanvas->Handle, S.c_str(),S.Length(), &R, DT_CENTER || DT_VCENTER || DT_SINGLELINE);
delete pCanvas;
TMetafileCanvas *pCanvas1 = new TMetafileCanvas((TMetafile *)LPages->Items[1], 0);
InflateRect(&R, -300, -300);
pCanvas1->Ellipse(R);
pCanvas1->Pen->Color = clBlue;
InflateRect(&R, -200, -200);
pCanvas1->Ellipse(R);
pCanvas1->Pen->Color = clGreen;
InflateRect(&R, -200, -200);
pCanvas1->Ellipse(R);
pCanvas1->Pen->Color = clRed;
InflateRect(&R, -200, -200);
pCanvas1->Ellipse(R);
InflateRect(&R, -200, -200);
pCanvas1->Rectangle(R);
delete pCanvas1;
HDC I;
I = GetDC(0); // Obtention d'un handle de device context sur l'écran
TMetafileCanvas *pCanvas2 = new TMetafileCanvas((TMetafile *)LPages->Items[2], 0);
StretchBlt(pCanvas2->Handle, 0, 0,
Printer()->PageWidth, Printer()->PageHeight,
I, 0, 0,
Screen->Width, Screen->Height,
SRCCOPY);
ReleaseDC(Handle, I); // ne pas oublier de relâcher le HDC
PaintBox1->Tag = 0;
delete pCanvas2;
Printer()->BeginDoc();
Printer()->Canvas->Draw(0, 0, (TMetafile *)LPages->Items[0]);
Printer()->NewPage();
Printer()->Canvas->Draw(0, 0, (TMetafile *)LPages->Items[1]);
// Printer()->NewPage();
// Printer()->Canvas->Draw(0, 0, (TMetafile *)LPages->Items[2]);
Printer()->EndDoc();
}
//--------------------------------------------------------------------------- |
Partager