Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>With the <a href="http://msdn.microsoft.com/en-us/library/9xc4z2c7.aspx" rel="nofollow"><code>CImageList</code> class</a> instance (which you get by calling to the <a href="http://msdn.microsoft.com/en-us/library/b75edw6k.aspx" rel="nofollow"><code>Detach</code> method</a> on the <a href="http://msdn.microsoft.com/en-US/library/hc0d17x3.aspx" rel="nofollow"><code>GetImageList</code> method</a> on the <a href="http://msdn.microsoft.com/en-us/library/hfshke78.aspx" rel="nofollow"><code>CListCtrl</code></a> instance that you have), you can get the <code>HIMAGELIST</code> handle by calling the <a href="http://msdn.microsoft.com/en-us/library/b75edw6k.aspx" rel="nofollow">Detach method</a>.</p> <p>From there you can call the underlying Windows API through the <a href="http://msdn.microsoft.com/en-us/library/aa446536.aspx" rel="nofollow">Platform Invocation Services (P/Invoke) layer</a>.</p> <p>The following assumes you have this <code>HIMAGELIST</code> pointer in an <a href="http://msdn.microsoft.com/en-us/library/system.intptr.aspx" rel="nofollow"><code>IntPtr</code></a>:</p> <pre><code>IntPtr imageList = ...; </code></pre> <p>First, you'll need to declare the <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/bb761552.aspx" rel="nofollow"><code>ImageList_GetImageCount</code> function</a> in .NET:</p> <pre><code>[DllImport("Comctl32.dll", SetLastError = true)] static extern int ImageList_GetImageCount(IntPtr himl); </code></pre> <p>And of course, store the result of that call in a variable:</p> <pre><code>int imageCount = ImageList_GetImageCount(imageList); </code></pre> <p>You'll also need to be able to get the details about each image, so you'll need the call to <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/bb761554.aspx" rel="nofollow"><code>ImageList_GetImageInfo</code></a>:</p> <pre><code>[StructLayout(LayoutKind.Sequential)] struct RECT { public int left, top, right, bottom; } [StructLayout(LayoutKind.Sequential)] struct IMAGEINFO { public IntPtr hbmImage; public IntPtr hbmMask; public int Unused1; public int Unused2; public RECT rcImage; } [DllImport("Comctl32.dll", SetLastError = true)] static extern bool ImageList_GetImageInfo(IntPtr himl, int i, ref IMAGEINFO pImageInfo); </code></pre> <p>With these, you can start your loop to get the information about the image:</p> <pre><code>for (int i = 0; i &lt; imageCount; ++i) { // The image info. var imageInfo = new IMAGEINFO(); // Get the call to ImageList_GetImageInfo. if (!ImageList_GetImageInfo(imageList, i, ref imageInfo) throw new System.ComponentModel.Win32Exception(); </code></pre> <p>Notice that in the <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/bb761393.aspx" rel="nofollow"><code>IMAGEINFO</code> structure</a> has a field that contains the pointer to the bitmap (the <code>hbmImage</code> field).</p> <p>This is a handle to an <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/aa383751%28v=vs.85%29.aspx" rel="nofollow"><code>HBITMAP</code></a> handle, which has an equivalent in .NET in the <a href="http://msdn.microsoft.com/en-us/library/system.drawing.bitmap.aspx" rel="nofollow"><code>Bitmap</code> class</a>. You can translate between the two by calling the static <a href="http://msdn.microsoft.com/en-us/library/k061we7x.aspx" rel="nofollow"><code>FromHbitmap</code> method</a> on the <a href="http://msdn.microsoft.com/en-us/library/84767bxk.aspx" rel="nofollow"><code>Image</code> class</a> (yes, it's strange it's not on the <code>Bitmap</code> class):</p> <pre><code> using (Bitmap bitmap = Image.FromHbitmap(imageInfo.hbmImage)) { </code></pre> <p>Once you have the <code>Bitmap</code> instance, you can call the <a href="http://msdn.microsoft.com/en-us/library/system.drawing.bitmap.save.aspx" rel="nofollow"><code>Save</code> method</a> on each instance to dump them to disk:</p> <pre><code> bitmap.Save("&lt;need to generate a filename&gt;.&lt;and extension&gt;"); } } </code></pre> <p>Note that there is the <a href="http://msdn.microsoft.com/en-us/library/system.windows.forms.imagelist.aspx" rel="nofollow"><code>ImageList</code> class</a> in .NET, but there's no way to pass the <code>HIMAGELIST</code> handle to the managed implementation (which would have made this much easier).</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload