Click here to Skip to main content
15,920,005 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: Is there a VC++ equivalent to the Visual Basic "CStr" keyword? Pin
prasad_som14-Dec-06 23:17
prasad_som14-Dec-06 23:17 
GeneralRe: Is there a VC++ equivalent to the Visual Basic "CStr" keyword? Pin
dharani_3d14-Dec-06 23:27
dharani_3d14-Dec-06 23:27 
GeneralRe: Is there a VC++ equivalent to the Visual Basic "CStr" keyword? Pin
dharani_3d14-Dec-06 23:29
dharani_3d14-Dec-06 23:29 
GeneralRe: Is there a VC++ equivalent to the Visual Basic "CStr" keyword? Pin
prasad_som14-Dec-06 23:36
prasad_som14-Dec-06 23:36 
AnswerRe: Is there a VC++ equivalent to the Visual Basic "CStr" keyword? Pin
David Crow15-Dec-06 4:07
David Crow15-Dec-06 4:07 
QuestionIs there any possiblity to declare a variable as a Variant and a Variant array in VC++? Pin
dharani_3d14-Dec-06 23:01
dharani_3d14-Dec-06 23:01 
AnswerRe: Is there any possiblity to declare a variable as a Variant and a Variant array in VC++? Pin
prasad_som14-Dec-06 23:26
prasad_som14-Dec-06 23:26 
QuestionPrinter Monitoring Pin
pnkj14-Dec-06 22:54
pnkj14-Dec-06 22:54 
Dear All

I have to monitor a printer, and for that I have to use FindFirstPrinterChangeNotification and FindNextPrinterChangeNotification APIs. For this I have written the code, which is below. Some problems that i am facing with this code are also stated below (after the code). It will be great you can shed some light on the issues I am facing. It will be of great help.


