枚舉計(jì)算機(jī)的所有打印機(jī)
成都創(chuàng)新互聯(lián)公司是專業(yè)的納雍網(wǎng)站建設(shè)公司,納雍接單;提供網(wǎng)站設(shè)計(jì)、網(wǎng)站制作,網(wǎng)頁(yè)設(shè)計(jì),網(wǎng)站設(shè)計(jì),建網(wǎng)站,PHP網(wǎng)站建設(shè)等專業(yè)做網(wǎng)站服務(wù);采用PHP框架,可快速的進(jìn)行納雍網(wǎng)站開發(fā)網(wǎng)頁(yè)制作和功能擴(kuò)展;專業(yè)做搜索引擎喜愛的網(wǎng)站,專業(yè)的做網(wǎng)站團(tuán)隊(duì),希望更多企業(yè)前來合作!#include <winspool.h> 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++) { TRACE(_T("x = %s\n"), prninfo->pPrinterName); TRACE(_T("x = %s\n"), prninfo->pPortName); } } }
2.設(shè)置默認(rèn)打印機(jī)
TCHAR szPrinterName[1024] = { 0 }; GetDlgItemText(IDC_EDIT1, szPrinterName, 1024); BOOL ret = FALSE; ret = SetDefaultPrinter(szPrinterName); if (ret == FALSE) AfxMessageBox(_T("設(shè)置默認(rèn)打印機(jī)失敗")); else AfxMessageBox(_T("設(shè)置默認(rèn)打印機(jī)成功"));
3.啟動(dòng)打印機(jī)服務(wù)
SHELLEXECUTEINFO ShExecInfo = { 0 }; ShExecInfo.cbSize = sizeof(SHELLEXECUTEINFO); ShExecInfo.fMask = SEE_MASK_NOCLOSEPROCESS; ShExecInfo.hwnd = NULL; ShExecInfo.lpVerb = NULL; ShExecInfo.lpFile = _T("cmd"); ShExecInfo.lpParameters = _T("/C net start spooler"); ShExecInfo.lpDirectory = NULL; ShExecInfo.nShow = SW_HIDE; ShExecInfo.hInstApp = NULL; ShellExecuteEx(&ShExecInfo); WaitForSingleObject(ShExecInfo.hProcess, INFINITE);
4.獲取指定打印機(jī)的所有紙張
TCHAR szPaperName[30000] = {0}; TCHAR str[650] = {0}; void CMFCApplication1Dlg::Printerdo1() { BYTE* pBuffer = NULL; DWORD dwSize = 0; DWORD dwNum = 0; //獲得緩沖區(qū)大小 ::EnumPrinters(PRINTER_ENUM_LOCAL, NULL, 5, pBuffer, dwSize, &dwSize, &dwNum); pBuffer = new BYTE[dwSize]; //枚舉打印機(jī) ::EnumPrinters(PRINTER_ENUM_LOCAL, NULL, 5, pBuffer, dwSize, &dwSize, &dwNum); if (dwNum != 0) { //獲得打印機(jī)信息 PRINTER_INFO_5* pPrinterInfo = (PRINTER_INFO_5*)pBuffer; LPHANDLE phandle; HANDLE handle; handle = malloc(sizeof(HANDLE)); phandle = &handle; PRINTER_DEFAULTS *printer_defaults; printer_defaults = (PRINTER_DEFAULTS *)malloc(sizeof(PRINTER_DEFAULTS)); LPWSTR str_printername, str_portname, papername2; //添加打印機(jī)名及端口 str_printername = pPrinterInfo->pPrinterName; str_portname = pPrinterInfo->pPortName; int nNeeded = 0; nNeeded = DeviceCapabilities(str_printername, str_portname, DC_PAPERNAMES, NULL, NULL); DeviceCapabilities(str_printername, str_portname, DC_PAPERNAMES, szPaperName,NULL); for (int i = 0, j=0; i < nNeeded && szPaperName[j] != 0;) { wmemcpy_s(str, 64, (LPCWSTR)(&szPaperName)+j,64); m_ListPrinter.AddString(str); TRACE(_T("%s\n"), str); j += 64; } } }
5.獲取所有紙張的尺寸
CPoint pt[107]; DeviceCapabilities(str_printername, str_printername, DC_PAPERSIZE, (LPWSTR)&pt, NULL);
6.獲取默認(rèn)打印機(jī)的默認(rèn)紙型和大小
void CMFCApplication1Dlg::OnBnClickedButton13() { // TODO: 在此添加控件通知處理程序代碼 PRINTDLG FAR * pPrintDlg = new PRINTDLG; //獲取當(dāng)前打印機(jī)的設(shè)置 if (AfxGetApp()->GetPrinterDeviceDefaults(pPrintDlg)) { //獲取打印機(jī)的兩個(gè)設(shè)置信息結(jié)構(gòu) DEVNAMES FAR*lpDevNames=(DEVNAMES FAR *)::GlobalLock(pPrintDlg->hDevNames); DEVMODE FAR*lpDevMode =(DEVMODE FAR *)::GlobalLock(pPrintDlg->hDevMode); //獲取相關(guān)信息:驅(qū)動(dòng)服務(wù)名,打印機(jī)名,端口號(hào) CString szDriver((LPTSTR)lpDevNames +lpDevNames->wDriverOffset); CString szDevice((LPTSTR)lpDevNames +lpDevNames->wDeviceOffset); CString szOutput((LPTSTR)lpDevNames +lpDevNames->wOutputOffset); HANDLE hPrinter; ::OpenPrinter((LPWSTR)(LPCWSTR)szDevice, &hPrinter, NULL); ::DocumentProperties(NULL,hPrinter,(LPWSTR)(LPCWSTR)szDevice,lpDevMode, lpDevMode, DM_IN_BUFFER | DM_OUT_BUFFER); // 結(jié)構(gòu)解鎖 ::GlobalUnlock(pPrintDlg->hDevNames); ::GlobalUnlock(pPrintDlg->hDevMode); } delete pPrintDlg; }
另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)scvps.cn,海內(nèi)外云服務(wù)器15元起步,三天無理由+7*72小時(shí)售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國(guó)服務(wù)器、虛擬主機(jī)、免備案服務(wù)器”等云主機(jī)租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡(jiǎn)單易用、服務(wù)可用性高、性價(jià)比高”等特點(diǎn)與優(yōu)勢(shì),專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場(chǎng)景需求。
網(wǎng)站題目:打印機(jī)的管理-創(chuàng)新互聯(lián)
網(wǎng)頁(yè)網(wǎng)址:http://m.newbst.com/article44/hpeee.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供全網(wǎng)營(yíng)銷推廣、Google、軟件開發(fā)、品牌網(wǎng)站建設(shè)、品牌網(wǎng)站制作、網(wǎng)站營(yíng)銷
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容
營(yíng)銷型網(wǎng)站建設(shè)知識(shí)