Solved

Printing behaves different in Win9x und WinNT

Posted on 2001-07-17
8
227 Views
Last Modified: 2010-04-04
using the print-method of a FORM (Delphi4) in Win9x it prints (as espected) a Bitmap-Hardcopy, in WINNT it produces a empty sheet.

What happens?

Using my own Print-Routine (using the DC from printer.gethandle) its the same strange thing: in WIN9x all is fine, under NT I get empty sheets. A small difference to the Delphi-print-method: (NT) after get empty pages from the first print-job the next print-job prints fine, but if after change any of the printeroptions (for inst. portrait->landscape) it prints (for the first time) again empty sheet...

Another strange thing is, that the printouts got from the same code and the same printer in NT and 9x differ: for inst. a frame around the whole printable area dont have a right side printing under NT, but is OK printing under 9x.


Whats wrong?

any hints?

nmm
0
Comment
Question by:nmm
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 2
8 Comments
 
LVL 30

Expert Comment

by:third
ID: 6292580
have u tried printing a test page in NT? and check if the printer selected in the printer options is the hardware that u have... :)
0
 
LVL 3

Expert Comment

by:SteveWaite
ID: 6293821
I had a similar problem. Maybe the printer driver has different referances to the gutter and margin widths on NT and 9x and wouldn't print anything on NT. Do not have your print code read and believe the margin widths from the driver but create your own. Some printer drivers (HP850c for one) does this between 95 and 98 where 95 gives proper dimensions and 98 gives wrong ones.

Steve
0
 

Author Comment

by:nmm
ID: 6401547
Hi Steve
What does that mean: "create your own", do you mean I should create my own printerdriver? I suppose that will be unpractiable, because the program sould print on any printer with windows-driver.

If you mean, I should create my own margin widths, that will also be not possible, because this way I have to guess (or believe the GetDeviceCaps-Information) the printers resulution, the sheet dimension and so on.

If the GetDeviceCaps-Infos are usualy wrong in NT, why will the second print-job print fine?

For me it looks like: somesort of necessary initialization will not be done proper by BeginDoc und sonething is wrong until the first Print-Job is done. May be its possible to do this special initialization befor printing? The crux is, that I dont know what is to be initialized...

nmm

0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 3

Expert Comment

by:SteveWaite
ID: 6903498
if you are still there....
this is what i do and works ok..
    try //except
      try //finally
        Application.MainForm.Enabled := False;
        with Printer do
        begin
          if (Copies = 1)
            then Title := txtTitle
            else Title := txtTitle + ' x' + IntToStr(Copies);
          BeginDoc;
          for I := Start to Stop do
          begin
            DrawPage; // Printer.Canvas
            if (I <> Stop)
              then NewPage;
          end;
          EndDoc;
        end;
      finally
        Application.MainForm.Enabled := True;
      end;
    except
      begin
        Errored := True;
        if Printer.Printing
          then Printer.Abort;
      end;
    end;
Regards,
Steve
0
 
LVL 3

Expert Comment

by:SteveWaite
ID: 6903513
> Another strange thing is, that the printouts got from the same code and the same printer in NT and 9x
differ: for inst. a frame around the whole printable area dont have a right side printing under NT,
but is OK printing under 9x.

Your 'printable area' is bigger than the 'actual' printable area and so your border is outside.

I was trying to say that you should not trust the GetDeviceCaps-Information.

Make your area smaller?
Regards,
Steve
0
 
LVL 3

Accepted Solution

by:
SteveWaite earned 200 total points
ID: 6903541
and do a proper printer setup before the print job..

// Assert confguration details
procedure TForm1.PrinterConfig;
var
  Device, Driver, Port: array[0..80] of Char;
  DevMode: THandle;
  PDevMode: PDeviceMode;
begin
  Printer.GetPrinter(Device, Driver, Port, DevMode); // Get printer device name etc.
  Printer.SetPrinter(Device, Driver, Port, 0);  // force reload of DEVMODE
  Printer.GetPrinter(Device, Driver, Port, DevMode); // get DEVMODE
  if not (DevMode = 0) then
  begin
    PDevMode := GlobalLock(DevMode); // lock it to get pointer to DEVMODE record
    if not (PDevMode = nil) then
    try
      with PDevMode^ Do
      begin
        // example: change the paper size
        dmPapersize := DMPAPER_A4;
        dmFields := dmFields or DM_PAPERSIZE; // force driver to re-select size
        // set something else
        // ..
      end;
    finally
      GlobalUnlock(DevMode);
    end;
  end;
end;
0
 

Author Comment

by:nmm
ID: 6911076
Hi Steve, thanx for this comments, finally it leads me to the solution: beside the differences of GetDeviceCap, which are explain the different behavior in printing frames, there is a difference in NT/2000 and Win98: If you assign the printer.handle to a variable DC:HDC, it differs depending on assignment before BeginDoc and after BeginDoc in NT.
I used such a "before-assigned" DC in what you call "DrawPage" (instad of printer.hanlde). In Win98 this works fine, but in NT the first time printing goes to a undefined DC.
After changing this (assign the DC-variable again after BeginDoc) it words in NT/2000 as well.

Reagrds
nmm
0
 
LVL 3

Expert Comment

by:SteveWaite
ID: 6911088
Glad I helped after all and thanks for posting that info too!
Regards,
Steve
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question