unit bb;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, QuickRpt, QRCtrls, jpeg,printers,winspool,StdCtrls,strutils;
type
TForm5 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form5: TForm5;
implementation
uses Unit1;
var
PrnHwnd:THandle;
// chs0=$1B,$26,$03,$57,0;//中文(普通)
// chs1=$1B,$26,$03,$57,1;//中文(四倍)
// eng=$1C,$2E,$1C,$57,0;//英文(普通)
// eng=$1C,$2E,$1C,$57,1;//英文(四倍)
// cut=$1B,$69;//切纸
// hl=$0A;//换行
// cr=$0D];//回车
// sp=$1B,$21,2;//字间间隔
// lsp=$1B,$32;//行间间隔
// hom=$1B,$3C;//行首
{$R *.dfm}
procedure OpenLptPrn(hp:string);
begin
PRNHwnd:=CreateFile(Pchar(hp), GENERIC_READ or GENERIC_WRITE,0,nil, OPEN_EXISTING,FILE_FLAG_OVERLAPPED,0);
if PRNHwnd=INVALID_HANDLE_VALUE then
Exception.Create('无效并行口');
end;
procedure delay(n:integer);//延时
var t:Tdatetime;
begin
t:=time;
repeat
//
until time>=t+n/24/60/60/1000;
end;
procedure SendToPrinter(SendBuf:array of byte);overload
var
tem:cardinal;
begin
WriteFile(PRNHwnd,SendBuf,High(SendBuf)+1,tem,nil);
end;
procedure SendToPrinter0(SendBuf:string);overload
var
i,a:integer;
begin
a:=0;
for i:=1 to Length(SendBuf)do
begin
if a=0 then
begin
if (ord(SendBuf)>0)and(ord(SendBuf)<128) then
begin
SendToPrinter([$1C,$2E,ord(SendBuf)]);
end
else
begin
SendToPrinter([$1C,$26,$1C,$57,1,ord(SendBuf),ord(SendBuf[i+1])]);
a:=1;
end;
end
else
begin
a:=0;
end;
end;
SendToPrinter([$1C,$2E,ord(' '),$0A]);
end;
procedure TForm1.Button1Click(Sender: TObject);
//点击就打印
var i,Linesl,Linedel:integer;
begin
Form1.ADOTable3.First;
OpenLptPrn('LPT1:');
SendToPrinter0(' 人事管理系统 ');
SendToPrinter0('-----------------------------');
SendToPrinter0(' 日期:'+datetostr(date())+gwb1);
SendToPrinter0(' 时间:'+timetostr(now())+' Tel:66200871');
For i:=1 to 8do
sendtoprinter([$0A]);
//8行回车
fileclose(PRNHwnd);
end;
end.