Memory DC Win2k can't work!
-
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
-
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
This has nothing to do with your problem, but why are you implementing operator-> and operator CMemoryDC* ? Tomasz Sowinski -- http://www.shooltz.com
-
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
-
Maybe the problem is that you write to window DC after it was released: pWnd->ReleaseDC(pDC); // now destructor CMemoryDC executes BitBlt