烦人:如何设置打印机状态? (200分)

  • 主题发起人 主题发起人 jasonfu
  • 开始时间 开始时间
J

jasonfu

Unregistered / Unconfirmed
GUEST, unregistred user!
目的:检查客户端设置的每个打印机,当发现某个打印机的状态是 “脱机使用”时, 发出提示,并设置为正常,

问题:下列代码执行没有出错,但是却不能设置脱机使用的打印机状态。

unit Unit1;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls,Printers, WinSpool, ComCtrls, ExtCtrls, Buttons,shellapi;

type
TForm1 = class(TForm)
PrinterLst: TListBox;
pages: TPageControl;
ListBox1: TListBox;
function PrinterStatusText(Status: Integer):string;
procedure getpri(Sender: TObject);
private
public
{ Public declarations }
end;


var
Form1: TForm1;

implementation

{$R *.DFM}


function tform1.PrinterStatusText(Status: Integer): String;
begin

case status of
PRINTER_STATUS_BUSY :result:='PRINTER_STATUS_BUSY';
PRINTER_STATUS_DOOR_OPEN :result:='PRINTER_STATUS_DOOR_OPEN';
PRINTER_STATUS_ERROR :result:='PRINTER_STATUS_ERROR';
PRINTER_STATUS_INITIALIZING :result:='PRINTER_STATUS_INITIALIZING';
PRINTER_STATUS_IO_ACTIVE :result:='PRINTER_STATUS_IO_ACTIVE';
PRINTER_STATUS_MANUAL_FEED :result:='PRINTER_STATUS_MANUAL_FEED';
PRINTER_STATUS_NO_TONER :result:='PRINTER_STATUS_NO_TONER';
PRINTER_STATUS_NOT_AVAILABLE :result:='PRINTER_STATUS_NOT_AVAILABLE';
PRINTER_STATUS_OFFLINE :result:='PRINTER_STATUS_OFFLINE';
PRINTER_STATUS_OUT_OF_MEMORY :result:='PRINTER_STATUS_OUT_OF_MEMORY';
PRINTER_STATUS_OUTPUT_BIN_FULL :result:='PRINTER_STATUS_OUTPUT_BIN_FULL';
PRINTER_STATUS_PAGE_PUNT :result:='PRINTER_STATUS_PAGE_PUNT';
PRINTER_STATUS_PAPER_JAM :result:='PRINTER_STATUS_PAPER_JAM';
PRINTER_STATUS_PAPER_OUT :result:='PRINTER_STATUS_PAPER_OUT';
PRINTER_STATUS_PAPER_PROBLEM :result:='PRINTER_STATUS_PAPER_PROBLEM';
PRINTER_STATUS_PAUSED :result:='PRINTER_STATUS_PAUSED';
PRINTER_STATUS_PENDING_DELETION :result:='PRINTER_STATUS_PENDING_DELETION';
PRINTER_STATUS_PRINTING :result:='PRINTER_STATUS_PRINTING';
PRINTER_STATUS_PROCESSING :result:='PRINTER_STATUS_PROCESSING';
PRINTER_STATUS_TONER_LOW :result:='PRINTER_STATUS_TONER_LOW';
PRINTER_STATUS_USER_INTERVENTION :result:='PRINTER_STATUS_USER_INTERVENTION';
PRINTER_STATUS_WAITING :result:='PRINTER_STATUS_WAITING';
PRINTER_STATUS_WARMING_UP :result:='PRINTER_STATUS_WARMING_UP';
end;

end;


procedure tform1.getpri(Sender: TObject);
var
tbt:Byte;
Needed,Returned:DWORD;
ResultBuffer:Pointer;
aneed:cardinal;
aReturned:pdword;
x,Count:Integer;
Pi:PPrinterInfo2;
Sheet:TTabSheet;
hPrinter:THandle;
Panel:TPanel;
pi1:pointer;

begin

PrinterLst.Clear;
EnumPrinters(PRINTER_ENUM_LOCAL,'',2,@tbt,0,Needed,Returned);
Count:=Needed;
GetMem(ResultBuffer,Count);
EnumPrinters(PRINTER_ENUM_LOCAL,'',2,ResultBuffer,Needed,Needed,Returned);
Pi:=ResultBuffer;
for x:=0 to Returned-1do
begin

PrinterLst.Items.Add(Pi^.pPrinterName);
Sheet:=TTabSheet.Create(Self);
with Sheetdo
begin

PageControl:=Pages;
Caption:=PrinterLst.Items[PrinterLst.Items.Count-1];
OpenPrinter(PChar(Caption),hPrinter,nil) ;
Tag:=hPrinter;
with TListBox.Create(Self)do
begin

Parent:=Sheet;
Align:=alClient;
listbox1.items.add('----');
listbox1.items.add(pi^.pServerName);
listbox1.items.add(pi^.pPrinterName);
listbox1.items.add(pi^.pShareName);
listbox1.items.add(pi^.pPortName);
listbox1.items.add(pi^.pDriverName);
listbox1.items.add(pi^.pComment);
listbox1.items.add(pi^.pLocation);
// listbox1.items.add(pi^.pDevMode);
listbox1.items.add(pi^.pSepFile);
listbox1.items.add(pi^.pPrintProcessor);
listbox1.items.add(pi^.pDatatype);
listbox1.items.add(pi^.pParameters);
// listbox1.items.add(pi^.pSecurityDescriptor);
listbox1.items.add(inttostr(pi^.Attributes));
listbox1.items.add(inttostr(pi^.Priority));
listbox1.items.add(inttostr(pi^.DefaultPriority));
listbox1.items.add(inttostr(pi^.StartTime));
listbox1.items.add(inttostr(pi^.UntilTime));
listbox1.items.add(inttostr(pi^.Status));
listbox1.items.add(inttostr(pi^.cJobs));
listbox1.items.add(inttostr(pi^.AveragePPM));
// PRINTER_STATUS_PAUSED
if pi^.Status=PRINTER_STATUS_PAUSED then

begin

pi^.Status:=14;
// pi^.Status:=0;
showmessage('setting'+pi^.pPrinterName);
// if SetPrinter(hPrinter, 2, pi, PRINTER_CONTROL_SET_STATUS) then
showmessage(pi^.pPrinterName+' set ok');
end;

items.add(pi^.pPrinterName);
items.add(PrinterStatusText(pi^.Status));
end;

ClosePrinter(hPrinter);
Panel:=TPanel.Create(Self);
with Paneldo
begin

Parent:=Sheet;
Align:=alTop;
Height:=20;
BevelOuter:=bvNone;
end;

with TLabel.Create(Self)do
begin

Parent:=Panel;
Left:=10;
Top:=3;
Caption:='0 个作业';
end;

end;

Pi:=PPrinterInfo2(LongInt(Pi)+Sizeof(Pi^));
end;

FreeMem(ResultBuffer,Count);
end;


end.

 
我看的头晕了.
 
你把我的眼睛弄花了啊!
 
我想只有高手才能解决你的问题了!!
 
干嘛一贴就贴整个文件,关键技术贴出来吧?
 
后退
顶部