用GetPrinter这个Win32 API,使用PRINTER_INFO_2结构参数,就可以取回打印机状态。
解决方案 »
- 根据报表的自定义纸张,如何控制打印机来切换纸张?
- 请问TOOLBUTTON控件在哪里?
- spcomm串口通讯
- 我现在有一个delphi开发的日文exe程序,需要汉化成中文菜单
- 请教一个关于ide的问题
- 100分的简单问题,答对的明天结账!
- 关于办公室自动化(OA)的议题,来者有分,不够可另开贴给分
- 各位介绍点delphi的书吧(原来我学delphi的,特喜欢这里,给点意见把)
- 一个简单的问题
- 各位高手,那里有关于delphi6所有控件的介绍啊?
- 如何改变编译后的exe文件的图标,默认的难看死了。5分,本人长期在线,先答先得。
- 求救:请问TFocusPanel,TMsoficeCaption,TLEDClock都指的到底是什么控件?
type JOB_INFO_1_ARRAY = Array of JOB_INFO_1;
Function GetSpoolerJobs(sPrinterName : String) : JOB_INFO_1_ARRAY;
var
i : Integer;
hPrinter : THandle;
bResult : Boolean;
cbBuf : DWORD;
pcbNeeded : DWORD;
pcReturned : DWORD;
aJobs : Array[0..99] of JOB_INFO_1;
begin
cbBuf := 1000; bResult := OpenPrinter(PChar(sPrinterName), hPrinter, Nil);
if NOT bResult then begin
ShowMessage('Error opening the printer');
exit;
end; bResult := EnumJobs(hPrinter,0,Length(aJobs),1,@aJobs,cbBuf,pcbNeeded,pcReturned);
if NOT bResult then begin
ShowMessage('Error Getting Jobs information');
exit;
end; for i:=0 to pcReturned-1 do begin
if aJobs[i].pDocument <> Nil then begin
SetLength(Result, Length(Result)+1);
Result[Length(Result)-1] := aJobs[i];
end;
end;
end; 测试例子:
1- 创建工程有 StringGrid 和一个 Timer.
2- StringGrid 'ColCount' and “RowCount” 值为 20
3- Timer的 “Interval” 属性值 500.
4- “OnTime” 实践中写这个代码
procedure TForm1.Timer1Timer(Sender: TObject);
var
i, ii : Integer;
aJobs : JOB_INFO_1_ARRAY;
begin
for i:=0 to StringGrid1.ColCount-1 do
for ii:=0 to StringGrid1.RowCount-1 do StringGrid1.Cells[i,ii] := ''; aJobs := GetSpoolerJobs('\\ibmserver\HP LaserJet 1100');//正在打印的打印机名字,这里我的打印机时网打。这里你要自己改 for i:=0 to Length(aJobs)-1 do begin
StringGrid1.Cells[i,0] := aJobs[i].pPrinterName;
StringGrid1.Cells[i,1] := aJobs[i].pMachineName;
StringGrid1.Cells[i,2] := aJobs[i].pUserName;
StringGrid1.Cells[i,3] := aJobs[i].pDocument;
StringGrid1.Cells[i,4] := aJobs[i].pDatatype;
StringGrid1.Cells[i,5] := aJobs[i].pStatus;
StringGrid1.Cells[i,6] := IntToStr(aJobs[i].Status); case aJobs[i].Status of
JOB_STATUS_PAUSED: StringGrid1.Cells[i,6] := 'JOB_STATUS_PAUSED';
JOB_STATUS_ERROR: StringGrid1.Cells[i,6] := 'JOB_STATUS_ERROR';
JOB_STATUS_DELETING: StringGrid1.Cells[i,6] := 'JOB_STATUS_DELETING';
JOB_STATUS_SPOOLING: StringGrid1.Cells[i,6] := 'JOB_STATUS_SPOOLING';
JOB_STATUS_PRINTING: StringGrid1.Cells[i,6] := 'JOB_STATUS_PRINTING';
JOB_STATUS_OFFLINE: StringGrid1.Cells[i,6] := 'JOB_STATUS_OFFLINE';
JOB_STATUS_PAPEROUT: StringGrid1.Cells[i,6] := 'JOB_STATUS_PAPEROUT';
JOB_STATUS_PRINTED: StringGrid1.Cells[i,6] := 'JOB_STATUS_PRINTED';
JOB_STATUS_DELETED: StringGrid1.Cells[i,6] := 'JOB_STATUS_DELETED';
JOB_STATUS_BLOCKED_DEVQ: StringGrid1.Cells[i,6] := 'JOB_STATUS_BLOCKED_DEVQ';
JOB_STATUS_USER_INTERVENTION: StringGrid1.Cells[i,6] := 'JOB_STATUS_USER_INTERVENTION';
JOB_STATUS_RESTART: StringGrid1.Cells[i,6] := 'JOB_STATUS_RESTART';
JOB_POSITION_UNSPECIFIED: StringGrid1.Cells[i,6] := 'JOB_POSITION_UNSPECIFIED'; else StringGrid1.Cells[i,6] := 'Unknown status...';
end;
end; StringGrid1.Refresh;
end; 5- 运行程序,打印程序测之
OK ⌒_⌒
希望你能留下Email,小弟还有些问题想请教!