共用方式為


作業管理

重要

建議您使用 Microsoft 的 IPP 收件匣類別驅動程式以及 Print Support Apps () ,來自定義印表機裝置開發 Windows 10 和 11 中的列印體驗。

如需詳細資訊,請參閱 列印支援應用程式設計指南

作業管理功能已在 Windows 8.1 和更新版本的 Windows 中引進,以提供作業佇列的即時檢視。

這項功能也可讓用戶端取消列印作業。 用戶端可以從 UWP 裝置應用程式或印表機擴充功能內呼叫適當的程式設計介面。

新的介面

Windows 8.1 中引進了下列介面,以實作作業管理功能。

IPrinterQueue2

IPrinterQueueView

IPrinterQueueViewEvent

IPrintJob

IPrintJobCollection

起始作業管理會話

若要起始作業管理工作階段,您必須先指定並要求您想要管理的作業範圍。 此範圍的作業稱為「檢視」,您可以使用 IPrinterQueue2::GetPrinterQueueView 方法來指定它。

如果您想要變更檢視來監視一組不同的作業,您可以使用 IPrinterQueueView::SetViewRange 方法來執行此動作。

請注意,列印佇列是動態佇列。 因此,每次列印佇列的狀態變更時,都會引發事件,而 IPrinterQueueViewEvent::OnChanged 方法會提供要求的檢視更新快照集。

下列 C# 代碼段說明如何使用新的介面來起始作業管理會話。

void PerformJobManagement(IPrinterQueue2 queue)
{
    //
    // Create a printer queue view and specify the range of
    // print queue positions to be monitored
    //

    PrinterQueueView queueView = queue.GetPrinterQueueView(0, COUNT_JOBS_MONITORED);

    //
    // Add the event handler to the IPrinterQueueView object via the 
    // standard COM event model, the IConnectionPoint mechanism.
    //

    queueView.OnChanged += queueView_OnChanged;


    //
    // When a different range of print jobs needs to be monitored, 
    // reset/update the view.
    //

    queueView.SetViewRange(20, COUNT_JOBS_MONITORED);

}

//
// Create an event handler that is called when
// there is a change in the View
//
void queueView_OnChanged(
    IPrintJobCollection pcollection,
    uint ulviewOffset,
    uint ulviewSize,
    uint ulcountJobsInPrintQueue)
{
    foreach (IPrintJob job in pCollection)
    {
        UIDisplay(job.Name);
        UIDisplay(job.Id);
    }
}

UIDisplay 是針對您為向使用者顯示資訊而開發的機制,使用泛型名稱。

此外,請注意,作業列舉會在新增第一個事件處理程式時啟動,並在移除最後一個事件處理程式時停止。

IPrinterQueue2

IPrinterQueueView

IPrinterQueueViewEvent

IPrintJob

IPrintJobCollection