private ImageList_GetImageCount ( |
||
himl | ||
Résultat | int |
public static ImageList GetImageList(object imageListAsPointer) { ImageList images = null; IntPtr intPtr = new IntPtr((int)imageListAsPointer); HandleRef hImageList = new HandleRef(null, intPtr); int count = UnsafeNativeMethods.ImageList_GetImageCount(hImageList); if (count > 0) { // Create a bitmap big enough to hold all the images Bitmap b = new Bitmap(16 * count, 16); Graphics g = Graphics.FromImage(b); // Loop through and extract each image from the imagelist into our own bitmap IntPtr hDC = IntPtr.Zero; try { hDC = g.GetHdc(); HandleRef handleRefDC = new HandleRef(null, hDC); for (int i = 0; i < count; i++) { UnsafeNativeMethods.ImageList_Draw(hImageList, i, handleRefDC, i * 16, 0, NativeMethods.ILD_NORMAL); } } finally { if (g != null && hDC != IntPtr.Zero) { g.ReleaseHdc(hDC); } } // Create a new imagelist based on our stolen images images = new ImageList(); images.ColorDepth = ColorDepth.Depth24Bit; images.ImageSize = new Size(16, 16); images.Images.AddStrip(b); } return(images); }