Query page size BEFORE printing

I need to know the width and height (in pixels) of the page which in my printer. Delphi provides a way to query it:
Printer.PageWidth and Printer.PageHeight contains the above values of the page which is BEING printed.

How can I query the size in pixels of the selected page in the selected printer BEFORE Printer.StartDoc?

Thank you,
Levente
LeventeAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

LischkeCommented:
Hi Levente,

try out this code:

procedure TMainForm.Button7Click(Sender: TObject);

var
  Buffer: array[0..255] of Char;
  DeviceMode: THandle;
  DevMode: PDevMode;

begin
  Printer.GetPrinter(Buffer, Buffer, Buffer, DeviceMode);
  DevMode := GlobalLock(DeviceMode);
  ShowMessage(IntToStr(DevMode.dmPaperWidth));
  GlobalUnlock(DeviceMode);
end;

Ciao, Mike
0
rwilson032697Commented:
Listening
0
LeventeAuthor Commented:
Mike,

I'm affraid, I must reject your answer. This call queries the PHYSICAL size of the page in tenths of milimetes. I need the logical one in pixels.

Br,
Levente
0
Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

rwilson032697Commented:
Hi Levente,

You can use the DevMode.dmPelsWidth and DevMode.dmPelsHeight fields to find this out.

Cheers,

Raymond.
0
LischkeCommented:
Ok, I didn't prove the pixel resolution and unfortunately the devmode structure gives no information about the resolution (at least as it is at the moment). A more general approach is to use a socalled information context which is kinda stripped down version of a device context:

procedure TMainForm.Button7Click(Sender: TObject);

var
  Driver,
  Device,
  Port: array[0..128] of Char;
  DeviceMode: THandle;
  IC: HDC;
  W, H,
  LogX,
  LogY: Integer;

begin
  Printer.GetPrinter(Device, Driver, Port, DeviceMode);
  IC := CreateIC(Driver, Device, Port, nil);
  W := GetDeviceCaps(IC, HORZRES);
  H := GetDeviceCaps(IC, VERTRES);
  LogX := GetDeviceCaps(IC, LOGPIXELSX);
  LogY := GetDeviceCaps(IC, LOGPIXELSY);
  DeleteDC(IC);
end;

This should finally give you not only the information you want at the moment but all you can expect from a DC.

Ciao, Mike
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
rwilson032697Commented:
Mike: What about the DevMode.dmPelsWidth and DevMode.dmPelsHeight fields?

Cheers,

Raymond.
0
LischkeCommented:
They do not contain useful values (equal to 0)...
0
LeventeAuthor Commented:
Thank you for your code. It finally works.
0
LischkeCommented:
Glad to help.

Ciao, Mike
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.