void StartNotifications(void)
{
HANDLE hPrinter = NULL;
PRINTER_NOTIFY_OPTIONS * p_NotifyOptions = NULL;
PRINTER_NOTIFY_OPTIONS_TYPE arr_NotifyOptionsType[2];
PWORD pPrinterFields;
WORD arrJobFields[100];
HANDLE hwndNotify = NULL;
DWORD dwChanged = 0;
int i;
FILE * pFile;
TCHAR * pBuf;
DWORD * adwData;
TCHAR arrBuf[50];
pFile = _tfopen(_T("C:\\PrinterNotifications.txt"), _T("a+"));
if(pFile)
{
MessageBox(NULL, _T("Opened"), _T("File Status"), MB_OK);
}


PRINTER_NOTIFY_INFO * p_OutPut = NULL;


if(OpenPrinter(_T("\\\\NECHCLSTDC\\HP LaserJet 4345 mfp PCL 5e"),
&hPrinter, NULL))
{
i=0;
arrJobFields[i++] = JOB_NOTIFY_FIELD_PRINTER_NAME;
arrJobFields[i++] = JOB_NOTIFY_FIELD_MACHINE_NAME;
arrJobFields[i++] = JOB_NOTIFY_FIELD_PORT_NAME;
arrJobFields[i++] = JOB_NOTIFY_FIELD_USER_NAME;
arrJobFields[i++] = JOB_NOTIFY_FIELD_NOTIFY_NAME;
arrJobFields[i++] = JOB_NOTIFY_FIELD_DATATYPE;
arrJobFields[i++] = JOB_NOTIFY_FIELD_PRINT_PROCESSOR;
arrJobFields[i++] = JOB_NOTIFY_FIELD_PARAMETERS;
arrJobFields[i++] = JOB_NOTIFY_FIELD_DRIVER_NAME;
arrJobFields[i++] = JOB_NOTIFY_FIELD_STATUS_STRING;
arrJobFields[i++] = JOB_NOTIFY_FIELD_DOCUMENT;
arrJobFields[i++] = JOB_NOTIFY_FIELD_PRIORITY;
arrJobFields[i++] = JOB_NOTIFY_FIELD_POSITION;
arrJobFields[i++] = JOB_NOTIFY_FIELD_START_TIME;
arrJobFields[i++] = JOB_NOTIFY_FIELD_UNTIL_TIME;
arrJobFields[i++] = JOB_NOTIFY_FIELD_TIME;
arrJobFields[i++] = JOB_NOTIFY_FIELD_TOTAL_PAGES;
arrJobFields[i++] = JOB_NOTIFY_FIELD_PAGES_PRINTED;
arrJobFields[i++] = JOB_NOTIFY_FIELD_TOTAL_BYTES;
arrJobFields[i++] = JOB_NOTIFY_FIELD_BYTES_PRINTED;


arr_NotifyOptionsType[0].Type = JOB_NOTIFY_TYPE ;
arr_NotifyOptionsType[0].pFields = arrJobFields;
arr_NotifyOptionsType[0].Count = 20;


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,
PRINTER_CHANGE_ALL, 0, p_NotifyOptions)) != INVALID_HANDLE_VALUE)
{
while(hwndNotify != INVALID_HANDLE_VALUE)
{
if(WaitForSingleObject(hwndNotify, INFINITE) == WAIT_OBJECT_0)
{


FindNextPrinterChangeNotification(hwndNotify, &dwChanged,
(LPVOID)p_NotifyOptions, (LPVOID*)&p_OutPut);
for (int i=0;(i<p_output->Count) && ;i++)
{
pBuf = (TCHAR*)(p_OutPut->aData[i].NotifyData.Data.pBuf);
adwData = p_OutPut->aData[i].NotifyData.adwData;
switch(p_OutPut->aData[i].Type)
{
case JOB_NOTIFY_TYPE:
{
//printf("\tジョブ通知(no.%d, id:%d)...", i,
p_OutPut->aData[i].Id);
switch(p_OutPut->aData[i].Field)
{
case JOB_NOTIFY_FIELD_PRINTER_NAME:
_fputts(_T("Printer Name "), pFile);
_fputts(pBuf, pFile);
_fputtc(_T('\n'), pFile);
break;
case JOB_NOTIFY_FIELD_MACHINE_NAME:
_fputts(_T("machine Name "), pFile);
_fputts(pBuf, pFile);
_fputtc(_T('\n'), pFile);
break;
case JOB_NOTIFY_FIELD_PORT_NAME:
_fputts(_T("Port Name "), pFile);
_fputts(pBuf, pFile);
_fputtc(_T('\n'), pFile);
break;
case JOB_NOTIFY_FIELD_USER_NAME:
_fputts(_T("User Name "), pFile);
_fputts(pBuf, pFile);
_fputtc(_T('\n'), pFile);
break;
case JOB_NOTIFY_FIELD_NOTIFY_NAME:
_fputts(_T("Notify Name "), pFile);
_fputts(pBuf, pFile);
_fputtc(_T('\n'), pFile);
break;
case JOB_NOTIFY_FIELD_DATATYPE:
_fputts(_T("Data Type "), pFile);
_fputts(pBuf, pFile);
_fputtc(_T('\n'), pFile);
break;
case JOB_NOTIFY_FIELD_PRINT_PROCESSOR:
_fputts(_T("Print Processor "), pFile);
_fputts(pBuf, pFile);
_fputtc(_T('\n'), pFile);
break;
case JOB_NOTIFY_FIELD_PARAMETERS:
_fputts(_T("Parameters"), pFile);
_fputts(pBuf, pFile);
_fputtc(_T('\n'), pFile);
break;
case JOB_NOTIFY_FIELD_DRIVER_NAME:
_fputts(_T("Driver Name "), pFile);
_fputts(pBuf, pFile);
_fputtc(_T('\n'), pFile);
break;
case JOB_NOTIFY_FIELD_DEVMODE:
// DEVMODE
break;
case JOB_NOTIFY_FIELD_STATUS:
if(adwData[0] & JOB_STATUS_PAUSED)
{
_fputts(_T("Status = "), pFile);
_fputts( _T("Paused"), pFile);
_fputtc(_T('\n'), pFile);
}
if(adwData[0] & JOB_STATUS_ERROR)
{
_fputts(_T("Status = "), pFile);
_fputts( _T("Error"), pFile);
_fputtc(_T('\n'), pFile);
}
if(adwData[0] & JOB_STATUS_DELETING)
{
_fputts(_T("Status = "), pFile);
_fputts( _T("Deleting"), pFile);
_fputtc(_T('\n'), pFile);
}
if(adwData[0] & JOB_STATUS_SPOOLING)
{
_fputts(_T("Status = "), pFile);
_fputts( _T("Spooling"), pFile);
_fputtc(_T('\n'), pFile);
}
if(adwData[0] & JOB_STATUS_PRINTING)
{
_fputts(_T("Status = "), pFile);
_fputts( _T("Printing"), pFile);
_fputtc(_T('\n'), pFile);
}
if(adwData[0] & JOB_STATUS_OFFLINE)
{
_fputts(_T("Status = "), pFile);
_fputts( _T("Offline"), pFile);
_fputtc(_T('\n'), pFile);
}
if(adwData[0] & JOB_STATUS_PAPEROUT)
{
_fputts(_T("Status = "), pFile);
_fputts( _T("PaperOut"), pFile);
_fputtc(_T('\n'), pFile);
}


if(adwData[0] & JOB_STATUS_PRINTED)
{
_fputts(_T("Status = "), pFile);
_fputts( _T("Printed"), pFile);
_fputtc(_T('\n'), pFile);
}
if(adwData[0] & JOB_STATUS_DELETED)
{
_fputts(_T("Status = "), pFile);
_fputts( _T("Deleted"), pFile);
_fputtc(_T('\n'), pFile);
}
if(adwData[0] & JOB_STATUS_BLOCKED_DEVQ)
{
_fputts(_T("Status = "), pFile);
_fputts( _T("Blocked DevQ"), pFile);
_fputtc(_T('\n'), pFile);
}
if(adwData[0] & JOB_STATUS_USER_INTERVENTION)
{
_fputts(_T("Status = "), pFile);
_fputts( _T("User Intervention"), pFile);
_fputtc(_T('\n'), pFile);
}
if(adwData[0] & JOB_STATUS_RESTART)
{
_fputts(_T("Status = "), pFile);
_fputts( _T("Restart"), pFile);
_fputtc(_T('\n'), pFile);
}
break;
case JOB_NOTIFY_FIELD_STATUS_STRING:
{
_fputts(_T("Status String= "), pFile);
_fputts( pBuf, pFile);
_fputtc(_T('\n'), pFile);
}
break;
case JOB_NOTIFY_FIELD_DOCUMENT:
{
_fputts(_T("Document = "), pFile);
_fputts( pBuf, pFile);
_fputtc(_T('\n'), pFile);
}
break;
case JOB_NOTIFY_FIELD_SUBMITTED:
//SYSTEMTIME
break;
case JOB_NOTIFY_FIELD_START_TIME:
memset(arrBuf, _T('\0'), 50);
_stprintf(arrBuf,_T("Start Time: %d:%d\n"), adwData[0]/60,
adwData[0]%60);
_fputts(arrBuf, pFile);
break;
case JOB_NOTIFY_FIELD_UNTIL_TIME:
memset(arrBuf, _T('\0'), 50);
_stprintf(arrBuf,_T("Until Time: %d:%d\n"), adwData[0]/60,
adwData[0]%60);
_fputts(arrBuf, pFile);
break;
case JOB_NOTIFY_FIELD_TIME:
memset(arrBuf, _T('\0'), 50);
_stprintf(arrBuf,_T("Field Time: %d: %d\n"), adwData[0]/60,
adwData[0]%60);
_fputts(arrBuf, pFile);
break;
case JOB_NOTIFY_FIELD_TOTAL_PAGES:
memset(arrBuf, _T('\0'), 50);
_stprintf(arrBuf,_T("Total Pages: %d\n"), adwData[0]);
_fputts(arrBuf, pFile);
break;
case JOB_NOTIFY_FIELD_PAGES_PRINTED:
memset(arrBuf, _T('\0'), 50);
_stprintf(arrBuf,_T("Pages Printed: %d\n"), adwData[0]);
_fputts(arrBuf, pFile);
break;
case JOB_NOTIFY_FIELD_TOTAL_BYTES:
memset(arrBuf, _T('\0'), 50);
_stprintf(arrBuf,_T("Total Bytes: %d\n"), adwData[0]);
_fputts(arrBuf, pFile);
break;
case JOB_NOTIFY_FIELD_BYTES_PRINTED:
memset(arrBuf, _T('\0'), 50);
_stprintf(arrBuf,_T("Bytes Printed: %d\n"), adwData[0]);
_fputts(arrBuf, pFile);
break;
}
break;
}
case PRINTER_NOTIFY_TYPE:
{
}
break;
}
}
}
}
}
else
{
DWORD dwError = GetLastError();
dwError += 0;
}
}
else
{
DWORD dwError = GetLastError();
dwError += 0;
}



}


