unit Printer; {$R PRINTER.RES} {$S-} interface uses WinTypes, WinProcs, WObjects; { TPrinter states } const ps_Ok = 0; ps_InvalidDevice = -1; { Device parameters (to set device) invalid } ps_Unassociated = -2; { Object not associated with a printer } { TPrintout banding flags } const pf_Graphics = $01; { Current band only accepts text } pf_Text = $02; { Current band only accepts graphics } pf_Both = $03; { Current band accepts both text and graphics } { TPrintout represents the physical printed document which is to sent to a printer to be printed. TPrintout does the rendering of the document onto the printer. For every document, or document type, a cooresponding TPrintout class should be created. } type PPrintout = ^TPrintout; TPrintout = object(TObject) Title: PChar; Banding: Boolean; ForceAllBands: Boolean; constructor Init(ATitle: PChar); destructor Done; virtual; procedure PrintPage(DC: HDC; Page: Word; Size: TPoint; var Rect: TRect; Flags: Word); virtual; function IsNextPage: Boolean; virtual; end; { TPrinter represent the physical printer device. To print a TPrintout, send the TPrintout to the TPrinter's Print method. } PPrinter = ^TPrinter; TPrinter = object(TObject) Device, Driver, Port: PChar; { Printer device description } Status: Integer; { Device status, error is <> ps_Ok } Error: Integer; { < 0 if error occured during print } DeviceModule: THandle; { Handle to printer driver module } DeviceMode: TDeviceMode; { Function pointer to DevMode } ExtDeviceMode: TExtDeviceMode; { Function pointer to ExtDevMode } DevSettings: PDevMode; { Local copy of printer settings } DevSettingSize: Integer; { Size of the printer settings } constructor Init; destructor Done; virtual; procedure ClearDevice; procedure Configure(Window: PWindowsObject); function GetDC: HDC; virtual; function InitAbortDialog(Parent: PWindowsObject; Title: PChar): PDialog; virtual; function InitSetupDialog(Parent: PWindowsObject): PDialog; virtual; procedure ReportError(Printout: PPrintout); virtual; procedure SetDevice(ADevice, ADriver, APort: PChar); procedure Setup(Parent: PWindowsObject); function Print(ParentWin: PWindowsObject; Printout: PPrintout): Boolean; end; { TPrinterSetupDlg is a dialog to modify which printer a TPrinter object is attached to. It displays the all the active printers in the system allowing the user to select the desired printer. The dialog also allow the user to call up the printer's "setup" dialog for further configuration of the printer. } const id_Combo = 100; id_Setup = 101; type PPrinterSetupDlg = ^TPrinterSetupDlg; TPrinterSetupDlg = object(TDialog) Printer: PPrinter; constructor Init(AParent: PWindowsObject; TemplateName: PChar; APrinter: PPrinter); destructor Done; virtual; procedure TransferData(TransferFlag: Word); virtual; procedure IDSetup(var Msg: TMessage); virtual id_First + id_Setup; procedure Cancel(var Msg: TMessage); virtual id_First + id_Cancel; private OldDevice, OldDriver, OldPort: PChar; DeviceCollection: PCollection; end; const id_Title = 101; id_Device = 102; id_Port = 103; type PPrinterAbortDlg = ^TPrinterAbortDlg; TPrinterAbortDlg = object(TDialog) constructor Init(AParent: PWindowsObject; Template, Title, Device, Port: PChar); procedure SetupWindow; virtual; procedure WMCommand(var Msg: TMessage); virtual wm_First + wm_Command; end; implementation end.