title: Error adding images to CImageList(MFC)
body: <p>I am adding images to a CImageList using the following code:</p>
  
  <pre><code>CImageList ImageList;
  
  ImageList.Create(64, 64, ILC_COLOR32, 0, 1);
  
        Find image path and load image . . .
  HBITMAP hBitmap = LoadBitmapFromFile(finder.GetFilePath(), NULL, 64, 64);
  
  int nImage = ImageList.Add(CBitmap::FromHandle(hBitmap), RGB(0,0,0));
  
  HBITMAP LoadBitmapFromFile(const char* pszFilePath, HDC hDC, long lMaxHeight, long lMaxWidth)
  {
      // Macro that MFC needs to manage its state within a DLL
      AFX_MANAGE_STATE(AfxGetStaticModuleState())
  
      // The item object which will be used to read in the file
      CxImage image;
      // Load the image from the file
      if(image.Load(pszFilePath))
      {
          ResizeImage(image, lMaxHeight, lMaxWidth);
  
          // Get a handle to a bitmap version of the image which the given DC can use
          return image.MakeBitmap(hDC);
      }
      return NULL;
  }
  
  void ResizeImage(CxImage&amp; image, long lMaxHeight, long lMaxWidth)
  {
      const DWORD ulImgHeight = image.GetHeight();
      const DWORD ulImgWidth = image.GetWidth();
  
      long nHeightDif = ulImgHeight - lMaxHeight;
      long nWidthDif = ulImgWidth - lMaxWidth;
      if(nHeightDif &gt; 0 || nWidthDif &gt; 0)
      {
          double rScaleFactor = 1.0;
          if(nHeightDif &gt; nWidthDif)
              rScaleFactor = (double)lMaxHeight / (double)ulImgHeight;
          else
              rScaleFactor = (double)lMaxWidth / (double)ulImgWidth;
  
          long nNewHeight = (long)(ulImgHeight * rScaleFactor);
          long nNewWidth = (long)(ulImgWidth * rScaleFactor);
  
          image.Resample2(nNewWidth, nNewHeight);
      }
  }
  </code></pre>
  
  <p>The Add method appears to add the image but will repeatedly return the same index value for the new image.  When the image list is displayed in a list box, the same image appears for all images that were added and returned the same index, but the filename appearing below the image on the list is correct.</p>
  
  <p>I have tried several things to determine wnat is happening all to no avail.  This problem does not appear to be tied to the image size, or shape (h. vs. w.).  I have verified that the correct image is attached to the HBITMAP that the image is loaded onto by displaying the image on a picture control, but the image on the list control is incorrect.</p>
  
  <p>If I add the images using:</p>
  
  <pre><code>int nImage = ImageList.Add(CBitmap::FromHandle(hBitmap), (CBitmap *)NULL);
  </code></pre>
  
  <p>none of the duplicated images are loaded.  Instead of the repeating index Add returns -1.  I can find no documentation for the errors on a CImageList.  Does anyone know what might be happening?</p>