⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 改变打印机属性页.txt

📁 大量Delphi开发资料
💻 TXT
字号:


   1.Create a copy of Printers.pas and rename the copy to NewPrint.pas.


     ***DO NOT make these changes to Printers.pas, if you do you will get an error saying "Unable to find printers.pas" when you compile your

     application. (Well, that's the error I received...)***


   2.Move NewPrint.pas to the Lib directory.


     (Usually "C:\Program Files\Borland\Delphi 2.0\Lib" ) 

   3.Change the UNIT NAME in NewPrint.pas


     from:

     unit Printers;


     to:

     unit NewPrint;


   4.Add the following PUBLIC METHOD declaration to the TPrinter object definition in the Interface section of NewPrint.pas:


        procedure NewPageDC(DM: PDevMode);


   5.Add the following procedure to the Implementation section of NewPrint.pas:



     procedure TPrinter.NewPageDC(DM: PDevMode);

        begin

           CheckPrinting(True);

           EndPage(DC);

          {Check to see if new device mode setting were passed}

           if Assigned(DM) then

             ResetDC(DC,DM^);

           StartPage(DC);

           Inc(FPageNumber);

           Canvas.Refresh;

       end;


   6.Instead of adding "Printers" to the USES clause of your application, add "NewPrint".


     EVERYTHING ELSE WORKS EXACTLY THE SAME (ie BeginDoc, EndDoc, NewPage, etc.) but you now have the capability of changing printer

     settings on the fly between pages WITHIN THE SAME PRINT DOCUMENT. (The example below shows how.)


     Instead of calling:


        Printer.NewPage;


     call: 


        Printer.NewPageDC(DevMode);


     Here is the small example (with bytes of code from other print altering routines I've gathered).


     procedure TForm1.Button1Click(Sender: TObject);

     var

       ADevice, ADriver, APort: array [0..255] of char;

       ADeviceMode: THandle;

       DevMode: PDevMode;


     begin

         with Printer do begin

           GetPrinter(ADevice,ADriver,APort,ADeviceMode);

           SetPrinter(ADevice,ADriver,APort,0);

           GetPrinter(ADevice,ADriver,APort,ADeviceMode);

           DevMode := GlobalLock(ADeviceMode);

           if not Assigned(DevMode) then ShowMessage('Can''t set printer.')

           else begin

             with DevMode^ do begin

               {Put any other settings you want here}

               dmDefaultSource := DMBIN_UPPER;

              {these codes are listed in "Windows.pas"}

             end;

             GlobalUnlock(ADeviceMode);

             SetPrinter(ADevice,ADriver,APort,ADeviceMode);

           end;

         end;

         Printer.BeginDoc;

         Printer.Canvas.TextOut(50,50,'This page is printing from the UPPER PAPER TRAY.');

         with DevMode^ do begin

           {Put any other settings you want here}

           dmDefaultSource := DMBIN_LOWER;

          {these codes are listed in "Windows.pas"}

         end;

         Printer.NewPageDC(DevMode);

         Printer.Canvas.TextOut(50,50,'This page is printing from the LOWER PAPER TRAY.');

         Printer.EndDoc;

     end;


     {*************************************************************


     Notes from the author:


     I've used this myself in applications for my job so I know it will work.

     These modifications were made in Delphi Client/Server 2.01 running on WinNT 4.0

     but they should work with Delphi 2.0 Standard and Professional, and under Windows95

     as well.  I have not tried them with Delphi 3 yet...  If anyone has any comments

     or questions, feel free to mail me...


                                              David A. Bussey

                                              ERC/RAL Developer

                                              River City Bank

                                              dbussey@bbtel.com


     ************************************************************}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -