Re: Print Properties
From: Peter Below (TeamB) (100113.1101_at_compuXXserve.com)
Date: 01/23/04
- Next message: Peter Below (TeamB): "Re: CopyFile inexplicably fails to work"
- Previous message: Brian Cook: "Re: WinExecAndWaitV2, ok but a question:"
- In reply to: Camiel Wijffels: "Re: Print Properties"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Fri, 23 Jan 2004 19:43:08 +0100
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
- Next message: Peter Below (TeamB): "Re: CopyFile inexplicably fails to work"
- Previous message: Brian Cook: "Re: WinExecAndWaitV2, ok but a question:"
- In reply to: Camiel Wijffels: "Re: Print Properties"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|