DELPHI AREA
MESSAGE BOARD
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   Favorites   Watched Topics     RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Print Using Custom Page Sizes on Windows NT and Windows 2000
Goto page 1, 2  Next
 
   Reply to topic       DELPHI AREA Forum Index -> DELPHI AREA's Products
View previous topic :: View next topic  
Author Message
mc
Member


Joined: 17 Jun 2004
Posts: 9

PostPosted: 17/06/04 20:17    Post subject: Print Using Custom Page Sizes on Windows NT and Windows 2000 Reply with quote

I just discover your very good TPrinterPreview, and I see that it's Great.

On systems that are running Windows NT and Windows 2000, we must define all page sizes as a form before we can use them...
It's my problem.
I just try TPrintPreview and it's not solving my problem.
I have see an article on the microsoft site that describe my problem.
But the solution is given in VB. Can you help please to adapt it to Delphi and to your good (very good) component.
Thank you in advance.
Sorry for my english.

The article is on Microsoft Knowledge Base published under Q282474

the link is:
http://support.microsoft.com/default.aspx?scid=kb;en-us;282474

mc


Last edited by mc on 22/06/04 21:37; edited 2 times in total
Back to top
View user's profile Visit poster's website
Kambiz
Administrator


Joined: 07 Mar 2003
Posts: 518
Location: Tehran, Iran

PostPosted: 18/06/04 20:43    Post subject: Reply with quote

I try to include it in TPrintPreview during this weekend.

Kambiz
Back to top
View user's profile Send e-mail Visit poster's website
mc
Member


Joined: 17 Jun 2004
Posts: 9

PostPosted: 18/06/04 21:29    Post subject: Reply with quote

I can't believe what I'm reading....
Imagine that I have products that I spend a lot of money to get them and when I ask for a few new improvements, the only answer that I get is that it will be included in the next release (next month or the next year....).
And now, you say that it will be done this weekend I just say I'm very happy.
Sorry for my english. But I hope that you understand me.
Thank you.
I will put links to your web site in every place possible.
I had put-it in a french developpement site [url]http://www.developpez.com/ [/url] in forum http://www.developpez.net/forums/viewtopic.php?t=209356

mc
Back to top
View user's profile Visit poster's website
Kambiz
Administrator


Joined: 07 Mar 2003
Posts: 518
Location: Tehran, Iran

PostPosted: 19/06/04 04:24    Post subject: Reply with quote

Thank you very much.
Back to top
View user's profile Send e-mail Visit poster's website
Kambiz
Administrator


Joined: 07 Mar 2003
Posts: 518
Location: Tehran, Iran

PostPosted: 19/06/04 19:37    Post subject: Reply with quote

It's done.

To manage forms, the FormName property and FetchFormNames, GetFormSize, AddNewForm, and RemoveForm methods are added.

Please look at the readme file for more information.

Cheers
Kambiz
Back to top
View user's profile Send e-mail Visit poster's website
mc
Member


Joined: 17 Jun 2004
Posts: 9

PostPosted: 20/06/04 08:18    Post subject: Reply with quote

Bravo
You are the best.
I tried it. It works very good but only like your previous pCustum do.
in the PrintPreview window all ok, but like with pCustum, when I send it to printer (print) and if I don't make manually default paper to custum it prints wrong.
If I have for example A4 default paper size, and I sent a job with custom size, it prints on a custum size but the datas are printed proportional custom/A4.
I have a HP Deskjet990Cxi printer but I don't think that the problem is from printer driver because with Microsoft Word and Excel and so on.. when I sent a job to the same printer with custom size and in the same time the default printer's paper size is standard one, it print very good.

An other point: how can define margins with PrintPreview and how to save user defined printer's parameters to use them in the next printing.

mc
Back to top
View user's profile Visit poster's website
Kambiz
Administrator


Joined: 07 Mar 2003
Posts: 518
Location: Tehran, Iran

PostPosted: 20/06/04 08:55    Post subject: Reply with quote

The component doesn't automatically add/select a new custom form when the paper is in custom size. So, instead of setting the custom paper size, your program should add a new form, and then select it in the component.

By the way, a printer might be unable to use some forms or custom paper sizes. Please read Windows NT Print Manager and Custom Form Limitations for more information.

Also, the component does handle neither page margins nor user defined printer's parameters. It's the developer's responsibility to manage them in his/her own way.
Back to top
View user's profile Send e-mail Visit poster's website
mc
Member


Joined: 17 Jun 2004
Posts: 9

PostPosted: 20/06/04 21:58    Post subject: Reply with quote

On the same machine with the same OS and the same printer, Microsoft Word is doing things very good. It's why I am sure that the solution exists.
I will continue to investigate and search this solution. And every body can help welcome. It's for me and for all the users of PrintPreview.
Thank you for the time reading this.

mc
Back to top
View user's profile Visit poster's website
Kambiz
Administrator


Joined: 07 Mar 2003
Posts: 518
Location: Tehran, Iran

PostPosted: 20/06/04 22:35    Post subject: Reply with quote

Did you try something like this?

Code:
procedure TMainForm.FormCreate(Sender: TObject);
begin
  PrintPreview.AddNewForm('My Custom Form', 10000 {x 0.01 mm}, 10000 {x 0.01 mm});
  PrintPreview.FormName := 'My Custom Form';
end;

procedure TMainForm.FormDestroy(Sender: TObject);
begin
  PrintPreview.RemoveForm('My Custom Form');
end;
Back to top
View user's profile Send e-mail Visit poster's website
mc
Member


Joined: 17 Jun 2004
Posts: 9

PostPosted: 20/06/04 22:38    Post subject: Reply with quote

Yes I do... of corse
On what OS you are working please?
mc


Last edited by mc on 22/06/04 21:38; edited 1 time in total
Back to top
View user's profile Visit poster's website
Kambiz
Administrator


Joined: 07 Mar 2003
Posts: 518
Location: Tehran, Iran

PostPosted: 21/06/04 09:22    Post subject: Reply with quote

Windows XP!

I don't have NT 4.0 or 2000 around.
Back to top
View user's profile Send e-mail Visit poster's website
mc
Member


Joined: 17 Jun 2004
Posts: 9

PostPosted: 21/06/04 20:23    Post subject: Reply with quote

Hello Kambiz

In the article on Microsoft Knowledge Base published under Q282474 :
Quote:
Retrieve the printer's DEVMODE structure, set the dmFormName member, and use the ResetDC function to set this form as the current form for the Device Context (DC) of the printer. When this form is selected for the DC, it is only selected for the calling process and does not change the driver's default setting. This does not require any special permissions. This method is preferred for applications that change a printer's settings.

I had exams your source code and I don't find a call to ResetDC.
What do you think?
mc
Back to top
View user's profile Visit poster's website
Kambiz
Administrator


Joined: 07 Mar 2003
Posts: 518
Location: Tehran, Iran

PostPosted: 22/06/04 07:55    Post subject: Reply with quote

Well, I thought Delphi's printer object does this task, but I was wrong.

Please replace the SetPrinterOptions method with the following one:

Code:
procedure TPrintPreview.SetPrinterOptions;
var
  DeviceMode: THandle;
  DevMode: PDeviceMode;
  Device, Driver, Port: array[0..MAX_PATH] of Char;
  PaperSize: TPoint;
  DriverInfo2: PDriverInfo2;
  DriverInfo2Size: DWORD;
  hPrinter: THandle;
  TheFormName: String;
begin
  if PrinterInstalled then
  begin
    TheFormName := FormName;
    Printer.GetPrinter(Device, Driver, Port, DeviceMode);
    OpenPrinter(Device, hPrinter, nil);
    try
      DevMode := PDevMode(GlobalLock(DeviceMode));
      try
        with DevMode^ do
        begin
          dmFields := dmFields or DM_PAPERSIZE;
          if IsCustomPaper then
          begin
            PaperSize := ConvertXY(FPageExt.X, FPageExt.Y, FUnits, mmLoMetric);
            if FOrientation = poLandscape then
              SwapValues(PaperSize.X, PaperSize.Y);
            dmPaperSize := DMPAPER_USER;
            dmFields := dmFields or DM_PAPERWIDTH;
            dmPaperWidth := PaperSize.X;
            dmFields := dmFields or DM_PAPERLENGTH;
            dmPaperLength := PaperSize.Y;
          end
          else
          begin
            dmPaperSize := PaperSizes[FPaperType].ID;
            dmFields := dmFields and not (DM_PAPERWIDTH or DM_PAPERLENGTH);
          end;
          dmFields := dmFields or DM_ORIENTATION;
          case FOrientation of
            poPortrait: dmOrientation := DMORIENT_PORTRAIT;
            poLandscape: dmOrientation := DMORIENT_LANDSCAPE;
          end;
          if TheFormName <> '' then
          begin
            dmFields := dmFields or DM_FORMNAME;
            StrPLCopy(dmFormName, TheFormName, CCHFORMNAME);
          end;
          ResetDC(Printer.Handle, DevMode^);
        end;
      finally
        GlobalUnlock(DeviceMode);
      end;
      GetPrinterDriver(hPrinter, nil, 2, nil, 0, DriverInfo2Size);
      GetMem(DriverInfo2, DriverInfo2Size);
      try
        GetPrinterDriver(hPrinter, nil, 2, DriverInfo2, DriverInfo2Size, DriverInfo2Size);
        StrPCopy(Driver, ExtractFileName(StrPas(DriverInfo2^.PDriverPath)));
      finally
        FreeMem(DriverInfo2, DriverInfo2Size);
      end;
    finally
      ClosePrinter(hPrinter);
    end;
    Printer.SetPrinter(Device, Driver, Port, DeviceMode);
  end;
end;

I hope that was the problem.
Back to top
View user's profile Send e-mail Visit poster's website
mc
Member


Joined: 17 Jun 2004
Posts: 9

PostPosted: 22/06/04 21:00    Post subject: Reply with quote

Hi Kambiz
Not yet, there is no change Crying or Very sad
Have you please someone that have Windows 2000 or Windows NT to try Forms and to see by yourself?
Thank you.
mc
Back to top
View user's profile Visit poster's website
Kambiz
Administrator


Joined: 07 Mar 2003
Posts: 518
Location: Tehran, Iran

PostPosted: 23/06/04 10:00    Post subject: Reply with quote

I'm sorry, but I don't have access to any NT or W2K machine.

Could you please check out the attached update?

Thank you,
Kambiz
Back to top
View user's profile Send e-mail Visit poster's website
Display posts from previous:   
   Reply to topic       DELPHI AREA Forum Index -> DELPHI AREA's Products All times are GMT
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group