2012-05-03 162 views
2

下打印我正在使用Windows CE 6.0在ARM平臺上開發設備。其中一個目標是爲用戶提供從設備直接打印的可能性(而不僅僅是文本!)。這意味着,Windows將不得不處理各種類型的打印機。我怎樣才能實現這樣的功能?在Windows CE 6.0

我的猜測是: - PCL打印(你還能得到一個PCL打印機?) - 網絡打印 -

感謝(如何做到這一點任何的例子嗎?)!

回答

3

在Windows CE 6.0下可以打印。在「\ WINCE600 \ PUBLIC \ COMMON \ OAK \ DRIVERS \ PRINTER \ PCL」中有一個PCL驅動程序的例子。要將其包含在OS Design中,請在Configuraiton Properties - > Environment中將SYSGEN_PRINTING,SYSGEN_PCL和SYSGEN_USB_PRINTER設置爲1。這將導致編譯樣本並將pcl.dll添加到OS Design。 USB打印機類驅動程序也將被添加。

上面的動作,讓我們打印的文本以ASCII碼:

// initialize printing 
    //hPrinter = CreateFile(L"LPT1:", GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL); 
    //if (hPrinter == NULL) RETAILMSG(TRUE, (L"Error in OnClick5 (GUI): CreateFile() returned NULL")); 

    // print text WORKS 
    //WriteFile(hPrinter, szText, sizeof(szText), &cBytes, NULL); 

    // close printer port 
    //CloseHandle(hPrinter); 

但打印例如BMP文件,我們需要真正使用PCL驅動程序(看下面的代碼)。問題是,我無法擺脫一個bug:StartDoc()總是返回「網絡請求不受支持」。什麼是開始打印工作的正確方法?

LPVOID lpMsgBuf = NULL; 
    HDC hdc = NULL; 
    DOCINFO di; 
    DEVMODE dm; 

    // initialize DEVMODE struct 
    memset(&dm, 0, sizeof(DEVMODE)); 
    wcscpy(dm.dmDeviceName, L"Hewlett-Packard LaserJet P3010 Series"); 
    dm.dmSize = sizeof(DEVMODE); 
    dm.dmPaperSize = DMPAPER_A4; 
    dm.dmPrintQuality = DMRES_DRAFT; 
    dm.dmFields = DM_PAPERSIZE | DM_PRINTQUALITY; 

    //PAGESETUPDLG psd; 
    //memset(&psd, 0, sizeof(psd)); 
    //psd.hwndOwner = NULL; 
    //psd.hDevMode = NULL; 
    //psd.hDevNames = NULL; 
    //psd.Flags = PSD_RETURNDEFAULT; 
    //psd.lStructSize = sizeof(psd); 

    //PageSetupDlg(&psd); 
    //RETAILMSG(TRUE, (L"GUI: PageSetupDlg() result 0x%x", CommDlgExtendedError())); 

    //if (psd.hDevMode == NULL) return -1; 

    //DEVMODE* lpdm = (DEVMODE*)psd.hDevMode; 

    DEVMODE* lpdm = &dm; 

    // initialize device context 
    hdc = CreateDC(L"pcl.dll", L"Printer", L"LPT1:", lpdm); 
    if (hdc == NULL) { 
     RETAILMSG(TRUE, (L"GUI: CreateDC() error 0x%x", GetLastError())); 
     return -1; 
    } 

    // register abort procedure 
    SetAbortProc(hdc, AbortProc); 

    // initialize DOCINFO struct 
    memset(&di, 0, sizeof(DOCINFO)); 
    di.cbSize = sizeof(DOCINFO); 
    di.lpszDocName = L"logo.bmp"; 
    di.lpszOutput = NULL; 
    di.lpszDatatype = 0; 
    di.fwType = 0; 

    // print file 
    if (StartDoc(hdc, &di) <= 0) { 
     RETAILMSG(TRUE, (L"Error in OnClick5 (GUI): StartDoc() returned non-positive value")); 
     FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, 
      NULL, GetLastError(), 0, (LPTSTR)&lpMsgBuf, 0, NULL); 
     RETAILMSG(TRUE, ((LPWSTR)lpMsgBuf)); 
     LocalFree(lpMsgBuf); 
     DeleteDC(hdc); 
     return -1; 
    } 
相關問題