作业管理
重要
建议使用 Microsoft 的 IPP 收件箱类驱动程序,以及 Print Support Apps (PSA) ,在 Windows 10 和 11 中自定义打印体验,以便进行打印机设备开发。
有关详细信息,请参阅 打印支持应用设计指南。
Windows 8.1 及更高版本的 Windows 中引入了作业管理功能,可提供作业队列的实时视图。
此功能还允许客户端取消打印作业。 客户端可以从 UWP 设备应用或打印机扩展调用相应的编程接口。
新接口
Windows 8.1中引入了以下接口来实现作业管理功能。
启动作业管理会话
若要启动作业管理会话,必须先指定并请求要管理的作业范围。 此范围的作业称为“视图”,可以使用 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 是你开发的用于向用户显示信息的机制的通用名称。
另请注意,作业枚举在添加第一个事件处理程序时启动,并在删除最后一个事件处理程序时停止。
相关主题
反馈
https://aka.ms/ContentUserFeedback。
即将发布:在整个 2024 年,我们将逐步淘汰作为内容反馈机制的“GitHub 问题”,并将其取代为新的反馈系统。 有关详细信息,请参阅:提交和查看相关反馈