I dumped the notification data in a file, and had the following
observations:

1. I never received any Status notification for any type of Print job,
i.e be it in EMF format or RAW format. In case of Status String, the
notification was there, but the pBuf was empty. So, how do we receive the status info?


2. In case of print job with EMF data type, the Total Pages and Printed
pages data was received correctly. Same case for Total Bytes and
Printed Bytes.


3. In case of print job with RAW format, Total pages was received with
correct values, but Printed Pages was always recieved with the value 0.
Total Bytes was OK, but at the end of the print job, the Total Bytes
and Printed Bytes were different, the latter being lesser then former.
So, it doesn't help in determining that whether a print job is finished
or not.

Thanks in advance.
Pankaj
QuestionShow the hourglass? Pin
bosfan14-Dec-06 22:49
bosfan14-Dec-06 22:49 
AnswerRe: Show the hourglass? Pin
prasad_som14-Dec-06 22:52
prasad_som14-Dec-06 22:52 
GeneralRe: Show the hourglass? [modified] Pin
kakan14-Dec-06 23:00
professionalkakan14-Dec-06 23:00 
AnswerRe: Show the hourglass? Pin
prasad_som14-Dec-06 23:11
prasad_som14-Dec-06 23:11 
GeneralRe: Show the hourglass? Pin
kakan14-Dec-06 23:14
professionalkakan14-Dec-06 23:14 
AnswerRe: Show the hourglass? Pin
prasad_som14-Dec-06 23:19
prasad_som14-Dec-06 23:19 
GeneralRe: Show the hourglass? Pin
prasad_som15-Dec-06 6:41
prasad_som15-Dec-06 6:41 
GeneralRe: Show the hourglass? Pin
kakan17-Dec-06 19:19
professionalkakan17-Dec-06 19:19 
GeneralRe: Show the hourglass? Pin
bosfan14-Dec-06 23:52
bosfan14-Dec-06 23:52 
GeneralRe: Show the hourglass? Pin
Chris Losinger15-Dec-06 3:47
professionalChris Losinger15-Dec-06 3:47 
GeneralRe: Show the hourglass? Pin
bosfan15-Dec-06 4:04
bosfan15-Dec-06 4:04 
QuestionHow to get the position of one obejct in an image Pin
oliverhuang14-Dec-06 21:42
oliverhuang14-Dec-06 21:42 
QuestionHow to load a file in my application.. Pin
Shah Satish14-Dec-06 21:07
Shah Satish14-Dec-06 21:07 
QuestionRe: How to load a file in my application.. Pin
prasad_som14-Dec-06 21:57
prasad_som14-Dec-06 21:57 
GeneralRe: How to load a file in my application.. Pin
Mila02514-Dec-06 22:27
Mila02514-Dec-06 22:27 
QuestionCDialog Pin
Bravoone_200614-Dec-06 21:03
Bravoone_200614-Dec-06 21:03 
AnswerRe: CDialog Pin
Hamid_RT14-Dec-06 21:12
Hamid_RT14-Dec-06 21:12 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.