标签:
标准方法是用: 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_1, PRINTER_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_1, PRINTER_INFO_2, PRINTER_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;
标签:
原文地址:http://www.cnblogs.com/ericyi/p/4390567.html