需要打印假脱机作业取消消息或回调 [英] Print spooler job cancellation message or callback wanted
问题描述
背景:
我现在正在尝试通过 GDI Print API,它看起来像这样:
StartDoc(hDC,&docinfo)
foreach page in page_buf
StartPage(hDC)
/* write the page to printer DC */
EndPage(hDC)
EndDoc(hDC)
问题:
在打印过程中会有一个通知区域图标,点击它会出现一个小窗口,显示指定打印机上的当前打印作业.
通过右键单击打印作业并选择Cancel
,将取消打印作业.但是我的应用程序会继续向打印机 DC 发送数据,直到处理完所有页面,并且状态在完成之前一直显示 Deleting - Spooling
.
我想要的是在选择取消后立即停止打印过程.
The Problem:
During printing there would be a notification area icon, and by clicking on it there would be a small window showing current printing jobs on a specified printer.
By right-clicking on a printing job and choosing Cancel
, a printing job shall be cancelled. But my application continues sending data to the printer DC until all pages are processed, and the status keeps showing Deleting - Spooling
before it finishes.
What I want is to stop the printing procedure right after choosing to cancel it.
我尝试过的:
1.首先我认为取消作业后设备内容会失效(这当然不是真的),并尝试检查StartPage
和 EndPage
.然后我发现他们在取消打印作业后都没有失败.
2. 我也试过 SetAbortProc
和 DocumentEvent
,发现它们不是我想要的.
What I've tried:
1. First I thought the device content would get invalid after cancelling the job (that's of course not true), and tried to examine the return values of StartPage
and EndPage
. Then I found they both don't fail after the cancellation of printing job.
2. I've also tried SetAbortProc
and DocumentEvent
, and found they're not what I want.
但是我想应该有某种机制可以在打印作业被取消时指示我的应用程序.如果有人尝试提供帮助,我们将不胜感激.
But I suppose there shall be some mechanism to indicate my application when the printing job is cancelled. It would be appreciated if someone tries to help.
推荐答案
做您想做的事情的唯一方法是使用 GetJob 函数 并终止循环.您想要的逻辑如下所示:
The only way to do what you want is to query the print job using the GetJob function and terminate your loop. The logic you want looks like this:
JOB_INFO_1 ji;
GetJob(...);
if (ji.Status & (JOB_STATUS_DELETED | JOB_STATUS_DELETING))
break;
这篇关于需要打印假脱机作业取消消息或回调的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!