MFC印刷问题

时间:2014-12-03 08:08:18

标签: c++ printing mfc

我为解决这个印刷问题而生气,我担心这个问题不完全符合这个社区的网络礼节,但我必须尝试。
我用MFC C ++编写了这个程序,它使用Window GDI在屏幕上生成一些自定义报告。 MSDN表示在OnPrint上使用正确的DPI重新计算进行绘制将为打印机准备好输出。很好,这就是我所做的,一切都适用于我的应用程序的几乎每个用户:

       
  • 开发,UNICODE,Windows 7,每台打印机
  •    
  • 发布,UNICODE,Windows 7,每台打印机
  •    
  • 安装1,Windows XP SP3,每台打印机
  •    
  • 安装2,Windows 7,每个打印机

但是第三次​​安装,使用Windows XP SP3,使用PDF Creator打印在纸上但,打印出正确数量的页面但完全空白。
你知道我在哪里可以搜索问题吗?如果您需要代码段或我发布的任何其他内容。

编辑Roger Rowland:


#ifndef WINVER
    #define WINVER          0x0501
#endif
#ifndef _WIN32_WINNT
    #define _WIN32_WINNT    0x0501
#endif
#ifndef _WIN32_WINDOWS
    #define _WIN32_WINDOWS  0x0410
#endif
#ifndef _WIN32_IE
    #define _WIN32_IE       0x0600
#endif

编辑2 - 打印设置
请注意,m_VDStampa是GDI绘图的包装器,因此请按原样使用。


void CMosaicoView::OnBeginPrinting( CDC *pDC, CPrintInfo *pInfo )
{
    // TODO: add extra initialization before printing
    LPDEVMODE   lpDevMode;
    PRINTDLG    pd;

    switch( m_ePrintMode )
    {
    case STAMPA_CATALOGO:
    case STAMPA_ORDINE:
    case STAMPA_PERSONALIZZATA:
        if( m_pStampa )
        {
            pd.lStructSize = (DWORD)sizeof( PRINTDLG );
            AfxGetApp()->GetPrinterDeviceDefaults( &pd );
            lpDevMode = (LPDEVMODE)::GlobalLock( pd.hDevMode );
            if( m_pStampa->m_spdDimFog.dX m_spdDimFog.dY )
                lpDevMode->dmOrientation = DMORIENT_PORTRAIT;
            else
                lpDevMode->dmOrientation = DMORIENT_LANDSCAPE;
            pDC->ResetDC( lpDevMode );
            ::GlobalUnlock( pd.hDevMode );
        }
        break;
    case STAMPA_ETICHETTE:
        if( m_pStampaEti )
        {
            pd.lStructSize = (DWORD)sizeof( PRINTDLG );
            AfxGetApp()->GetPrinterDeviceDefaults( &pd );
            lpDevMode = (LPDEVMODE)::GlobalLock( pd.hDevMode );
            if( m_pStampaEti->m_spdDimFog.dX m_spdDimFog.dY )
                lpDevMode->dmOrientation = DMORIENT_PORTRAIT;
            else
                lpDevMode->dmOrientation = DMORIENT_LANDSCAPE;
            pDC->ResetDC( lpDevMode );
            ::GlobalUnlock( pd.hDevMode );
        }
        break;
    }
    pInfo->SetMaxPage( m_lPagTot );
}

void CMosaicoView::OnPrepareDC( CDC *pDC, CPrintInfo *pInfo )
{
    // TODO: Add your specialized code here and/or call the base class
    int nY;

    if( pDC->IsPrinting() )
        nY = ( pInfo->m_nCurPage - 1 ) * pDC->GetDeviceCaps( VERTRES );
    CView::OnPrepareDC( pDC, pInfo );
}

void CMosaicoView::OnPrint( CDC *pDC, CPrintInfo *pInfo )
{
    // TODO: Add your specialized code here and/or call the base class
    BOOL        bRet;
    CPoint      pntDPI;
    CSize       szRisol;
    RECT        rctItem;
    RECT_2D     rect;
    sDatiStampa sdsDati;

// Getting the size of my sheet
    rctItem.left = 0;
    rctItem.right = szRisol.cx = pDC->GetDeviceCaps( HORZRES );
    rctItem.top = 0;
rctItem.bottom = szRisol.cy = pDC->GetDeviceCaps( VERTRES );

    pntDPI.x = pDC->GetDeviceCaps( LOGPIXELSX );
    pntDPI.y = pDC->GetDeviceCaps( LOGPIXELSY );
    if( !m_bVDStampaIniz )
    {
        bRet = m_VDStampa.Create( this, FALSE, RGB( 255, 255, 255 ) );      // bianca?
        m_VDStampa.Axes( FALSE );
        m_bVDStampaIniz = true;
    }

    m_VDStampa.ResetList();
    switch( m_eTipoStampa )
    {
    case STAMPA_ORDINE:
    case STAMPA_PERSONALIZZATA:
        m_VDStampa.AddToList( &m_DisegnaStampe );
        break;
    case STAMPA_CATALOGO:
        m_VDStampa.AddToList( &m_DisegnaCatalogo );
        break;
    case STAMPA_ETICHETTE:
        m_VDStampa.AddToList( &m_DisegnaEtichette );
        break;
    }
        rect.llc.x = 0;
    rect.llc.y = 0;
    if( m_pStampa )
    {
        rect.urc.x = m_pStampa->m_spdDimFog.dX;
        rect.urc.y = m_pStampa->m_spdDimFog.dY;
    }
    else
    {
        rect.urc.x = 210;
        rect.urc.y = 297;
    }
    bRet = m_VDStampa.SetViewport( rect );
    m_VDStampa.Resize( rctItem.right, rctItem.bottom );
    AggiornaDatiStampa( &sdsDati );
    switch( m_eTipoStampa )
    {
    case STAMPA_ORDINE:
    case STAMPA_PERSONALIZZATA:
        m_DisegnaStampe.SetDatiStampa( &sdsDati );
        m_DisegnaStampe.m_bASchermo = false;
        m_DisegnaStampe.SetPaginaStampa( pInfo->m_nCurPage - 1 );
        m_DisegnaStampe.m_pntDPI = pntDPI;
        m_DisegnaStampe.m_szRisoluzione = szRisol;
        break;
    case STAMPA_CATALOGO:
        m_DisegnaCatalogo.SetASchermo( false );
        m_DisegnaCatalogo.SetPaginaStampa( pInfo->m_nCurPage - 1 );
        break;
    case STAMPA_ETICHETTE:
        m_DisegnaEtichette.SetASchermo( false );
        m_DisegnaEtichette.SetPagStampa( pInfo->m_nCurPage - 1 );
        break;
    }
    m_VDStampa.Redraw();
    m_VDStampa.Swap( pDC, rctItem );
}

0 个答案:

没有答案