title: C++ Win32: HDC's, HWND's, SelectObject, and GetObject
body: <p>I'm new to win32 and there are some concepts I haven't fully grasped. For one, the difference between HDC and HWND. I understand (or think I understand) that they're handles to a objects and that hdc's can be derived from hwnd's. Like in the case of BeginPaint:</p>
  
  <pre><code>hdc = BeginPaint(hWnd, &amp;ps);
  </code></pre>
  
  <p>But i don't fully understand what seperates each as certain methods have hdc as parameters and some use hwnd</p>
  
  <p>Secondly, I'm not sure what SelectObject and GetObject do. I think that they associate handles with various objects, like in the case of this bitmap drawing function:</p>
  
  <pre><code>BOOL DrawBitmap (HDC hDC, INT x, INT y, INT width, INT height, HBITMAP hBitmap, 
                   DWORD dwROP)
  {
      HDC       hDCBits;
      BITMAP    Bitmap;
      BOOL      bResult;
  
      hDCBits = CreateCompatibleDC(hDC);
      GetObject(hBitmap, sizeof(BITMAP), (LPSTR)&amp;Bitmap);
      SelectObject(hDCBits, hBitmap);
      bResult = StretchBlt(hDC, x, y, width, height,hDCBits, 0, 0, Bitmap.bmWidth,
                           Bitmap.bmHeight, dwROP);
      DeleteDC(hDCBits);
  
      return bResult;
  }
  </code></pre>
  
  <p>But despite all of this I don't understand exactly what they do or how they work. Thanks, in advance.</p>