Unit1.~pas
资源名称:CADPrint.rar [点击查看]
上传用户:sh_weigang
上传日期:2013-04-17
资源大小:179k
文件大小:3k
源码类别:
打印编程
开发平台:
Delphi
- unit Unit1;
- interface
- uses
- Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
- Dialogs, OleCtrls, ECompositeViewer_TLB, ExpressViewerDll_TLB, StdCtrls,
- EPlotViewer_TLB, ExtCtrls, Printers;
- const
- WM_MyMSG = WM_USER + $1;
- type
- Tw_Main = class(TForm)
- CADViewer: TCExpressViewerControl;
- procedure FormCreate(Sender: TObject);
- procedure FormShow(Sender: TObject);
- private
- { Private declarations }
- procedure PrintFile;
- procedure OnMyMsg(var message:TMessage); message WM_MyMSG;
- public
- { Public declarations }
- end;
- var
- w_Main: Tw_Main;
- implementation
- uses AdCommon_TLB, EPlotRenderer_TLB;
- {$R *.dfm}
- procedure Tw_Main.FormCreate(Sender: TObject);
- begin
- Application.Title := Caption;
- if ParamStr(1) = '' then begin
- MessageBox( Handle,'达乐文企业传真中心专用工具,只能在达乐文传真服务器中使用。' +
- char(13) + char(10) + char(13) + char(10) + 'http://www.midpal.com.cn',
- '提示',MB_ICONINFORMATION+MB_OK);
- Application.ShowMainForm := false;
- Application.Terminate;
- exit;
- end else if not FileExists(ParamStr(1)) then begin
- MessageBox(Handle,PChar('文件 ' + ParamStr(1) + ' 不存在。'),PChar(Caption),MB_ICONINFORMATION+MB_OK);
- Application.ShowMainForm := false;
- Application.Terminate;
- exit;
- end;
- CADViewer.SourcePath := ParamStr(1);
- end;
- procedure Tw_Main.OnMyMsg(var message:TMessage);
- begin
- PrintFile;
- end;
- procedure Tw_Main.PrintFile;
- var
- View : IAdPageViewer2;
- i : Integer;
- pageCol : IAdCollection;
- newPage : OleVariant;
- CurView : IAdPageView;
- hPrintDC: Integer;
- dL : Real;
- dB : Real;
- dR : Real;
- dT : Real;
- bWhite : Boolean;
- di : DOCINFO;
- begin
- View := CADViewer.DocumentHandler AS IAdPageViewer2;
- View.WaitForPageLoaded;
- pageCol := View.Pages AS IAdCollection;
- hPrintDC := CreateDC('WINSPOOL','达乐文传真机',nil,nil);
- if hPrintDC = 0 then
- MessageBox(Handle,'达乐文传真机不存在,请安装后再转换。','提示',MB_ICONERROR + MB_OK)
- else begin
- Sleep(2000);
- StartDoc(hPrintDC,di);
- for i:=1 to pageCol.Count do
- begin
- newPage := pageCol.Item[i];
- View.Page := newPage;
- View.WaitForPageLoaded;
- CurView := View.View AS IAdPageView;
- dL := CurView.Left;
- dB := CurView.Bottom;
- dR := CurView.Right;
- dT := CurView.Top;
- try
- //View.SimplePrint(true,true);
- View.PrintEx(hPrintDC,dL,dB,dR,dT,true);
- except
- end;
- end;
- EndDoc(hPrintDC);
- DeleteDC(hPrintDC);
- end;
- Close();
- Application.Terminate;
- end;
- procedure Tw_Main.FormShow(Sender: TObject);
- begin
- PostMessage(Handle,WM_MYMSG,0,0);
- end;
- end.