标签:打印机
枚举计算机的所有打印机
PRINTER_INFO_5* prninfo = NULL; void CMFCApplication1Dlg::OnBnClickedButton8() { DWORD dwNeeded=0, dwReturned=0; EnumPrinters(PRINTER_ENUM_LOCAL, NULL, 5, NULL, 0, &dwNeeded, &dwReturned); prninfo = (PRINTER_INFO_5*)GlobalAlloc(GPTR, dwNeeded); if (EnumPrinters(PRINTER_ENUM_LOCAL, NULL, 5, (LPBYTE)prninfo, dwNeeded, &dwNeeded, &dwReturned)) { for (DWORD i = 0; i < dwReturned; i++, prninfo++) { TCHAR szBuf[256]; TRACE(_T("x = %s\n"), prninfo->pPrinterName); } } }
2.设置默认打印机
TCHAR szPrinterName[1024] = { 0 }; GetDlgItemText(IDC_EDIT1, szPrinterName, 1024); BOOL ret = FALSE; ret = SetDefaultPrinter(szPrinterName); if (ret == FALSE) AfxMessageBox(_T("设置默认打印机失败")); else AfxMessageBox(_T("设置默认打印机成功"));
3.启动打印机服务
ShellExecute(NULL, NULL, _T("cmd.exe"), _T("/C net start spooler"), NULL, SW_SHOWNORMAL);
标签:打印机
原文地址:http://blog.51cto.com/9233403/2102910