Ejemplo n.º 1
0
        /// <summary>
        /// Načte ikonu souboru podle jeho typu
        /// </summary>
        public void LoadIcon()
        {
            if (Name == null)
            {
                return;
            }

            Icon icon;

            if (FileName != "" && File.Exists(FullPath))
            {
                icon = ShellIcon.GetSmallIcon(FullPath);
            }
            else
            {
                string ext = Path.GetExtension(Name);
                if (ext == "")
                {
                    ext = Name;
                }
                icon = ShellIcon.GetSmallIconFromExtension(ext);
            }
            var bmpSrc = Imaging.CreateBitmapSourceFromHIcon(icon.Handle, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());

            icon.Dispose();
            Icon = bmpSrc;
        }
Ejemplo n.º 2
0
        /// <summary>Queries all processes and displays them.</summary>
        private void RefreshProcessList()
        {
            var dt = new DataTable();

            dt.Columns.Add("icon", typeof(Icon));
            dt.Columns.Add("name", typeof(string));
            dt.Columns.Add("id", typeof(int));
            dt.Columns.Add("path", typeof(string));

            nativeHelper.EnumerateProcesses((pid, path) =>
            {
                var moduleName = Path.GetFileName(path);
                if (!filterCheckBox.Checked || !CommonProcesses.Contains(moduleName.ToLower()))
                {
                    var row     = dt.NewRow();
                    row["icon"] = ShellIcon.GetSmallIcon(path);
                    row["name"] = moduleName;
                    row["id"]   = pid;
                    row["path"] = path;
                    dt.Rows.Add(row);
                }
            });

            dt.DefaultView.Sort = "name ASC";

            processDataGridView.DataSource = dt;

            ApplyFilter();
        }
Ejemplo n.º 3
0
        public static BitmapSource GetShortcutIconBitmapSource(string shortcutFilePath)
        {
            // https://www.brad-smith.info/blog/archives/164

            BitmapSource bitmapSource = null;

            /*
             * // Just in case we might need to implement this
             * string ext = Path.GetExtension(shortcutFilePath);
             * if(ext.Equals(Constants.EXT_URL, StringComparison.InvariantCultureIgnoreCase))
             * {
             *  // Uri uriLink = new Uri(@"pack://*****:*****@"pack://application:,,,/Images/globe.png");
             *  bitmapSource = new BitmapImage(uriLink);
             *  return bitmapSource;
             * }
             */

            /*
             * // This method works only on files, not on folders.
             * // This returns an icon with size of 32x32 pixels
             * using (Icon icon = Icon.ExtractAssociatedIcon(shortcutFilePath)) // TODO check if there is a function for 16x16
             * {
             *  bitmapSource = icon?.ToBitmapSource();
             * }
             */

            /*
             * // This is a native method and might requaire user previliges
             * // This returns an icon with size of 32x32 pixels
             * using (Icon icon = ShellIcon.GetLargeIcon(shortcutFilePath))
             * {
             *  bitmapSource = icon?.ToBitmapSource();
             * }
             */


            // *** Use this for best results ***
            // This is a native method and might requaire user previliges
            // This returns an icon with size of 16x16 pixels
            using (Icon icon = ShellIcon.GetSmallIcon(shortcutFilePath))
            {
                bitmapSource = icon?.ToBitmapSource();
            }


            /*
             * // Investigate SmallBitmapSource gives size of 32x32 pixels
             * // This is a native method and might requaire user previliges
             * // bitmapSource = Microsoft.WindowsAPICodePack.Shell.ShellObject.FromParsingName(shortcutFilePath).Thumbnail.SmallBitmapSource;
             */



            return(bitmapSource);
        }
Ejemplo n.º 4
0
    public int GetIconImageIndex(string path)
    {
        string extension = Path.GetExtension(path);

        if (_systemIcons.ContainsKey(extension) == false)
        {
            Icon icon = ShellIcon.GetSmallIcon(path);
            _imageList.Images.Add(icon);
            _systemIcons.Add(extension, _imageList.Images.Count - 1);
        }

        return((int)_systemIcons[Path.GetExtension(path)]);
    }
Ejemplo n.º 5
0
        private void LoadFileIcons(IEnumerable <IFileSystemEntry> entries)
        {
            IDictionary <string, Image> images = new Dictionary <string, Image>();

            foreach (IFileSystemEntry entry in entries.Where(entry => !entry.IsFolder))
            {
                string key = Path.GetExtension(entry.Name);
                if (key != null && !imageList.Images.ContainsKey(key) && !images.ContainsKey(key))
                {
                    images.Add(key, MakeIconImage(ShellIcon.GetSmallIcon(entry.Name)));
                }
            }
            AddToImageList(images);
        }
Ejemplo n.º 6
0
        /// <summary>
        ///   Gets the icon associated with the shell extension
        /// </summary>
        /// <param name = "filename"></param>
        /// <returns></returns>
        public static Image GetExtensionIcon(string filename)
        {
            var bmp    = ShellIcon.GetSmallIcon(filename).ToBitmap();
            var stream = new MemoryStream();

            bmp.Save(stream, ImageFormat.Png);
            var bmpImage = new BitmapImage();

            bmpImage.BeginInit();
            stream.Seek(0, SeekOrigin.Begin);
            bmpImage.StreamSource = stream;
            bmpImage.EndInit();

            var j = new Image
            {
                Source = bmpImage
            };

            return(j);
        }