unit fWriteRawStringToPrinter;
interface
uses
Windows,WinSpool;
function WriteRawStringToPrinter(
DocName : String;
PrinterName:String;
S:String) : Boolean;
function WriteRawStringToPrinterWithDelay(
DocName : String;
PrinterName:String;
S:String) : Boolean;
// function WriteRawStringToPrinterWithDelayByThread();
implementation
function WriteRawStringToPrinter(
DocName : String;
PrinterName:String;
S:String) : Boolean;
var
Handle: THandle;
N: DWORD;
DocInfo1: TDocInfo1;
begin
Result := True;
if not OpenPrinter(PChar(PrinterName), Handle, nil) then
begin
Result := False;
exit;
end;
with DocInfo1 do begin
pDocName := PChar(DocName);
pOutputFile := nil;
pDataType := 'RAW';
end;
StartDocPrinter(Handle, 1, @DocInfo1);
StartPagePrinter(Handle);
WritePrinter(Handle, PChar(S), Length(S), N);
EndPagePrinter(Handle);
EndDocPrinter(Handle);
ClosePrinter(Handle);
end;
function WriteRawStringToPrinterWithDelay(
DocName : String;
PrinterName:String;
S:String) : Boolean;
var
Handle: THandle;
N: DWORD;
DocInfo1: TDocInfo1;
TmpPtr : String;
i,DelayTime : Integer;
begin
Result := True;
DelayTime := 480;
if not OpenPrinter(PChar(PrinterName), Handle, nil) then
begin
Result := False;
exit;
end;
with DocInfo1 do begin
pDocName := PChar(DocName);
pOutputFile := nil;
pDataType := 'RAW';
end;
TmpPtr := '';
for i := 1 to Length(S) do
begin
TmpPtr := TmpPtr + S;
if S = CHAR($0A) then
begin
OpenPrinter(PChar(PrinterName), Handle, nil);
StartDocPrinter(Handle, 1, @DocInfo1);
StartPagePrinter(Handle);
WritePrinter(Handle, PChar(TmpPtr), Length(TmpPtr), N);
EndPagePrinter(Handle);
EndDocPrinter(Handle);
ClosePrinter(Handle);
sleep(DelayTime);
TmpPtr := '';
end;
end;
if S[Length(S)] <> CHAR($0A) then
begin
OpenPrinter(PChar(PrinterName), Handle, nil);
StartDocPrinter(Handle, 1, @DocInfo1);
StartPagePrinter(Handle);
WritePrinter(Handle, PChar(TmpPtr), Length(TmpPtr), N);
EndPagePrinter(Handle);
EndDocPrinter(Handle);
ClosePrinter(Handle);
sleep(DelayTime);
TmpPtr := '';
end;
end;
end.
给分吧,我自己的程序中的过程