Print spooler job cancellation message or callback wanted

人走茶凉 提交于 2019-12-11 07:31:19

问题


Backgroud:
I'm now trying to print via GDI Print API, and it looks like this:

StartDoc(hDC,&docinfo)
foreach page in page_buf
    StartPage(hDC)
    /* write the page to printer DC */
    EndPage(hDC)
EndDoc(hDC)

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.

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.


回答1:


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;


来源:https://stackoverflow.com/questions/14164064/print-spooler-job-cancellation-message-or-callback-wanted

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!