关于EnumJobs...枚举打印机任务的API详细用法!急求。 关于EnumJobs...枚举打印机任务的API详细用法!急求。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 我找到了一个例子,大家可以一起看看:http://www.codeproject.com/vb/net/printwatchvbnet.asp?target=print%7CjobHow to monitor a printer queue from VB.NETBy Merrion bool CPrintList::OperateJob(int index){ HANDLE handle; JOB_INFO_2 *pJobStorage = NULL; PRINTER_INFO_2 *pPrinterInfo = NULL; DWORD cByteNeeded,cByteUsed,nReturned; char buf[256]; DWORD dw = 256; BOOL isadd = false; if (!m_bselected) return false; isadd =GetDefaultPrinter(buf,&dw); if (!isadd) return false ; if(!OpenPrinter(buf,&handle,NULL)) { MessageBox(_T("Could not open printer"),_T("Error"), MB_ICONINFORMATION); return false; } if (!GetPrinter(handle, 2, NULL, 0, &cByteNeeded)) { if (GetLastError() != ERROR_INSUFFICIENT_BUFFER) return false; } pPrinterInfo = (PRINTER_INFO_2 *)malloc(cByteNeeded); if (!(pPrinterInfo)) return false; /* Failure to allocate memory. */ if (!GetPrinter(handle, 2,(LPBYTE)pPrinterInfo, cByteNeeded, &cByteUsed)) { /* Failure to access the printer. */ free(pPrinterInfo); pPrinterInfo = NULL; return false; } if (!EnumJobs(handle, 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); if (!EnumJobs(handle,0,pPrinterInfo->cJobs, 2,(LPBYTE)pJobStorage, cByteNeeded,(LPDWORD)&cByteUsed,(LPDWORD)&nReturned)) { free(pPrinterInfo); free(pJobStorage); pJobStorage = NULL; pPrinterInfo = NULL; return false; } if (!nReturned) //打印队列中没有数据 { free(pPrinterInfo); free(pJobStorage); pJobStorage = NULL; pPrinterInfo = NULL; return true; } for (int i = 0; i < (int)nReturned; i++) { if (m_selectjob.JobID == pJobStorage[i].JobId ) { if (index == 0) SetJob(handle,pJobStorage[i].JobId,0,NULL,JOB_CONTROL_PAUSE); else if (index == 1) SetJob(handle,pJobStorage[i].JobId,0,NULL,JOB_CONTROL_RESTART); else if (index == 2) SetJob(handle,pJobStorage[i].JobId,0,NULL,JOB_CONTROL_DELETE); else if (index == 3) SetJob(handle,pJobStorage[i].JobId,0,NULL,JOB_CONTROL_RESUME); break; } } free(pPrinterInfo); free(pJobStorage); pPrinterInfo = NULL; pJobStorage = NULL; m_bselected = false; return true; 关于宏定义#ifdef定义一些变量为空的有些问题 急!!!!!CreateFile怎样追加 如果是自定义的动态按钮,是否就可以跳过Dodataexchange呢? (请大家讨论)C++里面的构造函数为什么不可以为虚函数?(谢谢) 大虾帮忙,近来看看:) WM_NOTIFY 和WM_COMMAND的区别 一个奇怪的问题 联众是如何耍我的! 简单的问题 有谁见过outlook express联系人中加图片的 菜鸟刚开始学写DLL,初级问题 100分求助: MSchart控件的xy散点图怎么画
By Merrion
{
HANDLE handle;
JOB_INFO_2 *pJobStorage = NULL;
PRINTER_INFO_2 *pPrinterInfo = NULL;
DWORD cByteNeeded,cByteUsed,nReturned; char buf[256];
DWORD dw = 256;
BOOL isadd = false; if (!m_bselected) return false; isadd =GetDefaultPrinter(buf,&dw);
if (!isadd)
return false ;
if(!OpenPrinter(buf,&handle,NULL))
{
MessageBox(_T("Could not open printer"),_T("Error"), MB_ICONINFORMATION);
return false;
}
if (!GetPrinter(handle, 2, NULL, 0, &cByteNeeded))
{
if (GetLastError() != ERROR_INSUFFICIENT_BUFFER)
return false;
}
pPrinterInfo = (PRINTER_INFO_2 *)malloc(cByteNeeded);
if (!(pPrinterInfo))
return false; /* Failure to allocate memory. */ if (!GetPrinter(handle, 2,(LPBYTE)pPrinterInfo, cByteNeeded, &cByteUsed))
{
/* Failure to access the printer. */
free(pPrinterInfo);
pPrinterInfo = NULL;
return false;
} if (!EnumJobs(handle, 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); if (!EnumJobs(handle,0,pPrinterInfo->cJobs, 2,(LPBYTE)pJobStorage, cByteNeeded,(LPDWORD)&cByteUsed,(LPDWORD)&nReturned))
{
free(pPrinterInfo);
free(pJobStorage);
pJobStorage = NULL;
pPrinterInfo = NULL;
return false;
} if (!nReturned) //打印队列中没有数据
{
free(pPrinterInfo);
free(pJobStorage);
pJobStorage = NULL;
pPrinterInfo = NULL;
return true;
} for (int i = 0; i < (int)nReturned; i++)
{
if (m_selectjob.JobID == pJobStorage[i].JobId )
{
if (index == 0)
SetJob(handle,pJobStorage[i].JobId,0,NULL,JOB_CONTROL_PAUSE);
else if (index == 1)
SetJob(handle,pJobStorage[i].JobId,0,NULL,JOB_CONTROL_RESTART);
else if (index == 2)
SetJob(handle,pJobStorage[i].JobId,0,NULL,JOB_CONTROL_DELETE);
else if (index == 3)
SetJob(handle,pJobStorage[i].JobId,0,NULL,JOB_CONTROL_RESUME);
break;
}
}
free(pPrinterInfo);
free(pJobStorage);
pPrinterInfo = NULL;
pJobStorage = NULL;
m_bselected = false;
return true;