質問

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.

役に立ちましたか?

解決

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;
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top