在Windows CE 6.0下打印

时间:2012-05-03 11:22:53

标签: printing windows-ce

我正在使用Windows CE 6.0在ARM平台上开发设备。其中一个目标是为用户提供直接从设备打印的可能性(而不仅仅是文本!)。这意味着Windows必须处理各种类型的打印机。我怎样才能实现这样的功能?

我的猜测是: - PCL打印(你还能买到PCL打印机吗?) - 网络打印(怎么做 - 任何例子?)

谢谢!

1 个答案:

答案 0 :(得分:3)

在Windows CE 6.0下可以打印。 “\ WINCE600 \ PUBLIC \ COMMON \ OAK \ DRIVERS \ PRINTER \ PCL”中有一个PCL驱动程序示例。要将它包含在OS设计中,请在Configuraiton Properties中将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驱动程序(请查看以下代码)。问题是,我无法摆脱一个错误: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;
    }