Visual C++ 打印编程技术-编程基础-获取打印机
标准方法是用: 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;
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。