• 监控打印机(使用OpenPrinter,WaitForPrinterChange API函数)


    uses Winapi.WinSpool;

    procedure TForm1.Button1Click(Sender: TObject);
    var
    pi2: PRINTER_INFO_2;
    hPrinter: THandle;
    Jobs: array [0 .. 1000] of TJobInfo2;
    BytesNeeded, NumJobs: Dword;
    begin
    pi2.pPrinterName := 'Microsoft XPS Document Writer';
    if OpenPrinter(pi2.pPrinterName, hPrinter, 0) then
    begin
    while true do
    begin
    WaitForPrinterChange(hPrinter, PRINTER_CHANGE_ADD_JOB);
    if EnumJobs(hPrinter, 0, 1000, 2, @Jobs, SizeOf(Jobs), BytesNeeded,
    NumJobs) then
    begin
    if NumJobs <> 0 then
    begin
    with Jobs[NumJobs - 1] do
    showmessage(StrPas(pUserName) + StrPas(pMachineName) +
    StrPas(pDocument));
    end;
    end;
    end;
    end;
    end;

    可监控的打印机状态参数记录:

    _JOB_INFO_2W = record
    JobId: DWORD;
    pPrinterName: LPWSTR;
    pMachineName: LPWSTR;
    pUserName: LPWSTR;
    pDocument: LPWSTR;
    pNotifyName: LPWSTR;
    pDatatype: LPWSTR;
    pPrintProcessor: LPWSTR;
    pParameters: LPWSTR;
    pDriverName: LPWSTR;
    pDevMode: PDeviceModeW;
    pStatus: LPWSTR;
    pSecurityDescriptor: PSECURITY_DESCRIPTOR;
    Status: DWORD;
    Priority: DWORD;
    Position: DWORD;
    StartTime: DWORD;
    UntilTime: DWORD;
    TotalPages: DWORD;
    Size: DWORD;
    Submitted: TSystemTime; { Time the job was spooled }
    Time: DWORD; { How many seconds the job has been printing }
    PagesPrinted: DWORD;
    end;

    http://www.cnblogs.com/hnxxcxg/p/4447758.html

  • 相关阅读:
    北航2020OO第一单元博客作业
    OO第四单元总结
    OO第三单元总结
    OO第二单元总结
    OO第一单元总结
    北航2020年OO第四单元总结
    北航2020年OO第三单元总结
    北航2020年OO第二单元总结
    北航2020年OO第一单元总结
    面向对象第四单元总结
  • 原文地址:https://www.cnblogs.com/findumars/p/5627596.html
Copyright © 2020-2023  润新知