求,怎样获得打印机列表呢?

uxuan 2004-12-08 08:48:16
我想获得打印机列表,然后让用户选择打印机打印,
(界面我想自己做,不想调用windows的窗体出来)
...全文
199 点赞 收藏 2
写回复
2 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
bohut 2004-12-08
枚举打印机名:
DWORD dwFlags = PRINTER_ENUM_FAVORITE | PRINTER_ENUM_LOCAL;
LPPRINTER_INFO_2 pPrinters;
DWORD cbPrinters;
DWORD cReturned, i;

EnumPrinters (dwFlags, NULL, 2, NULL, 0, &cbPrinters,&cReturned);

if (!(pPrinters = (LPPRINTER_INFO_2) LocalAlloc (LPTR, cbPrinters + 4)))
return false;

if (!EnumPrinters (dwFlags, NULL, 2, (LPBYTE) pPrinters,
cbPrinters, &cbPrinters, &cReturned))
{
LocalFree (LocalHandle (pPrinters));
return false;
}

if (cReturned > 0)
{
for (i = 0; i < cReturned; i++)
{
AfxMessageBox((pPrinters + i)->pPrinterName);/////
if(strstr((pPrinters + i)->pPrinterName,"PDF")!=0 && strstr((pPrinters + i)->pPrinterName,"Writer")<=0)
{
m_sNewPrinter = "Adobe PDF";
return true;
}
}
for (i = 0; i < cReturned; i++)
{
if(strstr((pPrinters + i)->pPrinterName,"Acrobat Distiller")!=0 && m_sNewPrinter==""){
m_sNewPrinter = "Acrobat Distiller";
return true;
}
}
}

LocalFree (LocalHandle (pPrinters));
return false;
回复
Kudeet 2004-12-08
PRINTER_INFO_5 printerinfo[3];
DWORD need,returned;
EnumPrinters(PRINTER_ENUM_DEFAULT,NULL,5,(LPBYTE)printerinfo,sizeof(printerinfo),&need,&returned);

如果函数成功,第一个打印机信息结构的pPrinterName就有了打印机名称
printerinfo[0].pPrinterName
回复
相关推荐
发帖
硬件/系统
创建于2007-09-28

2594

社区成员

VC/MFC 硬件/系统
申请成为版主
帖子事件
创建了帖子
2004-12-08 08:48
社区公告
暂无公告