应该用api函数,但我没试过,查查这方面的资料吧

解决方案 »

  1.   

    得到当前打印任务队列以及任务状态,你只要循环检测测队列中的各任务,然后判断(pJobStorage[i].Status == JOB_STATUS_PRINTED)是否打印完成,接下来就处理自己的事情就是了。注意怎样使用API函数EnumJobs得到JOB_INFO_2结构以及怎样使用API函数GetPrinter得到PRINTER_INFO_2结构。
    以下是MSDN例程:
       BOOL GetJobs(HANDLE hPrinter,        /* handle to the printer */
                    JOB_INFO_2 **ppJobInfo, /* pointer to be filled  */
                    int *pcJobs,            /* count of jobs filled  */
                    DWORD *pStatus)         /* print Queue status    */
       {
           DWORD               cByteNeeded,
                               nReturned,
                               cByteUsed;
           JOB_INFO_2          *pJobStorage = NULL;
           PRINTER_INFO_2       *pPrinterInfo = NULL;   /* Get the buffer size needed */
           if (!GetPrinter(hPrinter, 2, NULL, 0, &cByteNeeded))
           {
               if (GetLastError() != ERROR_INSUFFICIENT_BUFFER)
                   return FALSE;
           }       pPrinterInfo = (PRINTER_INFO_2 *)malloc(cByteNeeded);
           if (!(pPrinterInfo))
               /* failure to allocate memory */
               return FALSE;       /* get the printer info */
           if (!GetPrinter(hPrinter,
                   2,
                   (LPSTR)pPrinterInfo,
                   cByteNeeded,
                   &cByteUsed))
           {
               /* failure to access the printer */
               free(pPrinterInfo);
               pPrinterInfo = NULL;
               return FALSE;
           }       /* Get job storage space */
           if (!EnumJobs(hPrinter,
                   0,
                   pPrinterInfo->cJobs,
                   2,
                   NULL,
                   0,
                   (LPDWORD)&cByteNeeded,
                   (LPDWORD)&nReturned))
           {
               if (GetLastError() != ERROR_INSUFFICIENT_BUFFER)
               {
                   free(pPrinterInfo);
                   pPrinterInfo = NULL;
                   return FALSE;
               }
           }       pJobStorage = (JOB_INFO_2 *)malloc(cByteNeeded);
           if (!pJobStorage)
           {
               /* failure to allocate Job storage space */
               free(pPrinterInfo);
               pPrinterInfo = NULL;
               return FALSE;
           }       ZeroMemory(pJobStorage, cByteNeeded);       /* get the list of jobs */
           if (!EnumJobs(hPrinter,
                   0,
                   pPrinterInfo->cJobs,
                   2,
                   (LPBYTE)pJobStorage,
                   cByteNeeded,
                   (LPDWORD)&cByteUsed,
                   (LPDWORD)&nReturned))
           {
               free(pPrinterInfo);
               free(pJobStorage);
               pJobStorage = NULL;
               pPrinterInfo = NULL;
               return FALSE;
           }       /*
            *  Return the information
            */
           *pcJobs = pPrinterInfo->cJobs;
           *pStatus = pPrinterInfo->Status;
           *ppJobInfo = pJobStorage;
           free(pPrinterInfo);       return TRUE;
       }