您需要使用 Windows API 函数OpenPrinter
和GetPrinter
. 调用时GetPrinter
,传递一条PRINTER_INFO_2
记录,该记录将返回,pDevMode
成员设置为a DEVMODE
;该DEVMODE
记录包含是否启用排序规则的标志(除其他外)。
这是 TeamB 的 Peter 下面的旧 Borland NG 帖子。它演示了更新打印机设置以使其永久化,但它包括使用OpenPrinter
、GetPrinter
、ClosePrinter
和PRINTER_INFO_2
,以及使用DEVMODE
(在下面的代码中引用hDevMode
);它应该让你开始。
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;