title: win32 bitmap erroneously converted to monochrome
body: <p>I'm trying to get the bits of a window icon, in order to send them through a socket. To test if I'm hable to get the BITMAP corresponding to the HICON, I save it on a file.</p>
  
  <p>The problem is that, opening the file where I've saved the bitmap, it appear monochrome (black and white, not grey scale).</p>
  
  <p>Here is the BITMAPINFO struct:</p>
  
  <pre><code>info.biSize = sizeof(BITMAPINFOHEADER);
  info.biWidth = bitmap.bmWidth;
  info.biHeight = bitmap.bmHeight;
  info.biPlanes = 1;  
  info.biBitCount = 32;
  info.biCompression = BI_RGB;    
  info.biSizeImage = 0;
  info.biXPelsPerMeter = 0;  
  info.biYPelsPerMeter = 0;     
  info.biClrUsed = 0; 
  info.biClrImportant = 0;
  </code></pre>
  
  <p>And I compute the size of the bitmap as:</p>
  
  <pre><code>DWORD dwBmpSize2 = ((bitmap.bmWidth * bi.biBitCount + 31) / 32) * 4 * bitmap.bmHeight;
  </code></pre>
  
  <p>Then:</p>
  
  <pre><code>// Starting with 32-bit Windows, GlobalAlloc and LocalAlloc are implemented as wrapper functions that 
      // call HeapAlloc using a handle to the process's default heap. Therefore, GlobalAlloc and LocalAlloc 
      // have greater overhead than HeapAlloc.
      HANDLE hDIB = GlobalAlloc(GHND, dwBmpSize);
      char *lpbitmap = (char *)GlobalLock(hDIB);
  
      //Prendo i bit dell'icona
      HDC hdc = GetDC(hwnd);
      GetDIBits(hdc, hbit, 0, (UINT)bitmap.bmHeight, lpbitmap, (BITMAPINFO*)&amp;bi,DIB_RGB_COLORS);
      wcout « "lpbitmap buffer: "« lpbitmap « endl;
  
      // A file is created, this is where we will save the screen capture.
      HANDLE hFile = CreateFile(L"captureqwsx.bmp",
        GENERIC_WRITE,
        0,
        NULL,
        CREATE_ALWAYS,
        FILE_ATTRIBUTE_NORMAL, NULL);
  
      // Add the size of the headers to the size of the bitmap to get the total file size
      DWORD dwSizeofDIB = dwBmpSize + sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER);
  
      //Offset to where the actual bitmap bits start.
      bmfHeader.bfOffBits = (DWORD)sizeof(BITMAPFILEHEADER) + (DWORD)sizeof(BITMAPINFOHEADER);
  
      //Size of the file
      bmfHeader.bfSize = dwSizeofDIB;
  
      //bfType must always be BM for Bitmaps
      bmfHeader.bfType = 0x4D42; //BM   
  
      DWORD dwBytesWritten = 0;
      WriteFile(hFile, (LPSTR)&amp;bmfHeader, sizeof(BITMAPFILEHEADER), &amp;dwBytesWritten, NULL);
      WriteFile(hFile, (LPSTR)&amp;bi, sizeof(BITMAPINFOHEADER), &amp;dwBytesWritten, NULL);
      WriteFile(hFile, (LPSTR)lpbitmap, dwBmpSize, &amp;dwBytesWritten, NULL);
  </code></pre>