title: How to convert HICON to HBITMAP in VC++?
body: <p>How to convert HICON to HBITMAP in VC++?</p>
  
  <p>I know this is an FAQ but all the solutions I've found on Google don't work. What I need is a function which takes a parameter HICON and returns HBITMAP.</p>
  
  <p>Greatest if possible to make conversion to 32-bit bitmap even the icon is 24-bit, 16-bit or 8-bit. </p>
  
  <p>This is the code, I don't know where it goes wrong:</p>
  
  <pre><code>HBITMAP icon_to_bitmap(HICON Icon_Handle) {
    HDC Screen_Handle = GetDC(NULL);
    HDC Device_Handle = CreateCompatibleDC(Screen_Handle);
  
    HBITMAP Bitmap_Handle = 
    CreateCompatibleBitmap(Device_Handle,GetSystemMetrics(SM_CXICON),
    GetSystemMetrics(SM_CYICON));
  
    HBITMAP Old_Bitmap = (HBITMAP)SelectObject(Device_Handle,Bitmap_Handle);
    DrawIcon(Device_Handle, 0,0, Icon_Handle);
    SelectObject(Device_Handle,Old_Bitmap);
  
    DeleteDC(Device_Handle);
    ReleaseDC(NULL,Screen_Handle);
    return Bitmap_Handle;
  }
  </code></pre>