Beispiel #1
0
        /// <summary>
        ///     Release all resources used by <see cref="StockIcon" /> class,
        ///     and optionally releases managed resources.
        /// </summary>
        /// <param name="disposing">
        ///     <c>true</c> to release both managed and unmanaged resources.
        ///     <c>false</c> to release only unmanaged resources.
        /// </param>
        protected virtual void Dispose(bool disposing)
        {
            if (!this.disposed)
            {
                if (disposing)
                {
                }

                // Release unmanaged resources.
                StockIconsNativeMethods.DestroyIcon(this.hIcon);
                this.hIcon = IntPtr.Zero;

                this.disposed = true;
            }
        }
Beispiel #2
0
        private IntPtr GetHIcon()
        {
            var flags = SHGSI.SHGSI_ICONLOCATION;

            if (this.Size == StockIconSize.Small)
            {
                flags |= SHGSI.SHGSI_SMALLICON;
            }
            else if (this.Size == StockIconSize.ShellSize)
            {
                flags |= SHGSI.SHGSI_SHELLICONSIZE;
            }
            else
            {
                flags |= SHGSI.SHGSI_LARGEICON;
            }

            if (this.Selected)
            {
                flags |= SHGSI.SHGSI_SELECTED;
            }

            if (this.LinkOverlay)
            {
                flags |= SHGSI.SHGSI_LINKOVERLAY;
            }

            var info = SHSTOCKICONINFO.Create();

            var hr = StockIconsNativeMethods.SHGetStockIconInfo(this.Id, flags, ref info);

            if (hr != COMErrorCodes.S_OK)
            {
                if (hr == COMErrorCodes.E_INVALIDARG)
                {
                    throw new InvalidOperationException(
                              string.Format(CultureInfo.InvariantCulture,
                                            ErrorMessages.StockIconInvalidGuid,
                                            this.Id));
                }

                return(IntPtr.Zero);
            }

            return(info.hIcon);
        }