uses
Windows, SysUtils, WinSpool, Printers;
.....
constdo
CUMENT_NAME = 'Johnson';
// *****************************************************************************
// PrintText: 直接打印。 参数PrinterName为 打印机名,空为使用默认打印机
// *****************************************************************************
function PrintText(PrinterName, Text: PChar;
nCount: integer): Boolean;
var
BytesWritten: Cardinal;
hPrinter: THandle;
Device : array[0..255] of char;
Driver : array[0..255] of char;
Port : array[0..255] of char;
hDeviceMode: THandle;
do
cInfo: TDocInfo1;
begin
Result:= False;
if (PrinterName=nil) or (Length(PrinterName)=0) then
Printer.GetPrinter(Device, Driver, Port, hDeviceMode)
else
StrCopy(Device, PrinterName);
if not OpenPrinter(Device, hPrinter, nil) then
Exit;
do
cInfo.pDocName :=do
CUMENT_NAME;
do
cInfo.pOutputFile := nil;
do
cInfo.pDatatype := 'RAW';
if StartDocPrinter(hPrinter, 1, @DocInfo) = 0 then
begin
ClosePrinter(hPrinter);
Exit;
end;
Result:= WritePrinter(hPrinter, Text, nCount, BytesWritten);
EndDocPrinter(hPrinter);
ClosePrinter(hPrinter);
end;