给你个简单的吧。FindFirstPrinterChangeNotification的,我就不发了。这里全有。
procedure TPrinterStateThread_9x.Execute;
const
LastJob = 9;
var
i: Integer;
Jobs: ^TJobInfo2A;
Size, NumJobs, BytesNeeded: Cardinal;
begin
while not Terminated do
begin
{
Temp_Str := Get_Printer_State(FPrinter_HWnd);
if Temp_Str <> '' then FLabel.Caption := FPrinter_Name + ' - ' + Temp_Str;
}
EnumJobs(FPrinter_HWnd, 0, LastJob, 2, Jobs, 0, Size, NumJobs);
if Size = 0 then Continue;
GetMem(Jobs, Size);
try
if EnumJobs(FPrinter_HWnd, 0, LastJob, 2, Jobs, Size, BytesNeeded, NumJobs) then
begin
for i := 0 to NumJobs - 1 do
with Jobs^ do
begin
UpdateListView(Jobs^);
Inc(Jobs);
end;
end
else //取得打印队列出错
PostMessage(FMain_Form, WM_USER_Message, 0, GetLastError);
finally
Dec(Jobs, NumJobs);
FreeMem(Jobs);
end;
end;
WinSpool.ClosePrinter(FPrinter_HWnd);
end;