码迷,mamicode.com
首页 > 编程语言 > 详细

Visual C++ 打印编程技术-编程基础-获取打印机

时间:2015-04-03 18:50:16      阅读:185      评论:0      收藏:0      [点我收藏+]

标签:

标准方法是用: EnumPrinters() 函数获取

#define PRINTER_ENUM_DEFAULT     0x00000001
#define PRINTER_ENUM_LOCAL       0x00000002
#define PRINTER_ENUM_CONNECTIONS 0x00000004
#define PRINTER_ENUM_FAVORITE    0x00000004
#define PRINTER_ENUM_NAME        0x00000008
#define PRINTER_ENUM_REMOTE      0x00000010
#define PRINTER_ENUM_SHARED      0x00000020
#define PRINTER_ENUM_NETWORK     0x00000040

  

BOOL EnumPrinters(
  _In_   DWORD Flags, // 打印机获取方式,见上表 
  _In_   LPTSTR Name,
  _In_   DWORD Level,//PRINTER_INFO_1PRINTER_INFO_2 , PRINTER_INFO_4, and PRINTER_INFO_5  分别对应1,2,4,5
  _Out_  LPBYTE pPrinterEnum,//A pointer to a buffer that receives an array of PRINTER_INFO_1PRINTER_INFO_2PRINTER_INFO_4, orPRINTER_INFO_5 structures.                             // Each structure contains data that describes an available print object.
  _In_   DWORD cbBuf,//The size, in bytes, of the buffer pointed to by pPrinterEnum.
  _Out_  LPDWORD pcbNeeded,
  _Out_  LPDWORD pcReturned
);

  

	DWORD dwSize,dwPrinters;
	::EnumPrinters(PRINTER_ENUM_LOCAL,NULL,5,NULL,0,&dwSize,&dwPrinters);
	BYTE* pBuffer=new BYTE[dwSize];
	::EnumPrinters(PRINTER_ENUM_LOCAL,NULL,5,pBuffer,dwSize,&dwSize,&dwPrinters);
	if(dwPrinters!=0)
	{
		PRINTER_INFO_5* pPrnInfo=(PRINTER_INFO_5*)pBuffer;
		for(UINT i=0;i<dwPrinters;i++)
		{
			m_listbox.AddString(pPrnInfo->pPrinterName); //m_listbox : Listbox控件变量
                        pPrnInfo++;
		}
	}
    delete[] pBuffer;

  

Visual C++ 打印编程技术-编程基础-获取打印机

标签:

原文地址:http://www.cnblogs.com/ericyi/p/4390567.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!