title: System Icons Retrieval in C# 1.0 and Alpha Channels
body: <p>In a .NET 1.0 C# application, I wish to display a list of files and folders in a listview control. I want to programmatically retrieve from windows the icons for the files or folders to display them appropriately in the list view.</p>
  
  <p>At present, I am using the Windows API Shell32.dll, but am having problems with the alpha channel in the icons (the backgrounds of the icons are showing up as black, rather than white / transparent).</p>
  
  <p>Below are two code extracts showing the API I'm trying to use, and the implemented code to retrieve the system icon for a folder (the code for the file is similar).</p>
  
  <pre><code>    [DllImport("Shell32.dll")]
      public static extern IntPtr SHGetFileInfo(
          string pszPath,
          uint dwFileAttributes,
          ref SHFILEINFO psfi,
          uint cbFileInfo,
          uint uFlags
          );
  </code></pre>
  
  <p>... <em>(note : Shell32 is a wrapper class for the above API)</em></p>
  
  <pre><code>// Get the folder icon
              Shell32.SHFILEINFO shfi = new Shell32.SHFILEINFO();
              Shell32.SHGetFileInfo(  null, 
                  Shell32.FILE_ATTRIBUTE_DIRECTORY, 
                  ref shfi, 
                  (uint) System.Runtime.InteropServices.Marshal.SizeOf(shfi), 
                  flags );
  
              System.Drawing.Icon.FromHandle(shfi.hIcon); // Load from the handle
  
              // Get the icon for storage in an imagelist //
              System.Drawing.Icon icon = (System.Drawing.Icon)System.Drawing.Icon.FromHandle(shfi.hIcon).Clone();
  </code></pre>
  
  <p>Is this the right approach? </p>
  
  <p>Is there a better way to accomplish this? </p>
  
  <p>Or, is there something I need to do to correctly set the alpha channel in the icon?</p>