How can I set the global default printer's papersize to A3 use delphi?

Hello,
  I want set the system's default printer(not user's) to A4(Papersize),How can do it with delph?
  Thank u.
zhijun_chenAsked:
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.

rwilson032697Commented:
Listening
0
schutnikCommented:
Try this.  I tested it on NT, but I don't have other versions of Windows so I can't test it on any other platforms.

Just replace 'bobprint' with the name of your printer.

Good luck,
Kelly

--------------------------------

uses WinSpool;

var
  hPrint: THandle;
  pInfo: ^PRINTER_INFO_2;
  pDef: PRINTER_DEFAULTS;
  cbInfo: DWORD;
begin
  // open the printer
  pDef.pDatatype := nil;
  pDef.pDevMode := nil;
  pDef.DesiredAccess := PRINTER_ALL_ACCESS;
  if not OpenPrinter('bobprint', hPrint, @pDef) then
  begin
    ShowMessage('could not open printer');
    exit;
  end;
  cbInfo := 0;
  // get the buffer size in cbInfo
  GetPrinter(hPrint, 2, nil, 0, @cbInfo);
  // allocate the buffer
  HGlobal(pInfo) := GlobalAlloc(GPTR, cbInfo);
  // get the printer info
  if not GetPrinter(hPrint, 2, pInfo, cbInfo, @cbInfo) then
  begin
    ShowMessage('could not get printer info : ' + IntToStr(GetLastError));
    exit;
  end;
  pInfo.pDevMode.dmPaperSize := DMPAPER_A4;
  pInfo.pDevMode.dmFields := DM_PAPERSIZE;
  if not SetPrinter(hPrint, 2, pInfo, 0) then
  begin
    ShowMessage('could not set printer info : ' + IntToStr(GetLastError));
    exit;
  end;
  ClosePrinter(hPrint);
  // free the printer info
  GlobalFree(HGlobal(pInfo));
end;
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
schutnikCommented:
Also, MS says to get the default printer, you do the following:

============
To get information about the default printer, call the GetProfileString function with the section name string set to "windows" and the key name string set to "device". The returned string contains the name of the default printer, the name of the printer DRV file, and the port to which the printer is attached.
============

As far as I know, there is no such thing as a 'system default printer' as all of that information is stored only on a user level in NT and only on a system level in 95/98.  Therefore, in NT, you would have to change the setting for all printers (by listing the printers and performing the change on each one individually) or only one specific printer.

Good luck
Kelly

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.