I'd like to know how to print all the FormView screens

65 views Asked by At

I added Formview screen to Dialog and dynamically added controls to Formview screen. With more control, scrolling appeared on the Formview screen. In this situation, when I try to output the Formview screen to the printer, only the truncated screen that has not been scrolled is visible. Like this

How can I modify it to get all the scrolled screens?This is the code I wrote to output the Formview screen.

void DIReportView::OnPrepareDC(CDC* pDC, CPrintInfo* pInfo)
{
    // TODO: Add your specialized code here and/or call the base class
    if (pInfo)
    {
        CClientDC dc(this);
        pDC->SetMapMode(MM_ANISOTROPIC);

        CSize sz(dc.GetDeviceCaps(LOGPIXELSX), dc.GetDeviceCaps(LOGPIXELSY));
        pDC->SetWindowExt(sz);
        sz = CSize(pDC->GetDeviceCaps(LOGPIXELSX), pDC->GetDeviceCaps(LOGPIXELSY));
        pDC->SetViewportExt(sz);
    }
}

BOOL DIReportView::OnPreparePrinting(CPrintInfo* pInfo)
{
    pInfo->SetMaxPage(1);

    pInfo->m_pPD->m_pd.Flags &= ~PD_NOSELECTION;
    pInfo->m_pPD->m_pd.hInstance = AfxGetInstanceHandle();

    // default preparation
    return DoPreparePrinting(pInfo);
}

void DIReportView::OnBeginPrinting(CDC* pDC, CPrintInfo* pInfo)
{
    
}

void DIReportView::OnEndPrinting(CDC* pDC, CPrintInfo* pInfo)
{
}

void DIReportView::OnPrint(CDC* pDC, CPrintInfo* pInfo)
{
    if (pInfo == NULL)
        return;

    if (m_dib.GetHandle() == NULL)
        return;
    {
        GLock lock(m_dib);
        BITMAPINFOHEADER* pBMI = (BITMAPINFOHEADER*)(LPVOID)lock;

        int nColors = 0;
        if (pBMI->biBitCount <= 8)
            nColors = (1 << pBMI->biBitCount);

        ::StretchDIBits(pDC->GetSafeHdc(),
            pInfo->m_rectDraw.left,
            pInfo->m_rectDraw.top,
            pBMI->biWidth,
            pBMI->biHeight,
            0,
            0,
            pBMI->biWidth,
            pBMI->biHeight,
            (LPBYTE)pBMI + (pBMI->biSize + nColors * sizeof(RGBQUAD)),
            (BITMAPINFO*)pBMI,
            DIB_RGB_COLORS,
            SRCCOPY);
    }
    //pDC->SetMapMode(MM_ANISOTROPIC);
    //pDC->SetWindowExt(m_pMemDC->GetDeviceCaps(LOGPIXELSX), m_pMemDC->GetDeviceCaps(LOGPIXELSY));
    //pDC->SetViewportExt(pDC->GetDeviceCaps(LOGPIXELSX), pDC->GetDeviceCaps(LOGPIXELSY));
    //pDC->StretchBlt(0, 0, m_rect.Width(), m_rect.Height(), m_pMemDC, 0, 0, m_rect.Width(), m_rect.Height(), SRCCOPY);

}

void DIReportView::OnFilePrintPreview()
{
    _grapImage();
    CFormView::OnFilePrintPreview();
}

void DIReportView::OnFilePrint()
{
    _grapImage();
    CFormView::OnFilePrint();
    
}

void DIReportView::_grapImage()
{
    //Grap Image
    CPoint oldPoint = GetScrollPosition();
    CPoint pt(0, 0);//scroll to up
    this->ScrollToPosition(pt);
    
    CClientDC dc(this);
    CRect rect;
    this->GetClientRect(rect);
    
    m_dib.Attach(GDIUtil::GrabDIB(&dc, rect));

    ScrollToPosition(oldPoint);
}

0

There are 0 answers