더블버퍼링용 SmartMemory Class
class SmartMemoryDC { public: CDC m_MemDC; CBitmap m_Bitmap, *m_OldBitmap; SmartMemoryDC( CDC* pDC, CRect& rect ) { m_MemDC.CreateCompatibleDC( pDC ); m_Bitmap.CreateCompatibleBitmap( pDC, rect.Width(), rect.Height() ); m_OldBitmap = m_MemDC.SelectObject( &m_Bitmap ); } ~SmartMemoryDC() { m_MemDC.SelectObject( m_OldBitmap ); } CDC* operator()() { return &m_MemDC; } CDC* operator->() { return &m_MemDC; } CDC* GetDC() { return &m_MemDC; } };
GDI+ 셋팅
void CSystemMonitorView::OnSize(UINT nType, int cx, int cy) { CScrollView::OnSize(nType, cx, cy); m_iWidth = cx; m_iHeight = cy; // TODO: 여기에 메시지 처리기 코드를 추가합니다. CClientDC dc(this); SAFE_DELETE(pMemDC); pMemDC = new SmartMemoryDC(&dc, CRect( 0, 0, cx, cy ) ); }
void CSystemMonitorView::OnDraw(CDC* pDC) { CGraphicAnalysisDoc* pDoc = GetDocument(); CPoint scrollPosition = GetScrollPosition(); Graphics graphics(pMemDC->GetDC()->GetSafeHdc()); //배경화면 색 SolidBrush solidBrush(Color(255, 255, 255, 255)); graphics.FillRectangle(&solidBrush, 0, 0, m_iWidth, m_iHeight); pDC->BitBlt( scrollPosition.x, 0, m_iWidth, m_iHeight, (*pMemDC)(), 0, 0, SRCCOPY ); }
댓글
* 단축키는 한글/영문 대소문자로 이용 가능하며, 티스토리 기본 도메인에서만 동작합니다.