title: How to use LoadImage and DeleteObject properly?
body: <p>I am working on a windows application with C++. I load a bmp file to a DC using LoadImage, and it shows up properly. However, when I call DeleteObject, the memory doesn't seem to be freed. (I use windows task manager to track the memory usage)</p>
  
  <p>In the WM_INITDIALOG part I do this:</p>
  
  <pre><code>static HBITMAP hBitmap = 0;
  char* tempPath = "tabView.bmp";  
  hBitmap = (HBITMAP)LoadImage(NULL,
                               tempPath,  // file containing bitmap
                               IMAGE_BITMAP,  // type = bitmap
                               0, 0,      // original size
                               LR_LOADFROMFILE);      // get image from a file
  if(hBitmap)
  {
      SendMessage(GetDlgItem(hwndDlg, IDC_PICTURE),
                  STM_SETIMAGE,         // message to send
                  (WPARAM)IMAGE_BITMAP, // bitmap type
                  (LPARAM)hBitmap);     // bitmap handle
  }
  </code></pre>
  
  <p>So the picture shows up in the DC, and memory increases. And in a button I do:</p>
  
  <pre><code>int result = DeleteObject(hBitmap);
  </code></pre>
  
  <p>When I press the button, I checked the result and it's a non-zero value, which is success. But IDC_PICTURE will still show the picture, and memory stays the same. I am wondering if the SendMessage() may increase the ref count on the hBitmap... </p>
  
  <p>So my question is: What is the proper way to clean up?</p>