How can I install COLLATE for the printer driver?
I need to pick up the printer driver settings that are set on a Windows machine to determine if they have been set for a specific printer.
I know how to get if a printer can be mapped using the call to DeviceCapabilities in DC_COLLATE, but that doesn't tell me if the print driver is installed for mapping or not, only that the printer has the ability to map, not what it will map ...
Why?
I'm trying to solve an issue in QuickReports with Delphi XE2 where our program no longer works the way it was compiled in Delphi 6. With Delphi 6, regardless of the settings from QuickReport, ALWAYS obeyed the collation setting in the printer driver. This is not the case in Delphi XE2.
The user has no security to change collation settings, it is forced to run for them by their system administrators, and these documents must be printed to the specified printer.
If I can tell if the driver is always installed for mapping, I can just force the collation in the QuickReport and it will do what I need, and hence my question above.
As always, I appreciate any ideas.
Hooray!
source to share
You need to use Windows API functions OpenPrinter
and GetPrinter
. When calling, GetPrinter
pass it a PRINTER_INFO_2
record that will be returned using the element pDevMode
set to DEVMODE
; that the entry DEVMODE
contains a flag whether the collation is enabled (among other things).
Here's an old Borland NG post from TeamB Dr. Peter Below. It demonstrates update the printer settings to make them permanent, but includes the use of OpenPrinter
, GetPrinter
, ClosePrinter
and PRINTER_INFO_2
, and the use DEVMODE
(referred to hDevMode
in the code below); he should get started.
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;
source to share