title: GetDC vs BeginPaint performance considerations
body: <p>MSDN and numerous post have suggested that BeginPaint/EndPaint should used in WM_PAINT. I've also seen numerous places suggesting that if double buffering is employed in painting, it makes more sense to initialize the DC and mem allocation in WM_CREATE and reuse those handles in WM_PAINT. </p>
  
  <p>For example, using BeginPaint, I commonly see:</p>
  
  <pre><code>case WM_PAINT:
  hdc = BeginPaint(hWnd, &amp;ps);
  MemDC = CreateCompatibleDC(hdc);
  bmp = CreateCompatibleBitmap(hdc, width, height);
  oldbmp = SelectObject(MemDC,bmp);
  g = new Graphics(MemDC);
  
  //do paint on bmp
  //blt bmp back to hdc
  
  EndPaint(hWnd, &amp;ps);
  DeleteObject(bmp);
  g-&gt;ReleaseHDC(MemDC);
  DeleteDC(MemDC);
  delete g;
  </code></pre>
  
  <p>To save the initialization and tearing down, is it possible to do this :</p>
  
  <pre><code>case WM_CREATE:
  hdc   = GetDC(hWnd);
  //create memDC and graphics object references ...
  case WM_DESTROY
  //delete memDC and graphics object references...
  case WM_PAINT
  BeginPaint(hWnd, &amp;ps);
  //use previously create mem and graphics object to paint 
  EndPaint(hWnd, &amp;ps);
  </code></pre>
  
  <p>So we only use EndPaint to clear the update region but delegate the drawing to prev created objects. </p>