1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124
|
#include <Winspool.h>
bool GetNextJobPrinter(const char *szPrinterName,int &rnLocation,JOB_INFO_1 **pInfosJob)
{
DWORD cbBuf=0;
DWORD pcbNeeded=0,pcReturned=0;
HANDLE hPrinter;
CString strPrinterName=szPrinterName;
if(OpenPrinter(strPrinterName.GetBuffer(0),&hPrinter,NULL))
{
cbBuf=pcbNeeded=pcReturned=0;
EnumJobs(
hPrinter, // handle to printer object
rnLocation, // location of first job in print queue to enumerate
1, // number of jobs to enumerate
1, // structure level
(LPBYTE)NULL, // pointer to structure array
cbBuf, // size of array, in bytes
&pcbNeeded, // addr. of variable with no. of bytes copied (or required)
&pcReturned // addr. of variable with no. of job info. structures copied
);
if(pcbNeeded)
{
if(*pInfosJob==NULL)
*pInfosJob=reinterpret_cast<JOB_INFO_1 *>(malloc(pcbNeeded));
cbBuf=pcbNeeded;
EnumJobs(
hPrinter, // handle to printer object
rnLocation, // location of first job in print queue to enumerate
1, // number of jobs to enumerate
1, // structure level
reinterpret_cast<LPBYTE>(*pInfosJob), // pointer to structure array
cbBuf, // size of array, in bytes
&pcbNeeded, // addr. of variable with no. of bytes copied (or required)
&pcReturned // addr. of variable with no. of job info. structures copied
);
if(!pcReturned)
{
free(*pInfosJob);
*pInfosJob=NULL;
}
}
rnLocation++;
ClosePrinter(hPrinter);
}
else return false;
return (pcReturned!=0);
}
//--------------------------------------------------------------
bool FindJobPrinter(const char *szPrinterName,const char *szJobName,JOB_INFO_1 **pInfosJob)
{
DWORD cbBuf=0;
DWORD pcbNeeded=0,pcReturned=0;
HANDLE hPrinter;
bool bokjob=false;
int nojob=0;
CString Currentjob,jobName;
jobName=szJobName;
jobName.MakeUpper();
CString strPrinterName=szPrinterName;
if(OpenPrinter(strPrinterName.GetBuffer(0),&hPrinter,NULL))
{
do
{
cbBuf=pcbNeeded=pcReturned=0;
EnumJobs(
hPrinter, // handle to printer object
nojob, // location of first job in print queue to enumerate
1, // number of jobs to enumerate
1, // structure level
(LPBYTE)NULL, // pointer to structure array
cbBuf, // size of array, in bytes
&pcbNeeded, // addr. of variable with no. of bytes copied (or required)
&pcReturned // addr. of variable with no. of job info. structures copied
);
if(pcbNeeded)
{
if(*pInfosJob==NULL)
*pInfosJob=reinterpret_cast<JOB_INFO_1 *>(malloc(pcbNeeded));
cbBuf=pcbNeeded;
EnumJobs(
hPrinter, // handle to printer object
nojob, // location of first job in print queue to enumerate
1, // number of jobs to enumerate
1, // structure level
reinterpret_cast<LPBYTE>(*pInfosJob), // pointer to structure array
cbBuf, // size of array, in bytes
&pcbNeeded, // addr. of variable with no. of bytes copied (or required)
&pcReturned // addr. of variable with no. of job info. structures copied
);
if(pcReturned)
{
Currentjob=(*pInfosJob)->pDocument;
Currentjob.MakeUpper();
bokjob=(Currentjob==jobName);
}
}
nojob++;
if(bokjob) break;
free(*pInfosJob);
*pInfosJob=NULL;
}
while(pcbNeeded);
ClosePrinter(hPrinter);
}
return bokjob;
}
//---------------------------------------
JOB_INFO_1 *pInfosJob=NULL;
if(FindJobPrinter("My Printer HP","Microsoft Word - toto.doc",&pInfosJob))
{
// traitement
//.............
// liberation
free(pInfosJob);
} |
Partager