工控编程吧
标题:
上位机MFC如何枚举打印机
[打印本页]
作者:
qq263946146
时间:
2019-8-3 10:26
标题:
上位机MFC如何枚举打印机
打印机全部的获取可以使用函数EnumPrinters。
具体的调用 方法查看下面按钮代码。
void CDemoDlg::OnTest()
{
CListCtrl* pList = (CListCtrl*)GetDlgItem(IDC_LIST);
pList->DeleteAllItems();
pList->SetRedraw(FALSE);
BYTE* pBuffer = NULL;
DWORD dwSize = 0;
DWORD dwNum = 0;
//获得缓冲区大小
::EnumPrinters(PRINTER_ENUM_LOCAL, NULL, 5, pBuffer, dwSize, &dwSize, &dwNum);
pBuffer = new BYTE[dwSize];
//枚举打印机
::EnumPrinters(PRINTER_ENUM_LOCAL, NULL, 5, pBuffer, dwSize, &dwSize, &dwNum);
if (dwNum != 0)
{
//获得打印机信息
PRINTER_INFO_5* pPrinterInfo = (PRINTER_INFO_5*)pBuffer;
for (DWORD n = 0; n < dwNum; n++)
{
pList->InsertItem(n, pPrinterInfo[n].pPrinterName);
pList->SetItemText(n, 1, pPrinterInfo[n].pPortName);
}
}
pList->SetRedraw(TRUE);
}
复制代码
[MFC408]1[/MFC408]
[weixinlianxi]1[/weixinlianxi]
欢迎光临 工控编程吧 (https://www.gkbc8.com/)
Powered by Discuz! X3.4