Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. CDC & Blitblt

CDC & Blitblt

Scheduled Pinned Locked Moved C / C++ / MFC
5 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Offline
    V Offline
    vijayaramaraju
    wrote on last edited by
    #1

    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

    P 1 Reply Last reply
    0
    • V vijayaramaraju

      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

      P Offline
      P Offline
      Pavel Krupets
      wrote on last edited by
      #2

      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

      V 1 Reply Last reply
      0
      • P 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

        V Offline
        V Offline
        vijayaramaraju
        wrote on last edited by
        #3

        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.

        P 1 Reply Last reply
        0
        • V vijayaramaraju

          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.

          P Offline
          P Offline
          Pavel Krupets
          wrote on last edited by
          #4

          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

          V 1 Reply Last reply
          0
          • P 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 Krupets

            V Offline
            V Offline
            vijayaramaraju
            wrote on last edited by
            #5

            ThanQ very much it's working now.

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups