Quantcast
Channel: CodeGuru Forums - Visual C++ Programming
Viewing all articles
Browse latest Browse all 3029

bitBlt & scrolling issue

$
0
0
Hi,

Here is my code;

Code:

void RenderPage(CDC* pDC)
{
        COLORREF        clrBackground = RGB(120, 120, 120);
        CRect                rcClient;

        CSize m_size;
        CPoint m_pt;

        GetClientRect(&rcClient);

        m_size.cx = rcClient.Width();
        m_size.cy = rcClient.Height();

        if (checkInitialization)
        {
                COLORREF        clrPage = RGB(255, 255, 255);
                COLORREF        clrFrame = GetSysColor(COLOR_WINDOWFRAME);

                CBitmap*        bmpOriginal = NULL;

                HBITMAP m_hBmpOld = NULL;
                HBITMAP m_hBmpNew = NULL;

                BITMAP m_bmInfo;

                SCROLLINFO scrollInfo;

                GetScrollInfo(SB_VERT, &scrollInfo);

                int nPosY = scrollInfo.nPos;

                GetScrollInfo(SB_HORZ, &scrollInfo);

                int nPosX = scrollInfo.nPos;

                m_pt.x = rcClient.left;
                m_pt.y = rcClient.top;

                int offsetx = m_pt.x;
                int offsety = m_pt.y;

                CDC                                        dcBuffer;
                CBitmap                                bmpBuffer;

                dcBuffer.CreateCompatibleDC(pDC);
                bmpBuffer.CreateCompatibleBitmap(pDC, rcClient.Width(), rcClient.Height());
                dcBuffer.SelectObject(bmpBuffer);
                dcBuffer.FillSolidRect(&rcClient, clrBackground);

                for (UINT nPage = 0; nPage < m_nTotalPages; nPage++)
                {
                        if (
                                (m_PageInfo[nPage].m_nPageStartY >= nPosY && m_PageInfo[nPage].m_nPageStartY <= nPosY + rcClient.Height()) ||
                                (m_PageInfo[nPage].m_nPageEndY >= nPosY && m_PageInfo[nPage].m_nPageEndY <= nPosY + rcClient.Height()) ||
                                (m_PageInfo[nPage].m_nPageStartY <= nPosY && m_PageInfo[nPage].m_nPageEndY >= nPosY + rcClient.Height())
                                )
                        {

                                switch (scaleType)
                                {
                                        case scaling::eFitWidth:
                                                m_hBmpNew = jmSDK->createImageFromPage(m_PageInfo[nPage].m_nPageNum, m_size.cx  * m_dbScaleFactor, 0, m_PageInfo[nPage].m_nRotation);
                                                break;
                                        case scaling::eFitPage:
                                                m_hBmpNew = jmSDK->createImageFromPage(m_PageInfo[nPage].m_nPageNum, 0, m_size.cy * m_dbScaleFactor, m_PageInfo[nPage].m_nRotation);
                                                break;
                                        case scaling::eFitActual:
                                        default:
                                                m_hBmpNew = jmSDK->createImageFromPage(m_PageInfo[nPage].m_nPageNum, 0, m_size.cx, m_PageInfo[nPage].m_nRotation);
                                                break;
                                }

                                HBITMAP CreateCompatibleBitmap(m_hBmpNew);

                                m_hBmpOld = (HBITMAP)SelectObject(dcBuffer, m_hBmpNew);

                                GetObject(m_hBmpNew, sizeof(BITMAP), &m_bmInfo);

                                if (m_bmInfo.bmWidth <= m_size.cx)
                                {
                                        if (m_size.cx - m_bmInfo.bmWidth == 0)
                                                offsetx = m_pt.x;
                                        else
                                                offsetx = m_pt.x + (m_size.cx - m_bmInfo.bmWidth) / 2;
                                }

                                if (m_bmInfo.bmHeight <= m_size.cy)
                                {
                                        if ((m_size.cy - m_bmInfo.bmHeight) == 0)
                                                offsety = m_pt.y;
                                        else
                                                offsety = m_pt.y + ((m_size.cy - m_bmInfo.bmHeight) / 2);
                                }

                                try
                                {
                                        pDC->FillSolidRect(&rcClient, clrBackground);
                                }
                                catch (Error &e)
                                {

                                }
                        }
                        else
                        {

                        }
                }

                bmpOriginal = (CBitmap*)pDC->SelectObject(bmpBuffer);
                pDC->BitBlt(offsetx, offsety, rcClient.Width(), rcClient.Height(), &dcBuffer, 0, 0, SRCCOPY);
                pDC->SelectObject(bmpOriginal);

                dcBuffer.DeleteDC();
                bmpBuffer.DeleteObject();
        }
        else
                pDC->FillSolidRect(&rcClient, clrBackground);
}

If I comment out;

Code:

m_hBmpOld = (HBITMAP)SelectObject(dcBuffer, m_hBmpNew);
and I have 0 , 0 instead of offsetx and offsety in the bitBlt, I get the following output;

https://hostr.co/file/970/g60huNooRd...t7.56.10PM.png

If I uncomment the selectObject and use offsetx and offsety in the bitBlt, I get the following output;

https://hostr.co/file/970/jnKBVc0AJx...t7.58.06PM.png

The second image is of a bitmap that is being scrolled down.

I return TRUE in EraseBckgrnd.

How can I fix this? I literally have tried everything.

If I use nPosX and nPosY, only one bitmap is rendered on the screen.

All help is appreciated.

Viewing all articles
Browse latest Browse all 3029

Latest Images

Trending Articles



Latest Images