Click here to Skip to main content
15,922,584 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionAdd custom perfmon counters Pin
runOnce0x5-Jan-09 2:02
runOnce0x5-Jan-09 2:02 
RantRe: Add custom perfmon counters Pin
runOnce0x8-Jan-09 20:50
runOnce0x8-Jan-09 20:50 
QuestionSDI app: Wait for printer Pin
nobaq5-Jan-09 1:56
nobaq5-Jan-09 1:56 
QuestionRe: SDI app: Wait for printer Pin
nobaq5-Jan-09 3:07
nobaq5-Jan-09 3:07 
AnswerRe: SDI app: Wait for printer Pin
Iain Clarke, Warrior Programmer5-Jan-09 3:53
Iain Clarke, Warrior Programmer5-Jan-09 3:53 
QuestionRe: SDI app: Wait for printer Pin
nobaq5-Jan-09 4:41
nobaq5-Jan-09 4:41 
AnswerRe: SDI app: Wait for printer Pin
Iain Clarke, Warrior Programmer5-Jan-09 5:04
Iain Clarke, Warrior Programmer5-Jan-09 5:04 
AnswerRe: SDI app: Wait for printer Pin
Randor 5-Jan-09 4:52
professional Randor 5-Jan-09 4:52 
You could obtain a PRINTER_INFO_2[^] structure which contains the number of jobs in the printer que. The Status member should return PRINTER_STATUS_PRINTING while printing and PRINTER_STATUS_WAITING when finished.

If you wanted to track individual print jobs you could use the JOB_INFO_1[^] or other associated print job structures to track the job. The Status member will return JOB_STATUS_PRINTED when the job has completed. It should be noted that older printers and/or port monitor drivers may always return JOB_STATUS_PRINTED information for job status. Your mileage may vary.

Some documentation:
http://support.microsoft.com/kb/158828[^]


Some sample code:

#include <winspool.h>
/************************************************************************************
	HANDLE OpenDefaultPrinter(ACCESS_MASK dwMask)
	Returns a HANDLE to the Default system printer. The caller must Close the HANDLE.
	-David Delaune 12-06-2006
*************************************************************************************/
HANDLE YourClass::OpenDefaultPrinter(ACCESS_MASK dwMask)
{
	HANDLE hPrinter = INVALID_HANDLE_VALUE;
	PRINTER_DEFAULTS pDef;
	DWORD dwSize;

	ZeroMemory(&pDef, sizeof(pDef));
    GetDefaultPrinter(NULL, &dwSize);
    
	TCHAR* szBuffer = new TCHAR[dwSize];

	if(NULL != szBuffer)
	{
		if(GetDefaultPrinter(szBuffer, &dwSize))
		{
			pDef.DesiredAccess = dwMask;
			OpenPrinter(szBuffer, &hPrinter, &pDef);
		}
		delete szBuffer;
	}
	return hPrinter;
}

/************************************************************************************
	DWORD GetPrintQueCount()
	Returns the number of waiting print jobs in the Default printer que.
	-David Delaune 12-06-2006
*************************************************************************************/
DWORD YourClass::GetPrintQueCount()
{
	DWORD dwNeeded = NULL;
	PRINTER_INFO_2 *pInfo = NULL;
	DWORD dwRet = 0;

	HANDLE hPrinter = OpenDefaultPrinter();

	if(INVALID_HANDLE_VALUE != hPrinter)
	{
		GetPrinter(hPrinter, 2, (LPBYTE)pInfo, 0, &dwNeeded);

		if(0 < dwNeeded)
		{
			pInfo = static_cast<PRINTER_INFO_2 *>(GlobalAlloc(GPTR, dwNeeded));
			if(NULL != pInfo)
			{
				if(GetPrinter(hPrinter, 2, (LPBYTE)pInfo, dwNeeded, &dwNeeded))
				{
					dwRet = pInfo->cJobs;
				}
			}
			GlobalFree(pInfo);
		}
		ClosePrinter(hPrinter);
	}
	return dwRet;
}


Good Luck,
-David Delaune
QuestionDoubt in using CToolTipCtrl Pin
KASR15-Jan-09 0:56
KASR15-Jan-09 0:56 
AnswerRe: Doubt in using CToolTipCtrl Pin
Iain Clarke, Warrior Programmer5-Jan-09 0:59
Iain Clarke, Warrior Programmer5-Jan-09 0:59 
GeneralRe: Doubt in using CToolTipCtrl Pin
KASR15-Jan-09 1:07
KASR15-Jan-09 1:07 
QuestionHardware info about the network controllers Pin
Pasy_m4-Jan-09 23:29
Pasy_m4-Jan-09 23:29 
AnswerRe: Hardware info about the network controllers Pin
Hamid_RT5-Jan-09 0:37
Hamid_RT5-Jan-09 0:37 
AnswerRe: Hardware info about the network controllers Pin
Randor 5-Jan-09 5:14
professional Randor 5-Jan-09 5:14 
AnswerRe: Hardware info about the network controllers Pin
David Crow5-Jan-09 8:03
David Crow5-Jan-09 8:03 
QuestionAccess Violation ....Very Interesting Pin
Aabid4-Jan-09 23:11
Aabid4-Jan-09 23:11 
GeneralRe: Access Violation ....Very Interesting Pin
CPallini4-Jan-09 23:16
mveCPallini4-Jan-09 23:16 
AnswerRe: Access Violation ....Very Interesting Pin
ThatsAlok4-Jan-09 23:26
ThatsAlok4-Jan-09 23:26 
GeneralRe: Access Violation ....Very Interesting Pin
CPallini4-Jan-09 23:42
mveCPallini4-Jan-09 23:42 
GeneralRe: Access Violation ....Very Interesting Pin
ThatsAlok4-Jan-09 23:48
ThatsAlok4-Jan-09 23:48 
GeneralRe: Access Violation ....Very Interesting Pin
CPallini5-Jan-09 1:16
mveCPallini5-Jan-09 1:16 
AnswerRe: Access Violation ....Very Interesting Pin
Radhakrishnan G.4-Jan-09 23:39
Radhakrishnan G.4-Jan-09 23:39 
GeneralRe: Access Violation ....Very Interesting Pin
Radhakrishnan G.4-Jan-09 23:40
Radhakrishnan G.4-Jan-09 23:40 
Question#pragma Pin
zon_cpp4-Jan-09 22:58
zon_cpp4-Jan-09 22:58 
AnswerRe: #pragma Pin
CPallini4-Jan-09 23:12
mveCPallini4-Jan-09 23: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.