大家好,請教一個技術問題
我用WinDDK里面的bitmap原始碼編譯出來的列印機驅動,怎么樣獲取到當前列印任務的名稱?
uj5u.com熱心網友回復:
OpenPrinter 后 EnumJobs 或 GetJob參考 msdn 的例子
BOOL ListJobsForPrinter( LPTSTR szPrinterName )
{
HANDLE hPrinter;
DWORD dwNeeded, dwReturned, i;
JOB_INFO_1 *pJobInfo;
// You need a printer handle, open the printer
if( ! OpenPrinter( szPrinterName, &hPrinter, NULL ) )
return FALSE;
// First you call EnumJobs() to find out how much memory you need
if( ! EnumJobs( hPrinter, 0, 0xFFFFFFFF, 1, NULL, 0, &dwNeeded,
&dwReturned ) )
{
// It should have failed, but if it failed for any reason other
// than "not enough memory", you should bail out
if( GetLastError() != ERROR_INSUFFICIENT_BUFFER )
{
ClosePrinter( hPrinter );
return FALSE;
}
}
// Allocate enough memory for the JOB_INFO_1 structures plus
// the extra data - dwNeeded from the previous call tells you
// the total size needed
if( (pJobInfo = (JOB_INFO_1 *)malloc( dwNeeded )) == NULL )
{
ClosePrinter( hPrinter );
return FALSE;
}
// Call EnumJobs() again and let it fill out our structures
if( ! EnumJobs( hPrinter, 0, 0xFFFFFFFF, 1, (LPBYTE)pJobInfo,
dwNeeded, &dwNeeded, &dwReturned ) )
{
ClosePrinter( hPrinter );
free( pJobInfo );
return FALSE;
}
// You're done with the printer handle, close it
ClosePrinter( hPrinter );
// dwReturned tells how many jobs there are
// Here, you'll simply display the number of jobs found
printf( "%d jobs\n", dwReturned );
// It's easy to loop through the jobs and access each one
for(i=0;i<dwReturned;i++)
{
// pJobInfo[i] is a JOB_INFO_1 struct for that job
// so here you could do whatever you want for each job
printf( "[%d] [%s]\n", pJobInfo[i].JobId, pJobInfo[i].pDocument );
}
// Clean up
free( pJobInfo );
return TRUE;
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/73838.html
標籤:硬件/系統
上一篇:VC/MFC從串口中讀取許多組數,怎樣篩選其中的某幾組資料
下一篇:用GDI+的效率問題
