procedure TRMReport.ShowPreparedReport; var s: string; lPreviewForm: TRMPreviewForm; begin RMCurReport := Self; Flag_PrintBackGroundPicture := True; if (not FThreadPrepareReport) and (EndPages.Count = 0) then Exit; FCurrentBand := nil; FCurrentPage := nil; FMasterReport := Self; FDocMode := rmdmPreviewing; s := RMLoadStr(SPreview); if ReportInfo.Title <> '' then s := s + ' - ' + ReportInfo.Title else if FileName <> '' then s := s + ' - ' + ExtractFileName(FileName) else s := s + ' - ' + RMLoadStr(SUntitled); if Assigned(Preview) then begin FCurPreview := Preview; Preview.ShowReport(Self); end else begin if csDesigning in ComponentState then lPreviewForm := TRMPreviewForm.Create(nil) else lPreviewForm := TRMPreviewForm.Create(Self);//这里
{ TRMPreviewForm } TRMPreviewForm = class(TForm) ImageList1: TImageList; procedure FormCreate(Sender: TObject); procedure FormClose(Sender: TObject; var Action: TCloseAction); procedure FormShow(Sender: TObject); procedure FormDestroy(Sender: TObject); procedure FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean); private { Private declarations } FDoc: Pointer; FViewer: TRMPreview;//这里 包括 预览对象 FPopupMenu: TRMPopupMenu; FPopupMenuPrint: TRMPopupMenu;
{ TRMPreview } TRMPreview = class(TRMVirtualPreview) private FShowToolbar: Boolean; FOnBtnExitClickEvent: TNotifyEvent; FOnSaveReportEvent: TRMPreviewSaveReportEvent; Dock971: TRMDock; ToolbarStand: TRMToolbar; BtnExit: TRMToolbarButton; btn100: TRMToolbarButton; btnOnePage: TRMToolbarButton; btnPageSetup: TRMToolbarButton; btnPageWidth: TRMToolbarButton; btnShowOutline: TRMToolbarButton; ToolbarSep972: TRMToolbarSep; //{$IFDEF USE_TB2K} // btnPrint: TRMSubmenuItem; //{$ELSE} btnPrint: TRMToolbarButton; //打印按钮 //{$ENDIF}
procedure TRMPreview.btnPrintClick(Sender: TObject); begin if (Report = nil) or (not btnPrint.Visible) then Exit; Print;//打印方法 end;
procedure TRMVirtualPreview.Print; var lSavePrinterIndex: Integer; lNeedSave: Boolean; lPages: string; lForm: TRMPrintDialogForm; begin if FPrepareReportFlag then Exit; if (GetEndPages = nil) or (RMPrinters.Count = 2) then Exit; lForm := TRMPrintDialogForm.Create(nil);//打印对话框
procedure TRMPrintDialogForm.FormShow(Sender: TObject); begin cmbPrinters.Items.Assign(RMPrinters.Printers);//读取打印机列表 cmbPrinters.Items.Delete(1);//删除虚拟打印机 FOldIndex := CurrentPrinter.PrinterIndex; if FOldIndex <= 1 then cmbPrinters.ItemIndex := 0 else cmbPrinters.ItemIndex := FOldIndex - 1; if cmbPrinters.ItemIndex < 0 then cmbPrinters.ItemIndex := 0; chkCollateClick(nil); cmbPrintAll.ItemIndex := 0; cmbPrintAll.Left := Label5.Left + Label5.Width + 11; cmbScalePapers.ItemIndex := -1; cmbPrintersChange(nil); FSpinOffsetTop.Value := FPrintOffsetTop / 10000; FSpinOffsetLeft.Value := FPrintOffsetLeft / 10000; end;
constructor TRMPrinterList.Create; begin inherited Create; FLock := TCriticalSection.Create; FPrinters := TStringList.Create; BuildPrinterList;//读取打印机列表 GetDefaultPrinter; end;
procedure TRMPrinterList.BuildPrinterList; var lLineCur, lPort: PChar; lBuffer, lPrinterInfo: PChar; lFlags, lCount, lNumInfo: DWORD; I: Integer; lLevel: Byte; tmp: TRMPrinterInfo; lStr: string; begin FLock.Acquire; try FreePrinterList; FPrinters.Clear; if Win32Platform = VER_PLATFORM_WIN32_NT then begin lFlags := PRINTER_ENUM_CONNECTIONS or PRINTER_ENUM_LOCAL; lLevel := 4; end else begin lFlags := PRINTER_ENUM_LOCAL; lLevel := 5; end; lCount := 0; EnumPrinters(lFlags, nil, lLevel, nil, 0, lCount, lNumInfo); if lCount > 0 then begin GetMem(lBuffer, lCount); try if not EnumPrinters(lFlags, nil, lLevel, PByte(lBuffer), lCount, lCount, lNumInfo) then Exit; lPrinterInfo := lBuffer; for I := 0 to lNumInfo - 1 do begin if lLevel = 4 then begin with PPrinterInfo4(lPrinterInfo)^ do begin tmp := TRMPrinterInfo.Create(nil, pPrinterName, nil); FPrinters.AddObject(pPrinterName, tmp); Inc(lPrinterInfo, sizeof(TPrinterInfo4)); end; end else begin with PPrinterInfo5(lPrinterInfo)^ do begin lLineCur := pPortName; lPort := FetchStr(lLineCur); while lPort^ <> #0 do begin lStr := Format(SDeviceOnPort, [pPrinterName, lPort]); tmp := TRMPrinterInfo.Create(nil, pPrinterName, lPort); FPrinters.AddObject(lStr, tmp); lPort := FetchStr(lLineCur); end; Inc(lPrinterInfo, sizeof(TPrinterInfo5)); end; end; end; finally FreeMem(lBuffer, lCount); end; end; tmp := TRMPrinterInfo.Create(nil, PChar(RMLoadStr(SDefaultPrinter)), nil); FPrinters.InsertObject(0, RMLoadStr(SDefaultPrinter), tmp); //默认打印机 tmp := TRMPrinterInfo.Create(nil, PChar(RMLoadStr(SVirtualPrinter)), nil); // 虚拟打印机 FPrinters.InsertObject(1, RMLoadStr(SVirtualPrinter), tmp); finally Flock.Release; end; end;
procedure TRMPrinterList.Refresh; begin FLock.Acquire; try BuildPrinterList; finally Flock.Release; end; end;