Printer_status_offline

Utilisateur anonyme - 8 févr. 2019 à 11:03
papyvore Messages postés 223 Date d'inscription samedi 15 novembre 2003 Statut Membre Dernière intervention 16 décembre 2021 - 21 févr. 2019 à 16:06
Bonjour à tous;
Voilà mon problème,
Je réaffiche dans mes Labels, les infos de mon imprimante.
Nom imprimante par défaut, Port, Travaux en cours, ça marche bien.
Je modifie l'imprimante par défaut également.
Mais, je n'arrive pas à afficher dans mon label4, si l'imprimante est allumée ou pas.
c'est: printer_status_offline m'affiche 128 , soit PrinterInfo.Status , m'affiche 0;
en permanence, que l'imprimante soit allumée ou non

Label4.Caption := IntToStr(PrinterInfo.Status);


Tous les codes que j'ai essayé ne fonctionnent pas , je pense, que ce sont des vieux codes avec des ports LPT.
Le port de mon imprimante est : Port USB002,
Je pense que le problème vient de là.
En vous remercient pour votre aide.
Bon codding à tous

4 réponses

papyvore Messages postés 223 Date d'inscription samedi 15 novembre 2003 Statut Membre Dernière intervention 16 décembre 2021 15
Modifié le 9 févr. 2019 à 12:11
Salut
essais ça ,marche chez moi avec une imprimante whifi
procedure TForm1.Button2Click(Sender: TObject);
var
  status: dword;
  function GetCurrentPrinterStatus: dword;
  var
    hPrinter: THandle;
    Device: array [0 .. 255] of char;
    Driver: array [0 .. 255] of char;
    Port: array [0 .. 255] of char;
    hDeviceMode: THandle;
    bytesNeeded: Cardinal;
    pPI: PPrinterInfo2;
    Defaults: TPrinterDefaults;
  begin
    Assert(Printer.PrinterIndex >= 0);
    Printer.GetPrinter(Device, Driver, Port, hDeviceMode);
    FillChar(Defaults, Sizeof(Defaults), 0);
    Defaults.DesiredAccess := PRINTER_ACCESS_ADMINISTER or PRINTER_ACCESS_USE;
    Win32Check(WinSpool.OpenPrinter(@Device, hPrinter, @Defaults));
    try
      WinSpool.GetPrinter(hPrinter, 2, Nil, 0, @bytesNeeded);
      GetMem(pPI, bytesNeeded);
      try
        Win32Check(WinSpool.GetPrinter(hPrinter, 2, pPI, bytesNeeded,
          @bytesNeeded));
        Result := pPI^.status;
      finally
        FreeMem(pPI);
      end;
    finally
      WinSpool.ClosePrinter(hPrinter);
    end;
  end;

begin
  status := GetCurrentPrinterStatus;
  if (status and PRINTER_STATUS_OFFLINE) <> 0 then
    ShowMessage('offline')
  else
    ShowMessage('online');
end;

a adapter a ton besoin

1
Utilisateur anonyme
9 févr. 2019 à 18:33
Bonsoir Papyvore;
Un grand merci pour ton aide.
Je vais essayer ton code et je te dirais ce qu'il en est.
Merci à toi bonne soirée
Cordialement
0
Utilisateur anonyme
10 févr. 2019 à 11:08
Bonjour Papyvore;
J'ai testé ton code, seul le message on line s'affiche.
Que l'imprimante soit allumée ou non
cordialement
0
papyvore Messages postés 223 Date d'inscription samedi 15 novembre 2003 Statut Membre Dernière intervention 16 décembre 2021 15
10 févr. 2019 à 15:17
bizarre, ça marche chez moi quel delphi ?
tu peux changer
if (status and PRINTER_STATUS_OFFLINE) <> 0 then
voilà mon code
begin
Status := GetCurrentPrinterStatus;
if (Status = PRINTER_STATUS_OFFLINE) then //<> 0 then
begin
// ShowMessage('offline') ;
MessageDlg('Acunes imprimantes actives', mtWarning, [mbOK], 0);
end
else
begin
// ShowMessage('online');

end;
end;
0
Merci pour ton aide,
j'ai essayé ton dernier post, Status_Off_Line ne fonctionne pas.
Mais, j'ai TROUVÉ !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

Voici ma solution:

var
  Form1: TForm1;
  Device : array[0..255] of char;
  Driver : array[0..255] of char;
  Port   : array[0..255] of char;
  hPrinter: THandle;
  hDeviceMode: THandle;
  pcbNeed: DWORD;
  Buffer: Pointer;


procedure TForm1.Button1Click(Sender: TObject);
begin
Printer.GetPrinter(Device, Driver, Port, hDeviceMode);

if not OpenPrinter(@Device, hPrinter, nil) then Exit;
if (OpenPrinter(@Device, hPrinter, nil)) then
  begin
  Try
  GetPrinter(hPrinter, 2, nil,0,@pcbNeed);
  GetMem(Buffer, pcbNeed);

  if GetPrinter(hPrinter, 2, Buffer, pcbNeed, @pcbNeed) then
  begin
  Edit1.Text:= TPrinterInfo2A(Buffer^).pPrinterName;

     if (TPrinterInfo2A(Buffer^).Attributes and PRINTER_ATTRIBUTE_WORK_OFFLINE = PRINTER_ATTRIBUTE_WORK_OFFLINE) then
      begin
      Showmessage('l''imprimante est éteinte.');
      Exit;
      end
      Else
      showmessage('l''imprimante est allumée.');

  end;
  Finally
  FreeMem(Buffer, pcbNeed);
  End;
end;
End;
0
papyvore Messages postés 223 Date d'inscription samedi 15 novembre 2003 Statut Membre Dernière intervention 16 décembre 2021 15
21 févr. 2019 à 16:06
Salut
en effet mon code est nul. Il ne marche pas .j'ai donc voulu utiliser le tient,
là j'ai un problème quelle soit allumée ou éteinte j'ai toujours la même réponse
"allumée"????
TPrinterInfo2A(Buffer^).Attributes
a toujours la même valeur(2624) dans les 2 cas (mon imprimante est en wifi).
Une idée ??
0
Rejoignez-nous