Article View: borland.public.delphi.nativeapi
Article #207Re: Print Properties
From: Peter Below (TeamB)
Date: Fri, 23 Jan 2004 18:43
Date: Fri, 23 Jan 2004 18:43
86 lines
3824 bytes
3824 bytes
In article <40104a0b@newsgroups.borland.com>, Camiel Wijffels wrote:
> The conjunction of GetPrinter and SetPrinter works just fine. Except for one
> point - the printerproperties gets lost.
>
> ie, when I have my app and select printer properties with (for example) the
> default printer, I can change the settings. These will indeed be used while
> printing. However when I select another printer in my listbox (applying once
> the Get/Set pair) and I go back to my default printer in my listbox
> (applying the Get/Set pair once more), the settings just made are lost. Only
> the printer default remains.
>
> How to solve?
The easiest way may be to make the changed settings the default, see below.
The alternative would be to save the complete device context for each printer
(beware: they will have different sizes for each printer, and the size is
*not* Sizeof(TDeviceMode)!), so you can restore those settings instead of
using ResetPrinter to restore the defaults. It may be enough, though, to save
only the public part of the device mode record (the part represented by a
TDeviceMode).
Uses WinSpool;
Procedure MakePrintersettingsPermanent;
var
hPrinter: THandle;
Device : array[0..255] of char;
Driver : array[0..255] of char;
Port : array[0..255] of char;
hDeviceMode: THandle;
pDevMode: PDeviceMode;
bytesNeeded: Cardinal;
pPI: PPrinterInfo2;
Defaults: TPrinterDefaults;
retval: BOOL;
begin
Assert( Printer.PrinterIndex >= 0 );
Printer.GetPrinter(Device, Driver, Port, hDeviceMode);
FillChar( Defaults, Sizeof(Defaults), 0 );
Defaults.DesiredAccess:=
PRINTER_ACCESS_ADMINISTER or PRINTER_ACCESS_USE;
if not WinSpool.OpenPrinter(@Device, hPrinter, @Defaults ) then
RaiseLastWin32Error;
try
retval := WinSpool.GetPrinter(
hPrinter,
2,
Nil, 0, @bytesNeeded );
GetMem( pPI, bytesNeeded );
try
retval := WinSpool.GetPrinter(
hPrinter, 2,
pPI, bytesNeeded, @bytesNeeded );
If not retval Then
RaiseLastWin32Error;
pDevMode := GlobalLock( hDeviceMode );
Assert( Assigned( pdevmode ));
try
Move( pdevmode^, pPI^.pDevMode^, Sizeof( pdevmode^ ));
finally
GlobalUnlock( hDevicemode );
end;
If not WinSpool.SetPrinter(
hPrinter, 2,
pPI,
0 )
Then
RaiseLastWin32error;
finally
FreeMem( pPI );
end;
finally
WinSpool.ClosePrinter( hPrinter );
end;
end;
--
Peter Below (TeamB)
Use the newsgroup archives :
http://www.mers.com/searchsite.html
http://www.tamaracka.com/search.htm
http://groups.google.com
http://www.prolix.be
Technical Details
Message-ID:
<VA.0000a8e5.00752d46@nomail.please>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!fu-berlin.de!news.eunet.no!uio.no!news.tele.dk!news.tele.dk!small.news.tele.dk!proxad.net!203.109.252.33.MISMATCH!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mailReferences:
<400b0645@newsgroups.borland.com> <40104a0b@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: f94dd,9c65616b0876a2f9 X-Google-Attributes: gidf94dd,public X-Google-ArrivalTime: 2004-01-23 11:04:28 PST Date: Fri, 23 Jan 2004 19:43:08 +0100 Newsgroups: borland.public.delphi.nativeapi Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit X-Newsreader: Virtual Access by Atlantic Coast PLC, http://www.atlantic-coast.com/va Organization: TeamB Message-ID: <VA.0000a8e5.00752d46@nomail.please> Subject: Re: Print Properties From: "Peter Below (TeamB)" <100113.1101@compuXXserve.com> Reply-To: 100113.1101@compuXXserve.com References: <400b0645@newsgroups.borland.com> <40104a0b@newsgroups.borland.com> NNTP-Posting-Host: 62.226.187.52 X-Trace: newsgroups.borland.com 1074883280 62.226.187.52 (23 Jan 2004 10:41:20 -0700) Lines: 88 Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!fu-berlin.de!news.eunet.no!uio.no!news.tele.dk!news.tele.dk!small.news.tele.dk!proxad.net!203.109.252.33.MISMATCH!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail