CDCHandle谨慎使用

 LRESULT OnPaint(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
 {
  //HDC hdc = (HDC)wParam
  CPaintDC dc(m_hWnd);
  DoPaint(dc);
  
  bHandled = FALSE;  
  return 0;
 }

 void DoPaint(CPaintDC& dc)
 {

  CDCHandle _dc;
  HDC hdcDestop = ::GetDC(NULL);
  _dc.CreateCompatibleDC(hdcDestop);
  _dc.SelectBitmap(bitmap);

  
  
  dc.StretchBlt(rect.left, rect.top, rect.right, rect.bottom, _dc, 0, 0, 20, 20, SRCCOPY);

  ::ReleaseDC(NULL, hdcDestop);
  _dc.DeleteDC();
 }

 

如果此时 没有  _dc.DeleteDC(); 那么重新事件后 界面会成空白

 

 

dc使用原则.

Create用Delete

Get用Release

posted @ 2011-02-24 15:44  MokLiu  阅读(617)  评论(0编辑  收藏  举报