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