/// <summary> /// Loads Icon from Resource /// </summary> /// <param name="name"></param> /// <returns></returns> private static Icon LoadIconFromResource(String name) { string resourceName = name.Substring(1); Icon icon = null; int indexOfDot = resourceName.IndexOf('.'); if (indexOfDot != -1) { string resourceFile = resourceName.Substring(0, indexOfDot); resourceName = resourceName.Substring(indexOfDot + 1); //TODO: load the library and the image from managed assembly as well. IntPtr hLib = user32.LoadLibrary(resourceFile); IntPtr imgPtr = NativeWindowCommon.LoadImage(hLib, resourceName, NativeWindowCommon.IMAGE_ICON, 0, 0, 0); if (imgPtr != IntPtr.Zero) { try { icon = (Icon)(Icon.FromHandle(imgPtr).Clone()); } finally { NativeWindowCommon.DestroyIcon(imgPtr); } } } else { if (ImageLoader != null) { icon = (Icon)ImageLoader.GetResourceObject(resourceName); } } return(icon); }