was ist neu ¦  programmier tips ¦  indy artikel ¦  intraweb artikel ¦  informationen ¦  links ¦  interviews
 sonstiges ¦  tutorials ¦  Add&Win Gewinnspiel

Tips (1541)

Dateien (137)
Datenbanken (90)
Drucken (35)
Grafik (114)
IDE (21)
Indy (5)
Internet / LAN (130)
IntraWeb (0)
Mathematik (76)
Multimedia (45)
Oberfläche (107)
Objekte/
ActiveX (51)

OpenTools API (3)
Sonstiges (126)
Strings (83)
System (266)
VCL (242)

Tips sortiert nach
Komponente


Tip suchen

Tip hinzufügen

Add&Win Gewinnspiel

Werbung

30 Visitors Online


 
...die Druckereinstellungen in eine Datei speichern?
Autor: Remmelt Koenes
Homepage: http://www.triplesoftware.com/
[ Tip ausdrucken ]  

Tip Bewertung (17):  
     


{
  Create a unit PrinterSetup and place code in this unit
  Do the following to save the printer config to file
}

procedure TForm1.Button1Click(Sender: TObject);
var
  
PrinterSetup: TPrinterSetup
begin
  
PrinterSetup := TPrinterSetup.Create;
  PrinterSetup.SaveSetup(FileName);
  //where file name is a string to the location of the File ex.'c:\print.cfg'
  
PrinterSetup.Free;
end

{***********************************}

unit PrinterSetup;

interface

uses
  
printers,
  windows,
  SysUtils,
  Classes,
  WinSpool;

type
  
TPrinterSetup = class

  private
    
Device, Driver, Port: array[0..CCHDEVICENAME] of char;
    DeviceMode: THandle;
    procedure Refresh;

  protected

  public
    procedure 
SaveSetup(FileName: TFilename);
    procedure LoadSetup(FileName: TFilename);
  end;
  TPrinterConfig = record
    
ADevice, ADriver, APort: array[0..CCHDEVICENAME] of char;
    SizeOfDeviceMode: DWORD;
  end;

implementation

procedure 
TPrinterSetup.Refresh;
begin
  
Printer.GetPrinter(Device, Driver, Port, DeviceMode);
end;

procedure TPrinterSetup.SaveSetup(FileName: TFilename);
var
  
StubDevMode: TDeviceMode;
  SetupPrinter: TPrinterConfig;
  FPrinterHandle: THandle;
  fFileConfig: file of TPrinterConfig;
  fFileDevMode: file of Char;
  pDevMode: PChar;
  Contador: Integer;
begin
  
Refresh;
  with SetupPrinter do
  begin
    
StrLCopy(ADevice, Device, SizeOf(ADevice));
    StrLCopy(ADriver, Driver, SizeOf(ADriver));
    StrLCopy(APort, Port, SizeOf(APort));
    OpenPrinter(Device, FPrinterHandle, nil);
    SizeOfDeviceMode := DocumentProperties(0, FPrinterHandle, Device,
      StubDevMode, StubDevMode, 0);
  end;
  AssignFile(fFileConfig, FileName);
  ReWrite(fFileConfig);
  Write(fFileConfig, SetupPrinter);
  CloseFile(fFileConfig);
  AssignFile(fFileDevMode, FileName);
  Reset(fFileDevMode);
  Seek(fFileDevMode, FileSize(fFileDevMode));
  pDevMode := GlobalLock(DeviceMode);
  for Contador := 0 to SetupPrinter.SizeOfDeviceMode - 1 do
  begin
    
Write(fFileDevMode, pDevMode[Contador]);
  end;
  CloseFile(fFileDevMode);
  GlobalUnLock(DeviceMode);
end;


procedure TPrinterSetup.LoadSetup(FileName: TFilename);
var
  
SetupPrinter: TPrinterConfig;
  fFileConfig: file of TPrinterConfig;
  fFileDevMode: file of Char;
  ADeviceMode: THandle;
  pDevMode: PChar;
  Contador: Integer;
begin
  if 
FileExists(FileName) then
  begin
    
AssignFile(fFileConfig, FileName);
    Reset(fFileConfig);
    read(fFileConfig, SetupPrinter);
    CloseFile(fFileConfig);
    AssignFile(fFileDevMode, FileName);
    Reset(fFileDevMode);
    Seek(fFileDevMode, SizeOf(SetupPrinter));
    ADeviceMode := GlobalAlloc(GHND, SetupPrinter.SizeOfDeviceMode);
    pDevMode := GlobalLock(ADeviceMode);
    for Contador := 0 to SetupPrinter.SizeOfDeviceMode - 1 do
    begin
      
read(fFileDevMode, char(pDevMode[Contador]));
    end;
    CloseFile(fFileDevMode);
    GlobalUnLock(ADeviceMode);
    Printer.SetPrinter(SetupPrinter.ADevice, SetupPrinter.ADriver,
      SetupPrinter.APort, ADeviceMode);
  end;
end;

end.

 

Bewerten Sie diesen Tipp:

dürftig
ausgezeichnet


Copyright © by SwissDelphiCenter.ch
All trademarks are the sole property of their respective owners