pankaj1782
December 4th, 2006, 06:09 AM
hi all,
I am trying to monitor the printer queue by using the Win32 Apis FindFirstPrinterChangeNotification and FindNextPrinterChangeNotification.
But, I am not getting two information....one is the no. of pages printed and the job completion indication.
For the first one I am setting the JOB_NOTIFY_FIELD_PAGES_PRINTED and for the second one JOB_NOTIFY_FIELD_STATUS is being used, in the required member of the PRINTER_NOTIFY_OPTIONS_TYPE structure.
In the case of no. of pages printed, i get correct values, if the document is more than 1 page, but always get 0 when the document is having a single page. why is this so?
And as regard the second thing the JOB_STATUS_PRINTED is never received. My code is as below:
void StartNotifications(void)
{
HANDLE hPrinter = NULL;
PRINTER_NOTIFY_OPTIONS * p_NotifyOptions = NULL;
PRINTER_NOTIFY_OPTIONS_TYPE arr_NotifyOptionsType[2];
PWORD pJobFields, pPrinterFields;
HANDLE hwndNotify = NULL;
DWORD dwChanged = 0;
PRINTER_NOTIFY_INFO * p_OutPut = NULL;
if(OpenPrinter(_T("\\\\NECHCLSTDC\\HP LaserJet 4345 mfp PCL 5e"), &hPrinter, NULL))
{
pJobFields = (PWORD)malloc(5 * sizeof(WORD));
pJobFields[0] = JOB_NOTIFY_FIELD_USER_NAME;
pJobFields[1] = JOB_NOTIFY_FIELD_PAGES_PRINTED;
pJobFields[2] = JOB_NOTIFY_FIELD_TOTAL_BYTES;
pJobFields[3] = JOB_NOTIFY_FIELD_STATUS;
pJobFields[4] = JOB_NOTIFY_FIELD_STATUS_STRING;
arr_NotifyOptionsType[0].Type = JOB_NOTIFY_TYPE ;
arr_NotifyOptionsType[0].pFields = pJobFields;
arr_NotifyOptionsType[0].Count = 5;
pPrinterFields = (PWORD)malloc(2 * sizeof(WORD));
pPrinterFields[0] = PRINTER_NOTIFY_FIELD_PRINTER_NAME;
pPrinterFields[1] = PRINTER_NOTIFY_FIELD_AVERAGE_PPM;
arr_NotifyOptionsType[1].Type = PRINTER_NOTIFY_TYPE ;
arr_NotifyOptionsType[1].pFields = pPrinterFields;
arr_NotifyOptionsType[1].Count = 2;
p_NotifyOptions = new PRINTER_NOTIFY_OPTIONS;
p_NotifyOptions->Count = 2;
p_NotifyOptions->Version = 2;
p_NotifyOptions->pTypes = arr_NotifyOptionsType;
p_NotifyOptions->Flags = PRINTER_NOTIFY_OPTIONS_REFRESH;
if((hwndNotify = FindFirstPrinterChangeNotification(hPrinter, 0, 0, p_NotifyOptions)) != INVALID_HANDLE_VALUE)
{
while(hwndNotify != INVALID_HANDLE_VALUE)
{
if(WaitForSingleObject(hwndNotify, 0) == WAIT_OBJECT_0)
{
FindNextPrinterChangeNotification(hwndNotify, &dwChanged, (LPVOID)p_NotifyOptions, (LPVOID*)&p_OutPut);
for (int i=0;i<p_OutPut->Count;i++)
{
if(p_OutPut->aData[i].Type == JOB_NOTIFY_TYPE)
{
if(p_OutPut->aData[i].Field == JOB_NOTIFY_FIELD_USER_NAME)
{
MessageBox(NULL,(LPTSTR)(p_OutPut->aData[i].NotifyData.Data.pBuf) ,_T("Status"),MB_OK);
}
if(p_OutPut->aData[i].Field == JOB_NOTIFY_FIELD_PAGES_PRINTED)
{
TCHAR buff[25];
_stprintf(buff,_T("PP = %d Job ID %ld"),p_OutPut->aData[i].NotifyData.adwData[0], p_OutPut->aData[i].Id);
MessageBox(NULL,buff ,_T("Status"),MB_OK);
}
if(p_OutPut->aData[i].Field == JOB_NOTIFY_FIELD_STATUS)
{
if(p_OutPut->aData[i].NotifyData.adwData[0] & JOB_STATUS_PRINTED)
MessageBox(NULL,_T("Job Done") ,_T("Status"),MB_OK);
}
if(p_OutPut->aData[i].Field == JOB_NOTIFY_FIELD_STATUS_STRING)
{
MessageBox(NULL,(LPTSTR)(p_OutPut->aData[i].NotifyData.Data.pBuf) ,_T("Status"),MB_OK);
}
}
}
}
}
}
else
{
DWORD dwError = GetLastError();
dwError += 0;
}
}
else
{
DWORD dwError = GetLastError();
dwError += 0;
}
}
It will be great if some one help me out with this...
Thanks
Pankaj
I am trying to monitor the printer queue by using the Win32 Apis FindFirstPrinterChangeNotification and FindNextPrinterChangeNotification.
But, I am not getting two information....one is the no. of pages printed and the job completion indication.
For the first one I am setting the JOB_NOTIFY_FIELD_PAGES_PRINTED and for the second one JOB_NOTIFY_FIELD_STATUS is being used, in the required member of the PRINTER_NOTIFY_OPTIONS_TYPE structure.
In the case of no. of pages printed, i get correct values, if the document is more than 1 page, but always get 0 when the document is having a single page. why is this so?
And as regard the second thing the JOB_STATUS_PRINTED is never received. My code is as below:
void StartNotifications(void)
{
HANDLE hPrinter = NULL;
PRINTER_NOTIFY_OPTIONS * p_NotifyOptions = NULL;
PRINTER_NOTIFY_OPTIONS_TYPE arr_NotifyOptionsType[2];
PWORD pJobFields, pPrinterFields;
HANDLE hwndNotify = NULL;
DWORD dwChanged = 0;
PRINTER_NOTIFY_INFO * p_OutPut = NULL;
if(OpenPrinter(_T("\\\\NECHCLSTDC\\HP LaserJet 4345 mfp PCL 5e"), &hPrinter, NULL))
{
pJobFields = (PWORD)malloc(5 * sizeof(WORD));
pJobFields[0] = JOB_NOTIFY_FIELD_USER_NAME;
pJobFields[1] = JOB_NOTIFY_FIELD_PAGES_PRINTED;
pJobFields[2] = JOB_NOTIFY_FIELD_TOTAL_BYTES;
pJobFields[3] = JOB_NOTIFY_FIELD_STATUS;
pJobFields[4] = JOB_NOTIFY_FIELD_STATUS_STRING;
arr_NotifyOptionsType[0].Type = JOB_NOTIFY_TYPE ;
arr_NotifyOptionsType[0].pFields = pJobFields;
arr_NotifyOptionsType[0].Count = 5;
pPrinterFields = (PWORD)malloc(2 * sizeof(WORD));
pPrinterFields[0] = PRINTER_NOTIFY_FIELD_PRINTER_NAME;
pPrinterFields[1] = PRINTER_NOTIFY_FIELD_AVERAGE_PPM;
arr_NotifyOptionsType[1].Type = PRINTER_NOTIFY_TYPE ;
arr_NotifyOptionsType[1].pFields = pPrinterFields;
arr_NotifyOptionsType[1].Count = 2;
p_NotifyOptions = new PRINTER_NOTIFY_OPTIONS;
p_NotifyOptions->Count = 2;
p_NotifyOptions->Version = 2;
p_NotifyOptions->pTypes = arr_NotifyOptionsType;
p_NotifyOptions->Flags = PRINTER_NOTIFY_OPTIONS_REFRESH;
if((hwndNotify = FindFirstPrinterChangeNotification(hPrinter, 0, 0, p_NotifyOptions)) != INVALID_HANDLE_VALUE)
{
while(hwndNotify != INVALID_HANDLE_VALUE)
{
if(WaitForSingleObject(hwndNotify, 0) == WAIT_OBJECT_0)
{
FindNextPrinterChangeNotification(hwndNotify, &dwChanged, (LPVOID)p_NotifyOptions, (LPVOID*)&p_OutPut);
for (int i=0;i<p_OutPut->Count;i++)
{
if(p_OutPut->aData[i].Type == JOB_NOTIFY_TYPE)
{
if(p_OutPut->aData[i].Field == JOB_NOTIFY_FIELD_USER_NAME)
{
MessageBox(NULL,(LPTSTR)(p_OutPut->aData[i].NotifyData.Data.pBuf) ,_T("Status"),MB_OK);
}
if(p_OutPut->aData[i].Field == JOB_NOTIFY_FIELD_PAGES_PRINTED)
{
TCHAR buff[25];
_stprintf(buff,_T("PP = %d Job ID %ld"),p_OutPut->aData[i].NotifyData.adwData[0], p_OutPut->aData[i].Id);
MessageBox(NULL,buff ,_T("Status"),MB_OK);
}
if(p_OutPut->aData[i].Field == JOB_NOTIFY_FIELD_STATUS)
{
if(p_OutPut->aData[i].NotifyData.adwData[0] & JOB_STATUS_PRINTED)
MessageBox(NULL,_T("Job Done") ,_T("Status"),MB_OK);
}
if(p_OutPut->aData[i].Field == JOB_NOTIFY_FIELD_STATUS_STRING)
{
MessageBox(NULL,(LPTSTR)(p_OutPut->aData[i].NotifyData.Data.pBuf) ,_T("Status"),MB_OK);
}
}
}
}
}
}
else
{
DWORD dwError = GetLastError();
dwError += 0;
}
}
else
{
DWORD dwError = GetLastError();
dwError += 0;
}
}
It will be great if some one help me out with this...
Thanks
Pankaj