HANDLE hPRN = CreateFile("prn"...);
if(hPRN)
{
    WriteFile(hPRN, "asdf中文asdf"...)
    CloseHandle(hPRN);
}为什么打印时"中文"两个子没有打印出来!?

解决方案 »

  1.   

    你仅仅是发送了几个字符给打印机,并不是一个打印文件,打印文件是按照打印机语言生成的二进制或者文本文件(依靠不同的驱动程序),打印机能理解出来asdf就不错了呵呵,打印机怎们能直接接受文本
      

  2.   

    bluebohe(薄荷):那有没有办法实现直接打印一段文本?
      

  3.   

    打印这个东西,是要用什么StartDoc那一堆的函数的,和在屏幕上画很像的,不过一个是hdc是屏幕的,一个是打印机的而已。不过我一看打印那几个函数就烦
      

  4.   

    向楼上说的那样,你要得到这个打印机的DC,然后在DC上面写写画画,,然或结束打印就OK拉,建议你跟踪进去OnPrint等函数,就能知道Windows是怎样打印的了
      

  5.   

    换行只是改变输出的X坐标,翻页应该是EndDoc吧,忘光了,以前是作这个的还
      

  6.   

    翻页是EndPage,打印结束是EndDoc
    MSDN里面有一段代码
        memset( &di, 0, sizeof(DOCINFO) );
        di.cbSize = sizeof(DOCINFO); 
        di.lpszDocName = "Bitmap Printing Test"; 
        di.lpszOutput = (LPTSTR) NULL; 
        di.lpszDataType = (LPTSTR) NULL; 
        di.fwType = 0; 
     
        // Begin a print job by calling the StartDoc function. 
     
        nError = StartDoc(pd.hDC, &di); 
        if (nError == SP_ERROR) 
        { 
            errhandler("StartDoc", hwnd); 
            goto Error; 
        } 
     
        // Inform the driver that the application is about to begin 
        // sending data. 
     
        nError = StartPage(pd.hDC); 
        if (nError <= 0) 
        { 
            errhandler("StartPage", hwnd); 
            goto Error; 
        } 
     
        // Retrieve the number of pixels-per-logical-inch in the 
        // horizontal and vertical directions for the display upon which 
        // the bitmap was created. These are likely the same as for 
        // the present display, so we use those values here. 
     
        hWinDC = GetDC(hWnd);
        fLogPelsX1 = (float) GetDeviceCaps(hWinDC, LOGPIXELSX); 
        fLogPelsY1 = (float) GetDeviceCaps(hWindDC, LOGPIXELSY); 
     
        // Retrieve the number of pixels-per-logical-inch in the 
        // horizontal and vertical directions for the printer upon which 
        // the bitmap will be printed. 
     
        fLogPelsX2 = (float) GetDeviceCaps(pd.hDC, LOGPIXELSX); 
        fLogPelsY2 = (float) GetDeviceCaps(pd.hDC, LOGPIXELSY); 
     
        // Determine the scaling factors required to print the bitmap and 
        // retain its original proportions. 
     
        if (fLogPelsX1 > fLogPelsX2) 
            fScaleX = (fLogPelsX1 / fLogPelsX2); 
        else fScaleX = (fLogPelsX2 / fLogPelsX1); 
     
        if (fLogPelsY1 > fLogPelsY2) 
            fScaleY = (fLogPelsY1 / fLogPelsY2); 
        else fScaleY = (fLogPelsY2 / fLogPelsY1); 
     
        // Compute the coordinates of the upper left corner of the 
        // centered bitmap. 
     
        cWidthPels = GetDeviceCaps(pd.hDC, HORZRES); 
        xLeft = ((cWidthPels / 2) - ((int) (((float) bmih.biWidth) 
                * fScaleX)) / 2); 
        cHeightPels = GetDeviceCaps(pd.hDC, VERTRES); 
        yTop = ((cHeightPels / 2) - ((int) (((float) bmih.biHeight) 
                * fScaleY)) / 2); 
     
        // Use StretchDIBits to scale the bitmap and maintain 
        // its original proportions (that is, if the bitmap was square 
        // when it appeared in the application's client area, it should 
        // also appear square on the page). 
     
        if (StretchDIBits(pd.hDC, xLeft, yTop, (int) ((float) bmih.biWidth 
            * fScaleX), (int) ((float) bmih.biHeight * fScaleY), 0, 0, 
            bmih.biWidth, bmih.biHeight, lpBits, lpBitsInfo, iUsage, 
            SRCCOPY) == GDI_ERROR) 
        {
            errhandler("StretchDIBits Failed", hwnd); 
        }
     
     
        // Retrieve the width of the string that specifies the full path 
        // and filename for the file that contains the bitmap. 
     
        GetTextExtentPoint32(pd.hDC, ofn.lpstrFile, 
            ofn.nFileExtension + 3, &szMetric); 
     
        // Compute the starting point for the text-output operation. The 
        // string will be centered horizontally and positioned three lines 
        // down from the top of the page. 
     
        xLeft = ((cWidthPels / 2) - (szMetric.cx / 2)); 
        yTop = (szMetric.cy * 3); 
     
        // Print the path and filename for the bitmap, centered at the top 
        // of the page. 
     
        TextOut(pd.hDC, xLeft, yTop, ofn.lpstrFile, 
            ofn.nFileExtension + 3); 
     
        // Determine whether the user has pressed the Cancel button in the 
        // AbortPrintJob dialog box; if the button has been pressed, call 
        // the AbortDoc function. Otherwise, inform the spooler that the 
        // page is complete. 
     
        nError = EndPage(pd.hDC); 
     
        if (nError <= 0) 
        { 
            errhandler("EndPage", hwnd); 
            goto Error; 
        } 
     
        // Inform the driver that document has ended. 
     
        nError = EndDoc(pd.hDC); 
        if (nError <= 0) 
            errhandler("EndDoc", hwnd); 
     
    Error: 
        // Enable the application's window. 
     
        EnableWindow(hwnd, TRUE); 
     
        // Remove the AbortPrintJob dialog box. 
     
        DestroyWindow(hdlgCancel); 
     
        // Delete the printer DC. 
     
        DeleteDC(pd.hDC); 
      

  7.   

    谢谢大家的出谋划策,由尤其是bluebohe(薄荷) 。开始散分!