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

Delphi Discussion :

[D7] Bacs imprimante


Sujet :

Delphi

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Invité
    Invité(e)
    Par défaut [D7] Bacs imprimante
    bonjour,

    je cherche depuis un moment comment lister et modifier le bac d'une imprimante.
    j'arrive bien à lister les imprimantes et sélectionner celle que je souhaite, mais je ne trouve pas comment gérer les bacs.

    j'ai déjà le code suivant :

    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
    procedure TForm1.FormCreate(Sender: TObject);
    begin
      cbb1.Items := Printer.Printers;
      cbb1.ItemIndex := Printer.PrinterIndex;
    end;
     
     
     
    procedure TForm1.btn6Click(Sender: TObject);
    var po: TPrinterOrientation;
    begin
      Printer.PrinterIndex := cbb1.ItemIndex;
     
      if rg1.ItemIndex = 0
      then po := poPortrait
      else po := poLandscape;
     
      Printer.PrinterIndex := 2;
      ChangePrinter(1, po);
     
      Printer.BeginDoc;
      Printer.Canvas.TextOut(50,50,'Test');
      Printer.EndDoc;
    end;    
     
     
    procedure TForm1.ChangePrinter(ToBin: Integer; ToOrientation: TPrinterOrientation);
    var
      ADevice, ADriver, APort: array [0..255] of Char;
      DeviceHandle: THandle;
      DevMode: PDeviceMode; // A Pointer to a TDeviceMode structure
    begin
      { First obtain a handle to the TPrinter's DeviceMode structure }
      Printer.GetPrinter(ADevice, ADriver, APort, DeviceHandle);
      { If DeviceHandle is still 0, then the driver was not loaded. Set
        the printer index to force the printer driver to load making the
        handle available }
      if DeviceHandle = 0 then begin
        Printer.PrinterIndex := Printer.PrinterIndex;
        Printer.GetPrinter(ADevice, ADriver, APort, DeviceHandle);
      end;
      { If DeviceHandle is still 0, then an error has occurred. Otherwise,
        use GlobalLock() to get a pointer to the TDeviceMode structure }
      if DeviceHandle = 0 then
        Raise Exception.Create('Could Not Initialize TDeviceMode structure');
      DevMode := GlobalLock(DeviceHandle);
      try
        with DevMode^ do begin
          dmFields := DM_DEFAULTSOURCE or DM_ORIENTATION;
          dmDefaultSource := ToBin;
          case ToOrientation of
            poPortrait: dmOrientation := DMORIENT_PORTRAIT;
            poLandscape: dmOrientation := DMORIENT_LANDSCAPE;
          end;
        end;
      finally
        GlobalUnlock(DeviceHandle);
      end;
    end;
    quelqu'un sait-il comment faire ?
    merci

    ben

  2. #2
    Membre Expert

    Homme Profil pro
    Retraité
    Inscrit en
    Novembre 2007
    Messages
    3 535
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 64
    Localisation : France, Rhône (Rhône Alpes)

    Informations professionnelles :
    Activité : Retraité

    Informations forums :
    Inscription : Novembre 2007
    Messages : 3 535
    Par défaut
    Je pense que ça doit être possible avec WMI

    Un outil pratique pour ça: https://theroadtodelphi.wordpress.co...-code-creator/

  3. #3
    Invité
    Invité(e)
    Par défaut
    je connais pas wmi, j'ai regardais un peu de quoi il s'agissait, l'outil n'a pas l'air évident à utiliser

  4. #4
    Rédacteur/Modérateur

    Avatar de SergioMaster
    Homme Profil pro
    Développeur informatique retraité
    Inscrit en
    Janvier 2007
    Messages
    15 736
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 69
    Localisation : France, Loire Atlantique (Pays de la Loire)

    Informations professionnelles :
    Activité : Développeur informatique retraité
    Secteur : Industrie

    Informations forums :
    Inscription : Janvier 2007
    Messages : 15 736
    Billets dans le blog
    65
    Par défaut
    Bonjour,
    point besoin de WMI.
    C'est un peu vieux pour moi (ante 2010) mais voici une réponse que j'avais fournie
    http://www.developpez.net/forums/d95...ersonnalisees/

    les mots clés importants : DC_BINNAMES,DC_BINS

  5. #5
    Invité
    Invité(e)
    Par défaut
    super merci !

    cela m'a permis de trouver ce code :

    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
    uses
      WinSpool, Printers;
     
    procedure GetPaperBins(sl: TStrings);
    type
      TBinName      = array [0..23] of Char;
      TBinNameArray = array [1..High(Integer) div SizeOf(TBinName)] of TBinName;
      PBinnameArray = ^TBinNameArray;
      TBinArray     = array [1..High(Integer) div SizeOf(Word)] of Word;
      PBinArray     = ^TBinArray;
    var
      Device, Driver, Port: array [0..255] of Char;
      hDevMode: THandle;
      i, numBinNames, numBins, temp: Integer;
      pBinNames: PBinnameArray;
      pBins: PBinArray;
    begin
      Printer.PrinterIndex := -1;
      Printer.GetPrinter(Device, Driver, Port, hDevmode);
      numBinNames := WinSpool.DeviceCapabilities(Device, Port, DC_BINNAMES, nil, nil);
      numBins     := WinSpool.DeviceCapabilities(Device, Port, DC_BINS, nil, nil);
      if numBins <> numBinNames then
      begin
        raise Exception.Create('DeviceCapabilities reports different number of bins and bin names!');
      end;
      if numBinNames > 0 then
      begin
        pBins := nil;
        GetMem(pBinNames, numBinNames * SizeOf(TBinname));
        GetMem(pBins, numBins * SizeOf(Word));
        try
          WinSpool.DeviceCapabilities(Device, Port, DC_BINNAMES, PChar(pBinNames), nil);
          WinSpool.DeviceCapabilities(Device, Port, DC_BINS, PChar(pBins), nil);
          sl.Clear;
          for i := 1 to numBinNames do
          begin
            temp := pBins^[i];
            sl.addObject(pBinNames^[i], TObject(temp));
          end;
        finally
          FreeMem(pBinNames);
          if pBins <> nil then
            FreeMem(pBins);
        end;
      end;
    end;
     
     
    procedure TForm1.Button1Click(Sender: TObject);
    begin
      GetPaperBins(Listbox1.Items);
    end;
    je devrais me débrouiller avec ça

  6. #6
    Invité
    Invité(e)
    Par défaut
    le bouton "Résolu" n'apparait pas pour que je puisse clôturer ce post

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

Discussions similaires

  1. Utilisation des bacs imprimantes
    Par verdurand dans le forum AS/400
    Réponses: 4
    Dernier message: 21/08/2007, 15h29
  2. Bac imprimante Excel
    Par AlAIN01 dans le forum Macros et VBA Excel
    Réponses: 1
    Dernier message: 02/09/2006, 12h24
  3. [C#] Choix bac imprimante
    Par JuJu° dans le forum Windows Forms
    Réponses: 2
    Dernier message: 28/07/2006, 18h45
  4. Changer de bac imprimante...
    Par asenaici dans le forum Langage
    Réponses: 1
    Dernier message: 04/05/2006, 14h14

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