- //得到所有打印机
- DWORD dwSize,dwPrinters;
- ::EnumPrinters(PRINTER_ENUM_CONNECTIONS | PRINTER_ENUM_LOCAL,NULL,5,NULL,0,&dwSize,&dwPrinters);
- BYTE *pBuffer=new BYTE[dwSize];
- ::EnumPrinters(PRINTER_ENUM_CONNECTIONS | PRINTER_ENUM_LOCAL,NULL,5,pBuffer,dwSize,&dwSize,&dwPrinters);
- CString sPrinter;
- if(dwPrinters!=0)
- {
- PRINTER_INFO_5 *pPrnInfo=(PRINTER_INFO_5 *)pBuffer;
- for(int i=0;i <dwPrinters;i++)
- {
- sPrinter.Format(_T("%s"),pPrnInfo-> pPrinterName);
- pPrnInfo++;//指针后移
- }
- }
- delete []pBuffer;
- //得到默认打印机并弹出属性编辑
- #include <WinSpool.h>
- #pragma comment(lib, "Winspool.lib")
- #include <shellapi.h>
- #pragma comment(lib, "shell32.lib")
- BOOL OpenDefaultPrinter()
- {
- BOOL bRet = FALSE;
- DWORD dwSize = 0;
- if(!GetDefaultPrinter(NULL, &dwSize)
- && GetLastError()==ERROR_INSUFFICIENT_BUFFER)
- {
- TCHAR *szPrinter = new TCHAR[dwSize+1];
- if(GetDefaultPrinter(szPrinter, &dwSize))
- {
- if(SHInvokePrinterCommand(
- NULL, //GetSafeHwnd(),
- PRINTACTION_PROPERTIES,
- szPrinter,
- NULL,
- FALSE))
- {
- bRet = TRUE;
- }
- }
- delete []szPrinter;
- }
- return bRet;
- }