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. Memory DC Win2k can't work!

Memory DC Win2k can't work!

Scheduled Pinned Locked Moved C / C++ / MFC
c++performancehelptutorialquestion
4 Posts 3 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.
  • R Offline
    R Offline
    RichardWdy
    wrote on last edited by
    #1

    I have a program derived form CMemDC. It can work perfectly in Win98, but it doesn't work in win2k. What's the problem and how to solve it? class CMemDC : public CDC { private: CBitmap m_bitmap; CBitmap* m_oldBitmap; CDC* m_pDC; CRect m_rect; public: CMemoryDC(CDC* pDC, CRect rcClip) : CDC(), m_oldBitmap(NULL), m_pDC(pDC) { CreateCompatibleDC(pDC); pDC->GetClipBox(&m_rect); IntersectRect(m_rect, rcClip, m_rect); m_bitmap.CreateCompatibleBitmap(pDC, m_rect.Width(), m_rect.Height()); m_oldBitmap = SelectObject(&m_bitmap); SetWindowOrg(m_rect.left, m_rect.top); } ~CMemoryDC() { m_pDC->BitBlt(m_rect.left, m_rect.top, m_rect.Width(), m_rect.Height(), this, m_rect.left, m_rect.top, SRCCOPY); SelectObject(m_oldBitmap); } CMemoryDC* operator->() { return this; } operator CMemoryDC*() { return this; } }; Usage: { CWnd * pWnd = GetDlgItem (IDC_MY_PANEL); CDC * pDC = pWnd->GetDC(); CMemDC MemDC(pDC, m_rcDest); MemDC.FillSolidRect(&m_rcDest, RGB(255, 255, 255)); MemDC.DrawText("Display here", rectDest, DT_SINGLELINE|DT_NOCLIP|DT_CENTER|DT_VCENTER); ...... pWnd->ReleaseDC(pDC); } Windows2000 SP2, VC++ 6.0 SP5

    T L 2 Replies Last reply
    0
    • R RichardWdy

      I have a program derived form CMemDC. It can work perfectly in Win98, but it doesn't work in win2k. What's the problem and how to solve it? class CMemDC : public CDC { private: CBitmap m_bitmap; CBitmap* m_oldBitmap; CDC* m_pDC; CRect m_rect; public: CMemoryDC(CDC* pDC, CRect rcClip) : CDC(), m_oldBitmap(NULL), m_pDC(pDC) { CreateCompatibleDC(pDC); pDC->GetClipBox(&m_rect); IntersectRect(m_rect, rcClip, m_rect); m_bitmap.CreateCompatibleBitmap(pDC, m_rect.Width(), m_rect.Height()); m_oldBitmap = SelectObject(&m_bitmap); SetWindowOrg(m_rect.left, m_rect.top); } ~CMemoryDC() { m_pDC->BitBlt(m_rect.left, m_rect.top, m_rect.Width(), m_rect.Height(), this, m_rect.left, m_rect.top, SRCCOPY); SelectObject(m_oldBitmap); } CMemoryDC* operator->() { return this; } operator CMemoryDC*() { return this; } }; Usage: { CWnd * pWnd = GetDlgItem (IDC_MY_PANEL); CDC * pDC = pWnd->GetDC(); CMemDC MemDC(pDC, m_rcDest); MemDC.FillSolidRect(&m_rcDest, RGB(255, 255, 255)); MemDC.DrawText("Display here", rectDest, DT_SINGLELINE|DT_NOCLIP|DT_CENTER|DT_VCENTER); ...... pWnd->ReleaseDC(pDC); } Windows2000 SP2, VC++ 6.0 SP5

      T Offline
      T Offline
      Tomasz Sowinski
      wrote on last edited by
      #2

      This has nothing to do with your problem, but why are you implementing operator-> and operator CMemoryDC* ? Tomasz Sowinski -- http://www.shooltz.com

      1 Reply Last reply
      0
      • R RichardWdy

        I have a program derived form CMemDC. It can work perfectly in Win98, but it doesn't work in win2k. What's the problem and how to solve it? class CMemDC : public CDC { private: CBitmap m_bitmap; CBitmap* m_oldBitmap; CDC* m_pDC; CRect m_rect; public: CMemoryDC(CDC* pDC, CRect rcClip) : CDC(), m_oldBitmap(NULL), m_pDC(pDC) { CreateCompatibleDC(pDC); pDC->GetClipBox(&m_rect); IntersectRect(m_rect, rcClip, m_rect); m_bitmap.CreateCompatibleBitmap(pDC, m_rect.Width(), m_rect.Height()); m_oldBitmap = SelectObject(&m_bitmap); SetWindowOrg(m_rect.left, m_rect.top); } ~CMemoryDC() { m_pDC->BitBlt(m_rect.left, m_rect.top, m_rect.Width(), m_rect.Height(), this, m_rect.left, m_rect.top, SRCCOPY); SelectObject(m_oldBitmap); } CMemoryDC* operator->() { return this; } operator CMemoryDC*() { return this; } }; Usage: { CWnd * pWnd = GetDlgItem (IDC_MY_PANEL); CDC * pDC = pWnd->GetDC(); CMemDC MemDC(pDC, m_rcDest); MemDC.FillSolidRect(&m_rcDest, RGB(255, 255, 255)); MemDC.DrawText("Display here", rectDest, DT_SINGLELINE|DT_NOCLIP|DT_CENTER|DT_VCENTER); ...... pWnd->ReleaseDC(pDC); } Windows2000 SP2, VC++ 6.0 SP5

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        Maybe the problem is that you write to window DC after it was released: pWnd->ReleaseDC(pDC); // now destructor CMemoryDC executes BitBlt

        L 1 Reply Last reply
        0
        • L Lost User

          Maybe the problem is that you write to window DC after it was released: pWnd->ReleaseDC(pDC); // now destructor CMemoryDC executes BitBlt

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          Thank you vrey much! I have solved it!:) :) :)

          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