IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

API, COM et SDKs Delphi Discussion :

API de pilotes d'imprimantes


Sujet :

API, COM et SDKs Delphi

  1. #1
    Membre habitué Avatar de neodelphi2007
    Profil pro
    Inscrit en
    Septembre 2007
    Messages
    202
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Septembre 2007
    Messages : 202
    Points : 179
    Points
    179
    Par défaut API de pilotes d'imprimantes
    Bonjour,

    je voudrais pouvoir controler les fonctions de base des pilotes d'imprimantes tels que la qualité d'impression (mode brouillon, rapide, normal...), la résolution etc.

    Existe t'il une api windows qui permet cela plus "pointu" que TPrinter ?

    Merci.

  2. #2
    Rédacteur/Modérateur
    Avatar de Andnotor
    Inscrit en
    Septembre 2008
    Messages
    5 671
    Détails du profil
    Informations personnelles :
    Localisation : Autre

    Informations forums :
    Inscription : Septembre 2008
    Messages : 5 671
    Points : 13 065
    Points
    13 065
    Par défaut
    Voilà un composant qui te permettra de sauvegarder ta config et de la rappeler à volonté

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    unit FilePrinterSetup;
     
    interface
     
    uses
      SysUtils, Classes, Dialogs,
      printers, windows, WinSpool;
     
    type
      TFilePrinterSetupException = procedure(Sender :TObject; Msg :string) of object;
     
      TFilePrinterSetup = class(TPrinterSetupDialog)
      private
        FFileName: TFileName;
        FOnException: TFilePrinterSetupException;
        { Déclarations privées }
      protected
        { Déclarations protégées }
      public
        { Déclarations publiques }
        function Load(aFileName :TFileName = ''; aExecute :boolean = FALSE) :boolean;
        procedure Save(aFileName :TFileName = '');
        function Execute: Boolean; override;
      published
        property FileName :TFileName read FFileName write FFileName;
        property OnException :TFilePrinterSetupException read FOnException write FOnException;
      end;
     
      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;
     
    procedure Register;
     
    implementation
     
    ResourceString
      Err1 = 'Configuration de l''impression'#13#13'%s'#13'Mauvais type de fichier';
     
    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;
     
    procedure Register;
    begin
      RegisterComponents('Samples', [TFilePrinterSetup]);
    end;
     
    { TFilePrinterSetup }
     
    function TFilePrinterSetup.Execute: Boolean;
    begin
      if inherited Execute then
        Save;
    end;
     
    function TFilePrinterSetup.Load(aFileName: TFileName; aExecute :boolean) :boolean;
    var
      PrinterSetup: TPrinterSetup;
    begin
      if aFileName <> '' then
        FileName := aFileName;
     
      PrinterSetup := TPrinterSetup.Create;
     
      try
        try
          PrinterSetup.LoadSetup(FileName);
        except
          if Assigned(FOnException) then
          begin
            FOnException(Self, Format(Err1, [FileName]));
            aExecute := FALSE;
          end
          else
            raise Exception.Create(Format(Err1, [FileName]));
        end;
      finally
        PrinterSetup.Free;
      end;
     
      if aExecute
      then Result := Execute
      else Result := TRUE;
    end;
     
    procedure TFilePrinterSetup.Save(aFileName: TFileName);
    var
      PrinterSetup: TPrinterSetup;
    begin
      if aFileName <> '' then
        FileName := aFileName;
     
      if FileName <> '' then
      begin
        PrinterSetup := TPrinterSetup.Create;
        PrinterSetup.SaveSetup(FileName);
        PrinterSetup.Free;
      end;
    end;
     
    end.

  3. #3
    Membre habitué Avatar de neodelphi2007
    Profil pro
    Inscrit en
    Septembre 2007
    Messages
    202
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Septembre 2007
    Messages : 202
    Points : 179
    Points
    179
    Par défaut
    Je te remercie andnotor,

    Ta solution est interressante, mais je cherche à controler les caractèristiques nominales d'une imprimante quelques que soit sa marque et son modèle.

    tel que ce composant: http://www.onedomain.com/Components/EDSPrint/

  4. #4
    Rédacteur/Modérateur
    Avatar de Andnotor
    Inscrit en
    Septembre 2008
    Messages
    5 671
    Détails du profil
    Informations personnelles :
    Localisation : Autre

    Informations forums :
    Inscription : Septembre 2008
    Messages : 5 671
    Points : 13 065
    Points
    13 065
    Par défaut
    Tu as déjà trouvé le composant, il est gratuit
    Alors où est ta question

  5. #5
    Membre habitué Avatar de neodelphi2007
    Profil pro
    Inscrit en
    Septembre 2007
    Messages
    202
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Septembre 2007
    Messages : 202
    Points : 179
    Points
    179
    Par défaut
    Je l'ai trouvé par hasard après ta réponse.

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. [XL-2007] Piloter une imprimante
    Par Lucky062 dans le forum Macros et VBA Excel
    Réponses: 2
    Dernier message: 06/08/2010, 10h45
  2. Comment installer un pilote d'imprimante?
    Par benlafo dans le forum Ubuntu
    Réponses: 2
    Dernier message: 29/11/2009, 14h02
  3. Pilote pour Imprimante thermique
    Par JP.NUAGE dans le forum Matériel
    Réponses: 3
    Dernier message: 29/06/2008, 12h18
  4. Pilote d'imprimantes USB
    Par JP.NUAGE dans le forum API, COM et SDKs
    Réponses: 1
    Dernier message: 26/10/2007, 20h40
  5. Piloter une imprimante
    Par Tigresse dans le forum Assembleur
    Réponses: 5
    Dernier message: 27/03/2003, 14h57

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo