请问如何用VB或DEPHI后台监测是否有打印任务传到打印机? 应该用api函数,但我没试过,查查这方面的资料吧 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 得到当前打印任务队列以及任务状态,你只要循环检测测队列中的各任务,然后判断(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; } VB6.0 如何写代码关闭windows 7 系统? vb 和VBA怎么样整合开发? VB6许可证补丁下载,VB6滚轮补丁下载 菜鸟请问:如何对datagrid中当前选中行的某一列的内容进行修改! 请问一个简单的问题! 求助:调出VB源码 关于VB调用EXCEL表后,能否让EXCEL窗口保持最大,且不可调整? 自编的控件里的按纽为什么不能用unload me来退出窗口? 请问那有VS.NET中文正式版下? 怎样才能忘记一个自己喜欢的人?--一个工资微薄的半程序员的苦恼 如何得到系统剩余打印任务的数量? 考研是否要学士学位阿?我毕业时候被扣了学士,不知道还能否报考?回答者有分!!
以下是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;
}