L
LanFairy
Unregistered / Unconfirmed
GUEST, unregistred user!
var
bm: TBitmap;
ADevice, ADriver, APort: Array [0..255] of Char;
DeviceHandle: THandle;
DevMode: PDeviceMode;
begin
//检测是否安装打印机
if NOT CheckIsSetupPrinter then
begin
InfoData(提示安装');
Exit;
end;
//判断打印机是否正在打印
if NOT Printer.Printing then
begin
//得到TDeviceMode结构,并进行设置
Printer.GetPrinter(ADevice, ADriver, APort, DeviceHandle);
if DeviceHandle = 0 then
begin
Printer.PrinterIndex := Printer.PrinterIndex;
Printer.GetPrinter(ADevice, ADriver, APort, DeviceHandle);
end;
if DeviceHandle = 0 then
begin
InfoData('²»ÄܶÔTDeviceMode½á¹¹½øÐгõʼ»¯');
end else
begin
DevMode := GlobalLock(DeviceHandle);
end;
//设置打印结构
with DevMode^do
begin
dmFields := dmFields or DM_COLOR;
dmColor := DMCOLOR_COLOR;
end;
dmFields := dmFields or DM_ORIENTATION;
if SysParam.parPrint.ppOrient = 'ºáÏò´òÓ¡' then
dmOrientation := DMORIENT_LANDSCAPE
else
dmOrientation := DMORIENT_PORTRAIT;
//ÉèÖÃÖ½Õųߴç
dmFields := dmFields or DM_PAPERSIZE;
dmPapersize := 0;
//ÉèÖÃÖ½Õų¤¶È
dmFields := dmFields or DM_PAPERLENGTH;
dmPaperlength := 2970;
//ÉèÖÃÖ½ÕÅ¿í¶È
dmFields:=dmFields or DM_PAPERWIDTH;
dmPaperwidth := 2100;
//ÉèÖôòÓ¡±ÈÀý
dmFields := dmFields or DM_SCALE;
dmSCALE := 200;
//ÉèÖÃÖ½ÕÅÀàÐÍ
dmFields := dmFields or DM_PAPERSIZE;
dmPaperSize := DMPAPER_A4;
end;
//ÖØÐÂË¢ÐÂÒ»ÏÂͼÐÎ
menuReadData.Click;
//½øÐдòÓ¡
if PrintDialog.Execute then
begin
bm := TBitmap.Create;
try
Image1.Bitmap.SaveToFile('tmp.bmp');
bm.LoadFromFile('tmp.bmp');
bm.HandleType := bmDIB;
//Printer.begin
Doc;
PrintStrectBitmap(bm);
//Printer.Canvas.StretchDraw(bm.Canvas.ClipRect, bm);
//Printer.EndDoc;
finally
bm.Free;
DeleteFile('tmp.bmp');
end;
end;
//È¡ÏûËø¶¨
if NOT DeviceHandle = 0 then
GlobalUnLock(DeviceHandle);
end else
begin
InfoData('ϵͳÕýÔÚ´òÓ¡ÇëÉÔºó£¡');
end;
end;
bm: TBitmap;
ADevice, ADriver, APort: Array [0..255] of Char;
DeviceHandle: THandle;
DevMode: PDeviceMode;
begin
//检测是否安装打印机
if NOT CheckIsSetupPrinter then
begin
InfoData(提示安装');
Exit;
end;
//判断打印机是否正在打印
if NOT Printer.Printing then
begin
//得到TDeviceMode结构,并进行设置
Printer.GetPrinter(ADevice, ADriver, APort, DeviceHandle);
if DeviceHandle = 0 then
begin
Printer.PrinterIndex := Printer.PrinterIndex;
Printer.GetPrinter(ADevice, ADriver, APort, DeviceHandle);
end;
if DeviceHandle = 0 then
begin
InfoData('²»ÄܶÔTDeviceMode½á¹¹½øÐгõʼ»¯');
end else
begin
DevMode := GlobalLock(DeviceHandle);
end;
//设置打印结构
with DevMode^do
begin
dmFields := dmFields or DM_COLOR;
dmColor := DMCOLOR_COLOR;
end;
dmFields := dmFields or DM_ORIENTATION;
if SysParam.parPrint.ppOrient = 'ºáÏò´òÓ¡' then
dmOrientation := DMORIENT_LANDSCAPE
else
dmOrientation := DMORIENT_PORTRAIT;
//ÉèÖÃÖ½Õųߴç
dmFields := dmFields or DM_PAPERSIZE;
dmPapersize := 0;
//ÉèÖÃÖ½Õų¤¶È
dmFields := dmFields or DM_PAPERLENGTH;
dmPaperlength := 2970;
//ÉèÖÃÖ½ÕÅ¿í¶È
dmFields:=dmFields or DM_PAPERWIDTH;
dmPaperwidth := 2100;
//ÉèÖôòÓ¡±ÈÀý
dmFields := dmFields or DM_SCALE;
dmSCALE := 200;
//ÉèÖÃÖ½ÕÅÀàÐÍ
dmFields := dmFields or DM_PAPERSIZE;
dmPaperSize := DMPAPER_A4;
end;
//ÖØÐÂË¢ÐÂÒ»ÏÂͼÐÎ
menuReadData.Click;
//½øÐдòÓ¡
if PrintDialog.Execute then
begin
bm := TBitmap.Create;
try
Image1.Bitmap.SaveToFile('tmp.bmp');
bm.LoadFromFile('tmp.bmp');
bm.HandleType := bmDIB;
//Printer.begin
Doc;
PrintStrectBitmap(bm);
//Printer.Canvas.StretchDraw(bm.Canvas.ClipRect, bm);
//Printer.EndDoc;
finally
bm.Free;
DeleteFile('tmp.bmp');
end;
end;
//È¡ÏûËø¶¨
if NOT DeviceHandle = 0 then
GlobalUnLock(DeviceHandle);
end else
begin
InfoData('ϵͳÕýÔÚ´òÓ¡ÇëÉÔºó£¡');
end;
end;