直接往打印机输送字符,不通过驱动程序,是并口(100分)

  • 主题发起人 主题发起人 delphijin
  • 开始时间 开始时间
D

delphijin

Unregistered / Unconfirmed
GUEST, unregistred user!
各位大侠,能不能实现直接把字符送到打印机,是并口的,多谢!
 
直接字符打印!
VAR
x :TextFile
begin
AssignFile( x, 'LPT1' );
ReWrite( x );
Write( x, '打印测试' );
Write( x, #12 );
//打印机换页
CloseFile( x );
END
 
Procedure DirectPrint(s : String);
var
PTBlock : TPassThroughData;
begin

PTBlock.nLen := Length(s);
StrPCopy(@PTBlock.Data,s);
Escape(printer.handle, PASSTHROUGH,0,@PTBlock,nil);
end;
试一下。
 
没问题,刚刚测试以后贴上来!
var
PrinterHandle:THandle;

uses WinSpool, Printers;
type TDocInfo1=packed record
lpszDocName: PAnsiChar;
lpszOutputFile: PAnsiChar;
lpszDatatype: PAnsiChar;
end;

*设置模块*
var
CTitle:array[0..31] of Char;
CMode:array[0..4] of Char;
do
cInfo:TDocInfo1;
begin
StrPLopy(CTitle, 'My Title');
StrPCopy(CMode, 'RAW');
FillChar(DocInfo, SizeOf(DocInfo), 0);
withdo
cInfodo
begin
lpszDocName:=CTitle;
//设置打印文档标题
lpszOutputFile:=nil;
lpszDatatype:=CMode;
end;
OpenPrinter('Printer Name Here', PrinterHandle, nil);
StartDocPrinter(PrinterHandle, 1, @DocInfo);
StartPagePrinter(PrinterHandle);
*打印模块*
var
Count:DWord;
begin
WritePrinter(PrinterHandle, PChar(printText), Length(printText),
Count);
EndPagePrinter(PrinterHandle);
//结束当页
EndDocPrinter(PrinterHandle);
//结束文档
if PrinterHandle<>0 then

begin
ClosePrinter(PrinterHandle);
//关闭打印设备
PrinterHandle:=0;
//关闭设备通知
end;

 
接受答案了.
 
后退
顶部