我得打印程序,在联想喷墨打印机上打印文本+图片正常,看在HP得激光打印机上打印就只能打印文本,无法输出图片!用IE在HP上打印图片可以!哪位大哥帮帮忙,看看是什么问题!
另:求打印编程详细资料!
谢谢! 

解决方案 »

  1.   

    http://www.codeproject.com/printing/printlib.asp
    http://www.codeproject.com/printing/printingmadeeasy.asp
      

  2.   

    春节回来,顶一下!
    我用CVIEW做打印预览测试时,可以正常显示但是在问题也是在激光打印机无法打印图片!
    下面是我的打印代码:请哪位大哥帮我看看!
    //报表打印函数
    BOOL CLableReport::Draw(CDC *pDC)
    {
    if (m_iLableCnt <= 0) 
    {
    //没有标签,直接返回
    return TRUE;
    }
    ASSERT(pDC != NULL);
    if (pDC->IsPrinting()) 
    {
    m_rectView.left += pDC->GetDeviceCaps(PHYSICALOFFSETX);
    m_rectView.top += pDC->GetDeviceCaps(PHYSICALOFFSETY);
    }
    pDC->DPtoLP(&m_rectView);
    m_rectView.top -= m_uTop;
    m_rectView.bottom += m_uBottom;
    m_rectView.left += m_uLeft;
    m_rectView.right -= m_uRight; CRImage* pRImage = (CRImage*)m_arrReportCtrl.GetAt(0);
    ASSERT(pRImage != NULL);
    CRLine* pRLine = (CRLine*)m_arrReportCtrl.GetAt(1);
    ASSERT(pRLine != NULL);
    CSize sizeImage = pRImage->GetImageSize(pDC); //计算行列数以及打印页数;
    int nColumnCount = m_rectView.Width() / (sizeImage.cx + m_uColumnDist);
    int nLineCountOfPage = 3;
    int iPageCount = 1;
    if (pDC->IsPrinting()) 
    {
    nLineCountOfPage = abs(m_rectView.Height()) / max(1, (sizeImage.cy + m_uLineDist));
    } if (nColumnCount <= 0) 
    {
    //列不够宽
    m_strError = "列宽度不够,无法显示图片!";
    return FALSE;
    }
    if (m_iLableCnt < nColumnCount) 
    {
    nColumnCount = m_iLableCnt;
    nLineCountOfPage = 1;
    }
    else
    {
    if (m_iLableCnt  <= nLineCountOfPage * nColumnCount ) 
    {
    nLineCountOfPage = m_iLableCnt / nColumnCount;
    if (m_iLableCnt % nColumnCount != 0) 
    {
    ++nLineCountOfPage;
    }
    }
    else
    {
    iPageCount = m_iLableCnt / (nLineCountOfPage * nColumnCount);
    if (m_iLableCnt % (nLineCountOfPage * nColumnCount) != 0) 
    {
    ++iPageCount;
    }
    }
    } //输出标签到DC
    int nLine, nColumn, nText;
    int xStartPos, yStartPos;
    int iPrintedLableCnt = 0;
    int iPage = 0;
    CRect rectLine;
    CString strPrintPage;
    while( iPage < iPageCount )
    {
    //输出图片
    CFont fontText;
    CFont *fontOld;
    int iFontHeight = 20;
    fontText.CreateFont(iFontHeight,0,0,0,FW_NORMAL,FALSE,FALSE,FALSE,DEFAULT_CHARSET,
    OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY,VARIABLE_PITCH | FF_DONTCARE,"宋体");
    int iTextCnt = m_pastrText->GetSize();
    //pDC->SelectObject(fontText);
    CRect rectClippedText; 
    for (nLine = 0; nLine < nLineCountOfPage; ++nLine)
    {
    for ( nColumn = 0; nColumn < nColumnCount; ++nColumn)
    {
    xStartPos = m_rectView.left + (sizeImage.cx + m_uColumnDist) * nColumn;
    yStartPos = (m_rectView.top - (sizeImage.cy + m_uLineDist) * nLine);
    rectClippedText.left = 40 + xStartPos;
    rectClippedText.right = rectClippedText.left + sizeImage.cx;
    for ( nText = 0; nText < iTextCnt; ++nText)
    {
    rectClippedText.top = yStartPos;
    rectClippedText.bottom = rectClippedText.top - iFontHeight;
    pDC->ExtTextOut(40 + xStartPos, yStartPos, ETO_CLIPPED, rectClippedText, m_pastrText->GetAt(nText), NULL);
    yStartPos -= iFontHeight;
    }
    CPoint pntStart(xStartPos, yStartPos);
    pDC->LPtoDP(&pntStart);
    pRImage->SetImageStartPoint(pntStart);
    pRImage->Draw(pDC);
    ++iPrintedLableCnt;
    if (iPrintedLableCnt >= m_iLableCnt) 
    {
    nLine = nLineCountOfPage + 1;
    break;
    }
    }
    } //显示模式下,只显示一页
    if (!pDC->IsPrinting()) 
    {
    break;
    }
    ++iPage;
    }
    return TRUE;
    }//图片打印函数
    void CRImage::Draw(CDC *pDC)
    {
    ASSERT(pDC != NULL); /********************************************
             m_hMemedc为显示器DC,里面存放图片代码为:
    m_hMemdc = ::CreateCompatibleDC(::GetDC(NULL));
    if (m_hMemdc == NULL) 
    {
    throw CReportException();
    return;
    }
    ::SelectObject( m_hMemdc, m_hImage);
    *******************************************/
    ::SetMapMode(m_hMemdc, pDC->GetMapMode());
    CSize sizeImage, sizeScreenImage;
    sizeImage = GetImageSize(pDC);
    sizeScreenImage = m_sizeImage;
    CDC::FromHandle(m_hMemdc)->DPtoLP((LPSIZE)&sizeScreenImage);
    CRect Dest;
    Dest = m_rectRCtrl; pDC->DPtoLP(&Dest);
    pDC->StretchBlt(Dest.left ,Dest.top ,
    sizeImage.cx, -sizeImage.cy,
    // Dest.Width(), Dest.Height(),
    (CDC::FromHandle (m_hMemdc)),
    0, 0,
    sizeScreenImage.cx,-sizeScreenImage.cy,
    SRCCOPY);
    }
      

  3.   

    我感觉跟驱动关系不是很大,因为如果驱动有问题,那么IE应该也不对,我感觉是不是在处理DC的时候的问题,我是猜得,参考一下,很有可能不对
      

  4.   

    TO: wangk(倒之) 
    从你提供的两个网址中,下载了一个CPAGE的打印类,它可以正确的输出图片到激光打印机。它用的是下面的两个打印函数!
    BOOL WINAPI PrintTheBitMap(PRTTYPE *ps)
    {
    BITMAPINFOHEADER bi;
        RECT             Rect;
    if(InitDIB(ps)==FALSE)
    return FALSE;   
        DibInfo(hbiCurrent, &bi);    if (!IsRectEmpty(&rcClip))
        {
              bi.biWidth  = rcClip.right  - rcClip.left;
              bi.biHeight = rcClip.bottom - rcClip.top;
        }
              /* Fix bounding rectangle for the picture .. */    Rect.top    = ps->rc.top;
        Rect.left   = ps->rc.left;
        Rect.bottom = ps->rc.bottom-ps->rc.top;
        Rect.right  = ps->rc.right-ps->rc.left;
    ps->rc.right=Rect.right;
    ps->rc.bottom=Rect.bottom;
    /* ... and inform the driver */
        ps->pDC->Escape(SET_BOUNDS, sizeof(RECT), (LPSTR)&Rect, NULL);
        PrintDIB(ps, ps->rc.left, ps->rc.top, ps->rc.right, ps->rc.bottom);
        FreeDib();
      return TRUE;
    }
    void WINAPI PrintDIB (PRTTYPE *ps, int x, int y, int dx, int dy)
    {
        BITMAPINFOHEADER bi;
        int dibX,  dibY;
        int dibDX, dibDY;    if (!bLegitDraw)
            return;    DibInfo (hbiCurrent, &bi);    if (IsRectEmpty (&rcClip)){
            dibX  = 0;
            dibY  = 0;
            dibDX = (int)bi.biWidth;
            dibDY = (int)bi.biHeight;
        }
        else{
            dibX  = rcClip.left;
            dibY  = (int)bi.biHeight - 1 - rcClip.bottom;
            dibDX = rcClip.right  - rcClip.left;
            dibDY = rcClip.bottom - rcClip.top;
        }    if (hdibCurrent){
            /* Stretch the DIB to printer DC */
            StretchDibBlt ( ps->pDC->GetSafeHdc(),
                            x,
                            y,
                            dx,
                            dy,
                            hdibCurrent,
                            dibX,
                            dibY,
                            dibDX,
                            dibDY,
                            SRCCOPY);
        }不知道为什么程序中用StretchBlt不能正确送到激光打印机打印,而可以送到喷墨打印机中。
    为什么?学习中...........