如何得知打印机是真正的打印机还是无纸打印机? [英] How to get to know the printer is a real one or a paperless printer?

查看:124
本文介绍了如何得知打印机是真正的打印机还是无纸打印机?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

C ++程序如何将实际打印机与虚拟打印机(例如PDF创建器)区分开?

How can a C++ program distinguish an actual printer from a virtual printer (e.g. a PDF creator)?

推荐答案

为此,您可以使用PRINTER_INFO_2名为pPortName的字段.然后,您可以将它与字符串"FILE"进行字符串比较,并获得连接到"FILE"端口的所有队列.同样,您可以添加更多解析逻辑来检测其他虚拟打印机.当您使用打印机句柄调用GetPrinter时,Windows将填充此结构.
To do this you can use PRINTER_INFO_2 which has a field called pPortName. And then you can string compare it with the string "FILE" and get all the queues which are connected to the "FILE" port. And you can similarly add in more parsing logic for detecting other virtual printers. This structure is filled up by Windows when you call GetPrinter with the printer handle.


要与Laxmi添加,
我写了(可能无法回忆起,无论是写它还是从任何站点下载)都获得了打印机的所有列表.
to add with Laxmi,
I wrote(probably, cant recall, whether I wrote it or downloaded it from any site) to get all the list of printers
int getAllPrinter(HWND hList)
{
	int i,j;
    wchar_t		*pPrInfo4=NULL;
    wchar_t		*pPrInfoP=NULL;
	wchar_t     *pStr    =NULL;
    DWORD       dwNeeded = 0;
	DWORD       dwReturned = 0;
	DWORD       dwReturnedP = 0;
	DWORD       dwBytes = 0;
	wchar_t     *strStr;
	wchar_t		strStrP[257];
	int pos;

	EnumPrinters( PRINTER_ENUM_LOCAL,NULL,1,NULL,dwBytes,&dwNeeded,&dwReturned);
    if( dwNeeded != 0)
       { pPrInfo4 = new wchar_t [dwNeeded+128];
		 dwBytes  = dwNeeded+128;
	     EnumPrinters( PRINTER_ENUM_LOCAL,NULL,1,(LPBYTE)pPrInfo4,dwBytes,&dwNeeded,&dwReturned);

		for( i=0; i<(int)dwReturned; i++ )
		   { 
				strStr = (wchar_t*)((PRINTER_INFO_1*)pPrInfo4)[i].pName;
				pos=ListBox_FindString(hList,0,strStr);
				if(pos==LB_ERR)
				{
					ListBox_AddString(hList,strStr);
				}
		   }
  	    delete pPrInfo4;
		pPrInfo4 = NULL;
	   }
    pPrInfo4=NULL;
    dwNeeded = 0;
	dwReturned = 0;
	dwBytes = 0;
	EnumPrinters( PRINTER_ENUM_LOCAL | PRINTER_ENUM_NETWORK,NULL,1,NULL,dwBytes,&dwNeeded,&dwReturned);
    if( dwNeeded != 0)
    { 
		pPrInfo4 = new wchar_t [dwNeeded+128];
		dwBytes  = dwNeeded+128;
        EnumPrinters( PRINTER_ENUM_LOCAL | PRINTER_ENUM_NETWORK,NULL,1,(LPBYTE)pPrInfo4,dwBytes,&dwNeeded,	&dwReturned);
		for( i=0; i<(int)dwReturned; i++ )
		{ 
			strStr = (wchar_t*)((PRINTER_INFO_1*)pPrInfo4)[i].pName;
			pos=ListBox_FindString(hList,0,strStr);
			if(pos==LB_ERR)
			{
				//wprintf(L"%s\n",strStr);
				ListBox_AddString(hList,strStr);
			}
		   }
  	    delete pPrInfo4;
		pPrInfo4 = NULL;
	   }
    pPrInfo4=NULL;
    dwNeeded = 0;
	dwReturned = 0;
	dwBytes = 0;
	EnumPrinters( PRINTER_ENUM_REMOTE,NULL,1,NULL,dwBytes,&dwNeeded,&dwReturned);
    if( dwNeeded != 0)
	{ 
		pPrInfo4 = new wchar_t [dwNeeded+128];
		dwBytes  = dwNeeded+128;
		EnumPrinters( PRINTER_ENUM_REMOTE,	NULL,	1,		(LPBYTE) pPrInfo4,	dwBytes,	&dwNeeded,	&dwReturned);
		for( i=0; i<(int)dwReturned; i++ )
		{	 
			wcscpy(strStr ,((PRINTER_INFO_1*)pPrInfo4)[i].pName);
			if( -1 == strposw(strStr,L"!!",0))   
			{
				pos=ListBox_FindString(hList,0,strStr);
				if(pos==LB_ERR)
				{
					//wprintf(L"%s\n",strStr);
					ListBox_AddString(hList,strStr);
				}
			}
			else 
			{ 
				pPrInfoP   = NULL;
				dwNeeded   = 0;
				dwReturnedP= 0;
				dwBytes    = 0;
				pStr = new wchar_t [wcslen(strStr)+1];
				wcscpy(pStr,strStr);
  				EnumPrinters(PRINTER_ENUM_NAME,pStr,1,NULL, dwBytes,&dwNeeded,	&dwReturnedP);
				if( dwNeeded != 0)
				{ 
					pPrInfoP = new wchar_t [dwNeeded+128];
					dwBytes  = dwNeeded+128;
  					EnumPrinters( PRINTER_ENUM_NAME,	pStr,	 1,		 (LPBYTE)pPrInfoP, dwBytes,		&dwNeeded,	&dwReturnedP);
					for( j=0; j<(int)dwReturnedP; j++ )
					{ 
						wcscpy(strStrP,((PRINTER_INFO_1*)pPrInfoP)[j].pName);
			            pos=ListBox_FindString(hList,0,strStr);
						if(pos==LB_ERR)
						{
							//wprintf(L"%s\n",strStr);
							ListBox_AddString(hList,strStr);
						}
		            }
					delete pStr;
  					delete pPrInfoP;
					pPrInfoP = NULL;
				}
			}
		}
  	    delete pPrInfo4;
		pPrInfo4 = NULL;
	}
	return true;  // return TRUE  unless you set the focus to a control
}


这篇关于如何得知打印机是真正的打印机还是无纸打印机?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