CDC & Blitblt
-
Hi, I've placed this code on the OnInitialUpdate if(m_pdcMemory->GetSafeHdc() == NULL) { CClientDC dc(this); OnPrepareDC(&dc); m_pdcMemory->CreateCompatibleDC(&dc); } and on the OnPaint handler the following code. CPaintDC dc(this); // device context for painting // TODO: Add your message handler code here OnPrepareDC(&dc); CRect rectUpdate; dc.GetClipBox(rectUpdate); m_pdcMemory->SelectClipRgn(NULL); m_pdcMemory->IntersectClipRect(&rectUpdate); CBrush backgroundBrush(::GetSysColor(COLOR_WINDOW)); CBrush* pOldBrush = m_pdcMemory->SelectObject(&backgroundBrush); m_pdcMemory->PatBlt(rectUpdate.left, rectUpdate.top, rectUpdate.Width(), rectUpdate.Height(), PATCOPY); OnDraw(m_pdcMemory); dc.BitBlt(rectUpdate.left, rectUpdate.top, rectUpdate.Width(), rectUpdate.Height(), m_pdcMemory, 0, 0, SRCCOPY); m_pdcMemory->SelectObject(pOldBrush); In the OnDraw I've included code to draw some stuff. but I'm unable to get any output any idea what the cause could be
-
Hi, I've placed this code on the OnInitialUpdate if(m_pdcMemory->GetSafeHdc() == NULL) { CClientDC dc(this); OnPrepareDC(&dc); m_pdcMemory->CreateCompatibleDC(&dc); } and on the OnPaint handler the following code. CPaintDC dc(this); // device context for painting // TODO: Add your message handler code here OnPrepareDC(&dc); CRect rectUpdate; dc.GetClipBox(rectUpdate); m_pdcMemory->SelectClipRgn(NULL); m_pdcMemory->IntersectClipRect(&rectUpdate); CBrush backgroundBrush(::GetSysColor(COLOR_WINDOW)); CBrush* pOldBrush = m_pdcMemory->SelectObject(&backgroundBrush); m_pdcMemory->PatBlt(rectUpdate.left, rectUpdate.top, rectUpdate.Width(), rectUpdate.Height(), PATCOPY); OnDraw(m_pdcMemory); dc.BitBlt(rectUpdate.left, rectUpdate.top, rectUpdate.Width(), rectUpdate.Height(), m_pdcMemory, 0, 0, SRCCOPY); m_pdcMemory->SelectObject(pOldBrush); In the OnDraw I've included code to draw some stuff. but I'm unable to get any output any idea what the cause could be
Hello! It's hard to tell without having the rest of the code. But I think you ought to set viewport / window origin. Because you use m_pdcMemory->IntersectClipRect(&rectUpdate); where rectUpdate is in dc coordinates. You can comment this function to check it. And if you use scrolling you must set viewport / window origin, otherwise you will always see only top / left part of your picture. With regards, Pavel Krupets
-
Hello! It's hard to tell without having the rest of the code. But I think you ought to set viewport / window origin. Because you use m_pdcMemory->IntersectClipRect(&rectUpdate); where rectUpdate is in dc coordinates. You can comment this function to check it. And if you use scrolling you must set viewport / window origin, otherwise you will always see only top / left part of your picture. With regards, Pavel Krupets
ThankQ for the suggestion I've removed the code ....... //m_pdcMemory->SelectClipRgn(NULL); //m_pdcMemory->IntersectClipRect(&rectUpdate); ........ But it still doesn't seem to work.
-
ThankQ for the suggestion I've removed the code ....... //m_pdcMemory->SelectClipRgn(NULL); //m_pdcMemory->IntersectClipRect(&rectUpdate); ........ But it still doesn't seem to work.
Hello. Sorry I've just spotted an error. You have to create and select bitmap into your off screen DC. Because by default it has 1 by 1 pixel monochrome bitmap selected. Example
HDC hDC = CreateCompatibleDC(hScreenDC); if (!hDC) return false; // Calculate dimensions long nWidth = 0; long nHeight = 0; if (pszClient) { nWidth = pszClient->cx; nHeight = pszClient->cy; } else { nWidth = GetDeviceCaps(hScreenDC, HORZRES); nHeight = GetDeviceCaps(hScreenDC, VERTRES); } // Create off-screen surface HBITMAP hBitmap = CreateCompatibleBitmap(hScreenDC, nWidth, nHeight); if (!hBitmap) { DeleteDC(hDC); return false; } // Make ours off-screen surface active m_hOldBitmap = SelectObject(m_hDC = hDC, m_hBitmap = hBitmap); return true;
With regards, Pavel Krupets -
Hello. Sorry I've just spotted an error. You have to create and select bitmap into your off screen DC. Because by default it has 1 by 1 pixel monochrome bitmap selected. Example
HDC hDC = CreateCompatibleDC(hScreenDC); if (!hDC) return false; // Calculate dimensions long nWidth = 0; long nHeight = 0; if (pszClient) { nWidth = pszClient->cx; nHeight = pszClient->cy; } else { nWidth = GetDeviceCaps(hScreenDC, HORZRES); nHeight = GetDeviceCaps(hScreenDC, VERTRES); } // Create off-screen surface HBITMAP hBitmap = CreateCompatibleBitmap(hScreenDC, nWidth, nHeight); if (!hBitmap) { DeleteDC(hDC); return false; } // Make ours off-screen surface active m_hOldBitmap = SelectObject(m_hDC = hDC, m_hBitmap = hBitmap); return true;
With regards, Pavel KrupetsThanQ very much it's working now.