private IntPtr GetHIcon() { // Create our internal flag to pass to the native method StockIconsNativeMethods.StockIconOptions flags = StockIconsNativeMethods.StockIconOptions.Handle; // Based on the current settings, update the flags if (CurrentSize == StockIconSize.Small) { flags |= StockIconsNativeMethods.StockIconOptions.Small; } else if (CurrentSize == StockIconSize.ShellSize) { flags |= StockIconsNativeMethods.StockIconOptions.ShellSize; } else { flags |= StockIconsNativeMethods.StockIconOptions.Large; // default } if (Selected) { flags |= StockIconsNativeMethods.StockIconOptions.Selected; } if (LinkOverlay) { flags |= StockIconsNativeMethods.StockIconOptions.LinkOverlay; } // Create a StockIconInfo structure to pass to the native method. StockIconsNativeMethods.StockIconInfo info = new StockIconsNativeMethods.StockIconInfo(); info.StuctureSize = (UInt32)Marshal.SizeOf(typeof(StockIconsNativeMethods.StockIconInfo)); // Pass the struct to the native method HResult hr = StockIconsNativeMethods.SHGetStockIconInfo(identifier, flags, ref info); // If we get an error, return null as the icon requested might not be supported // on the current system if (hr != HResult.Ok) { if (hr == HResult.InvalidArguments) { throw new InvalidOperationException( string.Format(System.Globalization.CultureInfo.InvariantCulture, LocalizedMessages.StockIconInvalidGuid, identifier)); } return(IntPtr.Zero); } // If we succeed, return the HIcon return(info.Handle); }
private IntPtr GetHIcon() { // Create our internal flag to pass to the native method StockIconsNativeMethods.StockIconOptions flags = StockIconsNativeMethods.StockIconOptions.Handle; // Based on the current settings, update the flags if (CurrentSize == StockIconSizes.Small) { flags |= StockIconsNativeMethods.StockIconOptions.Small; } else if (CurrentSize == StockIconSizes.ShellSize) { flags |= StockIconsNativeMethods.StockIconOptions.ShellSize; } else { flags |= StockIconsNativeMethods.StockIconOptions.Large; // default } if (Selected) { flags |= StockIconsNativeMethods.StockIconOptions.Selected; } if (LinkOverlay) { flags |= StockIconsNativeMethods.StockIconOptions.LinkOverlay; } // Create a StockIconInfo structure to pass to the native method. StockIconsNativeMethods.StockIconInfo info = new StockIconsNativeMethods.StockIconInfo(); info.StuctureSize = (UInt32)Marshal.SizeOf(typeof(StockIconsNativeMethods.StockIconInfo)); // Pass the struct to the native method HRESULT hr = StockIconsNativeMethods.SHGetStockIconInfo(identifier, flags, ref info); // If we get an error, return null as the icon requested might not be supported // on the current system if (hr != HRESULT.S_OK) { if (hr == HRESULT.E_INVALIDARG) { throw new ArgumentException(string.Format("The Stock Icon identifier given is invalid ({0})", identifier)); } else { return(IntPtr.Zero); } } // If we succeed, return the HIcon return(info.Handle); }