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 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124
| procedure
ScreenShot(activeWindow: bool; destBitmap: TBitmap);
var
w, h: integer;
DC: HDC;
hWin: Cardinal;
r: TRect;
begin
if activeWindow then
begin
hWin := GetForegroundWindow;
dc := GetWindowDC(hWin);
GetWindowRect(hWin, r);
w := r.Right - r.Left;
h := r.Bottom - r.Top;
end
else
begin
hWin := GetDesktopWindow;
dc := GetDC(hWin);
w := GetDeviceCaps(DC, HORZRES);
h := GetDeviceCaps(DC, VERTRES);
end;
try
destBitmap.Width := w;
destBitmap.Height := h;
BitBlt(destBitmap.Canvas.Handle,
0,
0,
destBitmap.Width,
destBitmap.Height,
DC,
0,
0,
SRCCOPY);
finally
ReleaseDC(hWin, DC);
end;
end;
{------------------------------------------------------------------------------}
procedure Tform.ImpressionEcran;
var
DesktopBitmap : TBitmap;
Info: PBitmapInfo;
InfoSize: DWord;
Image: Pointer;
ImageSize: DWORD;
Bits: HBITMAP;
DIBWidth, DIBHeight: Longint;
PrintWidth, PrintHeight: Longint;
LargPrn: longint;
HautPrn: longint;
Torientation : TPrinterOrientation;
begin
PrintScale := poPrintToFit;
Torientation := Printer.Orientation ;
Printer.Orientation := poLandscape;
Printer.BeginDoc;
DesktopBitmap := TBitmap.Create;
try
ScreenShot(true,DesktopBitmap);
DesktopBitmap.Canvas.TextOut(5,10,'fait le : '+formatdatetime('yyyy/mm/dd',now));
Canvas.Lock;
try
with Printer, Canvas do
begin
Bits := DesktopBitmap.Handle;
GetDIBSizes(Bits, InfoSize, ImageSize);
Info := AllocMem(InfoSize);
try
Image := AllocMem(ImageSize);
try
GetDIB(Bits, 0, Info^, Image^);
with Info^.bmiHeader do
begin
DIBWidth := biWidth;
DIBHeight := biHeight;
end;
case PrintScale of
poProportional:
begin
LargPrn := GetDeviceCaps(Printer.Handle, LOGPIXELSX);
LargPrn := (LargPrn * 90) div 100;
PrintWidth := MulDiv(DIBWidth, LargPrn, PixelsPerInch);
hautPrn := GetDeviceCaps(Printer.Handle, LOGPIXELSY);
hautPrn := (hautPrn * 90) div 100;
PrintHeight := MulDiv(DIBHeight, HautPrn, PixelsPerInch);
end;
poPrintToFit:
begin
PrintWidth := MulDiv(DIBWidth, PageHeight, DIBHeight);
if PrintWidth < PageWidth then
PrintHeight := PageHeight
else
begin
PrintWidth := PageWidth;
PrintHeight := MulDiv(DIBHeight, PageWidth, DIBWidth);
end;
end;
else
PrintWidth := DIBWidth;
PrintHeight := DIBHeight;
end;
StretchDIBits(Canvas.Handle, 0, 0, PrintWidth, PrintHeight, 0, 0,
DIBWidth, DIBHeight, Image, Info^, DIB_RGB_COLORS, SRCCOPY);
finally
FreeMem(Image, ImageSize);
end;
finally
FreeMem(Info, InfoSize);
end;
end;
finally
Canvas.Unlock;
DesktopBitmap.Free;
end;
finally
Printer.EndDoc;
Printer.Orientation := Torientation;
end;
end; |
Partager