title: How can I add a transparent PNG as a toolbar icon?
body: <p>My intention is to create a toolbar in Win32 containing a transparent icon. I have tried the following code to create a simple toolbar with one button having a custom image:</p>
  
  <pre class="lang-cpp prettyprint-override"><code>// Create the toolbar
  HWND hToolbar = CreateWindow(TOOLBARCLASSNAME,
                               NULL,
                               WS_CHILD | TBSTYLE_FLAT | TBSTYLE_AUTOSIZE | TBSTYLE_LIST | CCS_BOTTOM,
                               0, 0, 0, 0,
                               hwnd,
                               NULL,
                               ghInstance, // &lt;-this is the HINSTANCE of the application
                               NULL);
  
  // Set the font (this cannot be the problem)
  SendMessage(hToolbar,
              WM_SETFONT,
              (WPARAM)hFontBold,
              static_cast&lt;LPARAM&gt;(MAKELONG(TRUE, 0)));
  
  auto hImagelist = ImageList_Create(32, 32,ILC_COLOR24 | ILC_MASK, 1, 0);
  
  HBITMAP bitmap = static_cast&lt;HBITMAP&gt;(LoadImage(ghInstance,
      /* ID_IMG_SPAWN is my custom resource -&gt; */ MAKEINTRESOURCE(ID_IMG_SPAWN), 
                                                  IMAGE_BITMAP,
                                                  32, 32,
                                                  NULL));
  ImageList_AddMasked(hImagelist,
                      bitmap,
                      RGB(255,255,255) /* white is the transparent color */);
  SendMessage(hToolbar,
              TB_SETIMAGELIST,
              static_cast&lt;WPARAM&gt;(0),
              (LPARAM)hImagelist);
  </code></pre>
  
  <p><code>ImageList_Create</code> only supports 24-bit bitmaps, which means there is no alpha channel for transparency. However, I can simulate a transparency effect by using a mask color via <code>ImageList_AddMasked</code>. (Here, I am setting white (<code>RGB(255, 255, 255)</code>) to the mask color.)</p>
  
  <p>This worked fine, but the image displayed this way is <em>extremely sharp/jagged</em> because of the lack of granularity in the alpha channel (each pixel is either transparent or fully opaque).</p>
  
  <p>I understand that the PNG format can solve this, since it provides a true alpha channel. I know that the PNG format is supported by Win32 ImageLists, but I don't know how to use it properly. (PNG resources can be added to Visual Studio resources, but I don't know how to use them from code.)</p>
  
  <p>I couldn't find any way to make <code>LoadImage</code> load a PNG. The only supported types are <code>IMAGE_BITMAP</code> <code>IMAGE_CURSOR</code> and <code>IMAGE_ICON</code>. I changed the resource (<code>ID_IMG_SPAWN</code>) to a PNG file and tried each of those three types one by one, but all resulted in merely a blank display like this:</p>
  
  <p><a href="https://i.stack.imgur.com/gdct1.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/gdct1.png" alt=""></a></p>
  
  <p>Can anyone help me out? How can I use <code>LoadImage</code> to load a transparent PNG and use it as a toolbar image?</p>