Z
zlc_168
Unregistered / Unconfirmed
GUEST, unregistred user!
编写了一组件,编写过程如下
1、选择ActiveX Library创建ActiveX库.
2、再往新建的库中加入一个Automation Object
主要是用作b/s模式下客户端精确控制打印,编译后注册,但是在html中调用时却出
错,无任何响应,源码如下:
unit bs_print;
{$WARN SYMBOL_PLATFORM OFF}
interface
uses
ComObj, ActiveX, bs_print_TLB, StdVcl,printers,windows;
const
max_len=80;
max_path=80;
type
TprtTest3 = class(TAutoObject, IprtTest3)
protected
function prtCustomPage(PageWidth, PageHeight, Orientation: SYSINT): SYSINT;
safecall;
procedure prtDrawLine(x1, y1, x2, y2, LineWidth: SYSINT); safecall;
procedure setFont(FontName: PChar; FontSize: SYSINT); safecall;
procedure prtTextRect(VAlign, HAlign, RectLeft, RectTop, RectRight,
RectBottom: SYSINT; prtText: PChar); safecall;
{ Protected declarations }
end;
implementation
uses ComServ;
function getx():sysint;
begin
result:=trunc(getdevicecaps(printer.Handle,LOGPIXELSX)/25.38);
end;
function gety():sysint;
begin
result:=trunc(getdevicecaps(printer.Handle,LOGPIXELSY)/25.38);
end;
function TprtTest3.prtCustomPage(PageWidth, PageHeight,
Orientation: SYSINT): SYSINT;
var
Device:Array [0..max_len-1] of Char;
Driver:Array [0..(max_path-1)] of Char;
Port:Array [0..32] of Char;
dmode:thandle;
pdmodedevmode;
begin
try
result:=0;
printer.GetPrinter(device,driver,port,dmode);
if dmode<>0 then
begin
pdmode:=globallock(dmode);
if pdmode<>nil then
begin
pdmode^.dmFields:=pdmode^.dmFields or DM_PAPERSIZE or DM_ORIENTATION;
pDMode^.dmPaperSize:=DMPAPER_USER;
pdmode^.dmPaperWidth:=PageWidth;
pdmode^.dmPaperLength:=PageHeight;
pdmode^.dmOrientation:=Orientation;
end;
printer.SetPrinter(device,driver,port,dmode);
globalunlock(dmode);
end;
except
result:=0;
end;
end;
procedure TprtTest3.prtDrawLine(x1, y1, x2, y2, LineWidth: SYSINT);
var
x,y:integer;
begin
x:=getx;
y:=gety;
x1:=x1*x;
y1:=y1*y;
x2:=x2*x;
y2:=y2*y;
printer.Canvas.MoveTo(x1,y1);
printer.Canvas.LineTo(x2,y2);
end;
procedure TprtTest3.setFont(FontName: PChar; FontSize: SYSINT);
begin
end;
procedure TprtTest3.prtTextRect(VAlign, HAlign, RectLeft, RectTop,
RectRight, RectBottom: SYSINT; prtText: PChar);
var
x,y:integer;
begin
x:=getx;
y:=gety;
rectleft:=rectleft*x;
recttop:=recttop*y;
rectright:=rectright*x;
rectbottom:=rectbottom*y;
printer.Canvas.TextOut(rectleft,recttop,prttext);
end;
initialization
TAutoObjectFactory.Create(ComServer, TprtTest3, Class_prtTest3,
ciMultiInstance, tmApartment);
end.
在html调用如下:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<meta name="GENERATOR" content="Microsoft FrontPage 4.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<SCRIPT LANGUAGE="VBScript">
Sub TestPrtObject
Dim prtObject
Set prtObject=CreateObject("bs_print.prtTest3")
prtObject.prtCustomPage 1000,1000,1
prtObject.prtDrawLine 2,2,1000,1000,1
prtObject.prtDrawLine 500,700,1000,1000,1
prtObject.prtTextRect 2,2,0,0,1000,500,"WEB应用程序打印测试"
document.exam.T1.value="fwergearh"
Set prtObject=Nothing
End Sub
</SCRIPT>
<title>New Page 1</title>
</head>
<body>
这是一个ActiveX示例程序!
<form method="POST" name="exam" action="--WEBBOT-SELF--">
<p><input type="text" name="T1" size="20"></p>
</form>
<p><input type="button" value="打印" name="B3" onclick="TestPrtObject"></p>
</body>
</html>
运行后提示网页上有错误,请各位大侠给看看。
1、选择ActiveX Library创建ActiveX库.
2、再往新建的库中加入一个Automation Object
主要是用作b/s模式下客户端精确控制打印,编译后注册,但是在html中调用时却出
错,无任何响应,源码如下:
unit bs_print;
{$WARN SYMBOL_PLATFORM OFF}
interface
uses
ComObj, ActiveX, bs_print_TLB, StdVcl,printers,windows;
const
max_len=80;
max_path=80;
type
TprtTest3 = class(TAutoObject, IprtTest3)
protected
function prtCustomPage(PageWidth, PageHeight, Orientation: SYSINT): SYSINT;
safecall;
procedure prtDrawLine(x1, y1, x2, y2, LineWidth: SYSINT); safecall;
procedure setFont(FontName: PChar; FontSize: SYSINT); safecall;
procedure prtTextRect(VAlign, HAlign, RectLeft, RectTop, RectRight,
RectBottom: SYSINT; prtText: PChar); safecall;
{ Protected declarations }
end;
implementation
uses ComServ;
function getx():sysint;
begin
result:=trunc(getdevicecaps(printer.Handle,LOGPIXELSX)/25.38);
end;
function gety():sysint;
begin
result:=trunc(getdevicecaps(printer.Handle,LOGPIXELSY)/25.38);
end;
function TprtTest3.prtCustomPage(PageWidth, PageHeight,
Orientation: SYSINT): SYSINT;
var
Device:Array [0..max_len-1] of Char;
Driver:Array [0..(max_path-1)] of Char;
Port:Array [0..32] of Char;
dmode:thandle;
pdmodedevmode;
begin
try
result:=0;
printer.GetPrinter(device,driver,port,dmode);
if dmode<>0 then
begin
pdmode:=globallock(dmode);
if pdmode<>nil then
begin
pdmode^.dmFields:=pdmode^.dmFields or DM_PAPERSIZE or DM_ORIENTATION;
pDMode^.dmPaperSize:=DMPAPER_USER;
pdmode^.dmPaperWidth:=PageWidth;
pdmode^.dmPaperLength:=PageHeight;
pdmode^.dmOrientation:=Orientation;
end;
printer.SetPrinter(device,driver,port,dmode);
globalunlock(dmode);
end;
except
result:=0;
end;
end;
procedure TprtTest3.prtDrawLine(x1, y1, x2, y2, LineWidth: SYSINT);
var
x,y:integer;
begin
x:=getx;
y:=gety;
x1:=x1*x;
y1:=y1*y;
x2:=x2*x;
y2:=y2*y;
printer.Canvas.MoveTo(x1,y1);
printer.Canvas.LineTo(x2,y2);
end;
procedure TprtTest3.setFont(FontName: PChar; FontSize: SYSINT);
begin
end;
procedure TprtTest3.prtTextRect(VAlign, HAlign, RectLeft, RectTop,
RectRight, RectBottom: SYSINT; prtText: PChar);
var
x,y:integer;
begin
x:=getx;
y:=gety;
rectleft:=rectleft*x;
recttop:=recttop*y;
rectright:=rectright*x;
rectbottom:=rectbottom*y;
printer.Canvas.TextOut(rectleft,recttop,prttext);
end;
initialization
TAutoObjectFactory.Create(ComServer, TprtTest3, Class_prtTest3,
ciMultiInstance, tmApartment);
end.
在html调用如下:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<meta name="GENERATOR" content="Microsoft FrontPage 4.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<SCRIPT LANGUAGE="VBScript">
Sub TestPrtObject
Dim prtObject
Set prtObject=CreateObject("bs_print.prtTest3")
prtObject.prtCustomPage 1000,1000,1
prtObject.prtDrawLine 2,2,1000,1000,1
prtObject.prtDrawLine 500,700,1000,1000,1
prtObject.prtTextRect 2,2,0,0,1000,500,"WEB应用程序打印测试"
document.exam.T1.value="fwergearh"
Set prtObject=Nothing
End Sub
</SCRIPT>
<title>New Page 1</title>
</head>
<body>
这是一个ActiveX示例程序!
<form method="POST" name="exam" action="--WEBBOT-SELF--">
<p><input type="text" name="T1" size="20"></p>
</form>
<p><input type="button" value="打印" name="B3" onclick="TestPrtObject"></p>
</body>
</html>
运行后提示网页上有错误,请各位大侠给看看。