#include <iostream>
#include <stdio.h>
#include <windows.h>
using namespace std;
//遍历电脑中的打印机
void get_all_printer_device()
{
DWORD dwFlags = PRINTER_ENUM_FAVORITE | PRINTER_ENUM_LOCAL;
LPPRINTER_INFO_2 pPrinters;
DWORD cbPrinters;
DWORD cReturned, i;
char buf[256];
EnumPrinters (dwFlags, NULL, 2, NULL, 0, &cbPrinters,
&cReturned);
if (!(pPrinters = (LPPRINTER_INFO_2) LocalAlloc (LPTR, cbPrinters + 4)))
{
::MessageBox (NULL, "error",
"error", MB_OK | MB_ICONEXCLAMATION);
}
if (!EnumPrinters (dwFlags, NULL, 2, (LPBYTE) pPrinters,
cbPrinters, &cbPrinters, &cReturned))
{
::MessageBox (NULL, "error",
"error", MB_OK | MB_ICONEXCLAMATION);
}
if (cReturned > 0)
{
for (i = 0; i < cReturned; i++)
{
//
// for each printer in the PRINTER_INFO_2 array: build a string that
// looks like "DEVICE_NAME;PORT;DRIVER_NAME"
//
printf("printer name:%s\n",(pPrinters+i)->pPrinterName);
printf("printer portname:%s\n",(pPrinters+i)->pPortName);
#if 0
strcpy (buf, (pPrinters + i)->pPrinterName);
strcat (buf, ";");
strcat (buf, (pPrinters + i)->pPortName);
strcat (buf, ";");
strcat (buf, (pPrinters + i)->pDriverName);
#endif
}
}
else
::MessageBox (NULL, "No printers listed", "PRINTER.EXE", MB_OK);
#endif
}
//获取默认打印机
void GetSystemDefaultPrinter()
{
char szBuff[1024] = {0};
DWORD len = 1024;
int ret;
ret = GetDefaultPrinter(szBuff,&len);
if(ret == FALSE){
printf("getdefault printer error:%d\n",GetLastError());
return ;
}
printf("default printer:%s\n",szBuff);
return;
}
阅读(1884) | 评论(0) | 转发(0) |