Thursday, December 14, 2017

DELPHI - How set active printer to color/monochrome

When is parameter TRUE -> set active printer to color.
function SetPrinterColor( _b : boolean ) : boolean;
var
  buffer1 : array[0..250] of char;
  buffer2 : array[0..250] of char;
  buffer3 : array[0..250] of char;
  ADevice, ADriver, APort : pchar;
  hDm : THandle;
  pdm : PDEVMODE;
begin
  ADevice := buffer1;
  ADriver := buffer2;
  APort   := buffer3;

  { get active printer }

  Printer.GetPrinter( ADevice, ADriver, APort, hDm );

  { make change }

  Pdm := globalLock ( hDm );
  if _b then
    pdm^.dmColor := DMCOLOR_COLOR
  else
    pdm^.dmColor := DMCOLOR_MONOCHROME;
  globalUnlock(hDm);

  { set value }

  Printer.SetPrinter( ADevice, ADriver, APort, hDm );

  result := true;
end;

No comments:

Post a Comment