/// <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(); }
void LoadShortcuts() { using (var db = new LiteDatabase(@".\sc.db")) { var collection = db.GetCollection <Shortcut>(); var list = collection.FindAll()?.ToList(); if (list != null) { foreach (var shortcut in list) { MemoryStream iconStream = new MemoryStream(); var fs = db.GetStorage <string>(); // method 1 //var file = fs.FindById(shortcut.Icon); //file.CopyTo(iconStream); // method 2 //fs.Download(shortcut.Icon, @"D:\luzhi.jpg", true); // method 3 //var file = fs.FindById(shortcut.Icon); //if (file != null) //{ // using (var fStream = file.OpenRead()) // { // fStream.CopyTo(iconStream); // iconStream.Seek(0, SeekOrigin.Begin); // } //} // 加载图标 if (!string.IsNullOrEmpty(shortcut.Icon)) { fs.Download(shortcut.Icon, iconStream); iconStream.Seek(0, SeekOrigin.Begin); // 就差这一句 shortcut.IconStream = (ImageSource) new ImageSourceConverter().ConvertFrom(iconStream); } else { if (File.Exists(shortcut.Command)) { var icon = ShellIcon.GetLargeIcon(shortcut.Command); shortcut.IconStream = icon.ToImageSource(); } else { //todo: 默认图标 } } } } this.Datas = list; } }
public Icon GetStaticIcon(StaticIconType type, IconSize size) { ShellIcon.IconSize iconSize; switch (size) { case IconSize.Large: iconSize = ShellIcon.IconSize.Large; break; case IconSize.Small: iconSize = ShellIcon.IconSize.Small; break; default: throw new NotSupportedException(); } ShellIcon.FolderType folderType; switch (type) { case StaticIconType.OpenDirectory: folderType = ShellIcon.FolderType.Open; break; case StaticIconType.CloseDirectory: folderType = ShellIcon.FolderType.Closed; break; default: throw new NotSupportedException(); } SD.Icon icon = ShellIcon.GetFolderIcon(iconSize, folderType); return(new Icon(new IconHandler(icon))); }
/// <summary> /// Bind Composition Object to treeview /// </summary> private void Render(bool Clear = true) { if (Clear) { tvStartMenu.Nodes.Clear(); Image imStart = imlIcons.Images[0]; imlIcons.Images.Clear(); //Add Shell Icons imlIcons.Images.Add("START", imStart); imlIcons.Images.Add("APPLICATION_DEFAULT", ShellIcon.GetSystemIcon(ShellIcon.SHSTOCKICONID.SIID_APPLICATION, ShellIcon.SHGSI.SHGSI_ICON | ShellIcon.SHGSI.SHGSI_SMALLICON)); imlIcons.Images.Add("FOLDER_CLOSED", ShellIcon.GetSystemIcon(ShellIcon.SHSTOCKICONID.SIID_FOLDER, ShellIcon.SHGSI.SHGSI_ICON | ShellIcon.SHGSI.SHGSI_SMALLICON)); imlIcons.Images.Add("FOLDER_OPEN", ShellIcon.GetSystemIcon(ShellIcon.SHSTOCKICONID.SIID_FOLDEROPEN, ShellIcon.SHGSI.SHGSI_ICON | ShellIcon.SHGSI.SHGSI_SMALLICON)); } TreeNode lNode; //Create Main Node lNode = tvStartMenu.Nodes.Add("\\", "Start"); lNode.ImageKey = "START"; lNode.SelectedImageKey = "START"; if (_Shortcuts != null) { foreach (DesktopComposer.Implementation.Shortcut s in _Shortcuts) { //1. Find Relative Path lNode = AddNode(s); } } else { } }
private void AddVideos(TreeNode parent) { string path = Environment.GetFolderPath(Environment.SpecialFolder.MyVideos); AddImageToList(this.ImageList, path, ShellIcon.GetIcon(path)); AddNodeToParent(parent, "Videos", path, path); }
private void AddMusics(TreeNode parent) { string path = SpecialDirectories.MyMusic; AddImageToList(this.ImageList, path, ShellIcon.GetIcon(path)); AddNodeToParent(parent, "Musics", path, path); }
/// <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; }
private void AddDesktop(TreeNode parent) { string path = SpecialDirectories.Desktop; AddImageToList(this.ImageList, path, ShellIcon.GetIcon(path)); AddNodeToParent(parent, "Desktop", path, path); }
private void AddDownloads(TreeNode parent) { string userPath = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile); string downloadPath = Path.Combine(userPath, "Downloads"); AddImageToList(this.ImageList, downloadPath, ShellIcon.GetIcon(downloadPath)); AddNodeToParent(parent, "Downloads", downloadPath, downloadPath); }
public ToolItem(ToolListConfiguration model) { this.Icon = ShellIcon.GetIconFor(string.IsNullOrEmpty(model.Icon) ? model.Path : model.Icon); this.Model = model; this.Header = model.Name; this.Description = model.Path == null ? null : model.Path; this.IsUac = model.AsAdmin; }
public frmMyDlg() { InitializeComponent(); imageList1.Images.Add(ShellIcon.GetLargeFolderIcon()); imageList1.Images.Add(ShellIcon.GetSmallIconFromExtension(".txt")); fileTree.ImageList = imageList1; SetTree(); }
public static void Default_0_FlushCacheInWindows() { if (!Runtime.Platform.IsWindows) { return; } Assert.True(ShellIcon.FlushCache()); }
/* * //private const int MAX_PATH = 260; * //[StructLayout(LayoutKind.Sequential)] * //private struct SHFILEINFO { * // public IntPtr hIcon; * // public int iIcon; * // public int dwAttributes; * // [MarshalAs(UnmanagedType.ByValTStr, SizeConst = MAX_PATH)] * // public string szDisplayName; * // [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 80)] * // public string szTypeName; * //} */ public void Dispose() { if (ShellIcon != null) { ShellIcon.Dispose(); ShellIcon = null; } }
/// <summary> /// Create bitmap source from icon. /// </summary> /// <param name="icon"><see cref="ShellIcon" />.</param> /// <returns></returns> public static BitmapSource CreateBitmapSource(ShellIcon icon) { Contract.Requires <ArgumentNullException>(icon != null); return(System.Windows.Interop.Imaging.CreateBitmapSourceFromHIcon( icon.Handle, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions())); }
public StartMenuEditorControl() { InitializeComponent(); //Add Shell Icons imlIcons.Images.Add("APPLICATION_DEFAULT", ShellIcon.GetSystemIcon(ShellIcon.SHSTOCKICONID.SIID_APPLICATION, ShellIcon.SHGSI.SHGSI_ICON | ShellIcon.SHGSI.SHGSI_SMALLICON)); imlIcons.Images.Add("FOLDER_CLOSED", ShellIcon.GetSystemIcon(ShellIcon.SHSTOCKICONID.SIID_FOLDER, ShellIcon.SHGSI.SHGSI_ICON | ShellIcon.SHGSI.SHGSI_SMALLICON)); imlIcons.Images.Add("FOLDER_OPEN", ShellIcon.GetSystemIcon(ShellIcon.SHSTOCKICONID.SIID_FOLDEROPEN, ShellIcon.SHGSI.SHGSI_ICON | ShellIcon.SHGSI.SHGSI_SMALLICON)); }
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); }
public override ShellIcon GetIcon(bool open) { string ext = IconHelper.GetExtension(name); //Icon ic = IconHelper.GetFileIcon(ext, User32.IconSize.Small, false); //IntPtr hIcon = IconHelper.GetXLIcon(IconHelper.GetIconIndex(ext)); //Icon ic = (Icon)Icon.FromHandle(hIcon).Clone(); //User32.DestroyIcon(hIcon); // don't forget to cleanup return(ShellIcon.CreateFromIcon(null, false, false, ext)); }
private static ListViewItem InitListviewItem(FileSystemInfo info) { var list = SmallImageList; var item = new ShellInfoItem(info); string[] row = item.ToArray(); int key = list.Images.IndexOfKey("unknown"); if (info.Attributes.HasFlag(FileAttributes.Directory)) { var dir = (DirectoryInfo)info; try { dir.GetAccessControl(); if (dir.Attributes.HasFlag(FileAttributes.Hidden)) { key = list.Images.IndexOfKey("hidden_folder"); } else { key = list.Images.IndexOfKey("FolderIcon"); } } catch (UnauthorizedAccessException) { //key = list.Images.IndexOfKey("locked_folder"); key = list.Images.IndexOfKey("LockFolder"); } } else { var icon = ShellIcon.GetIcon(info.FullName); string ext = item.Ext; if (icon != null) { AddKeyToImageList(info.FullName, icon); key = list.Images.IndexOfKey(info.FullName); } else if (!String.IsNullOrEmpty(ext)) { icon = ShellIcon.GetSmallIconFromExtension(ext); AddKeyToImageList(ext, icon); key = list.Images.IndexOfKey(ext); } } var lvi = new ListViewItem(row, key) { Tag = info.FullName }; return(lvi); }
private ImageSource GetFolderImage() { var img = ShellIcon.GetLargeFolderIcon(); Bitmap bitmap = img.ToBitmap(); IntPtr hBitmap = bitmap.GetHbitmap(); ImageSource image = Imaging.CreateBitmapSourceFromHBitmap( hBitmap, IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions()); return(image); }
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)]); }
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); }
private Icon GetIconFromDeviceIconPath(string iconPath) { if (string.IsNullOrEmpty(iconPath)) { return(null); } if (string.IsNullOrEmpty(iconPath) || !ShellIcon.TryExtractIconByIdOrIndex(iconPath, IconSize, out Icon icon)) { return(new Icon(Resources.FallbackDevice, IconSize)); } return(icon); }
private void DrawDrivesImage(object sender, DrawItemEventArgs e) { if (e.Index == -1) { return; } e.DrawBackground(); string path = this.Items[e.Index].ToString(); Icon icon = ShellIcon.GetIcon(path); e.Graphics.DrawIcon(icon, 3, e.Bounds.Top); e.Graphics.DrawString(path, this.Font, Brushes.Black, icon.Width + 2, e.Bounds.Top); e.DrawFocusRectangle(); }
protected override BitmapSource Convert(Shell shell, string databaseRootPath) { try { if (shell == null) { return(null); } return(ShellIcon.Load(databaseRootPath, shell.Type, 96)); } catch (Exception) { return(null); } }
public override ShellIcon GetIcon(bool open) { if (val == null) { using (RegistryKey key = OpenKey()) { val = key.GetValue(valueName); } } return(ShellIcon.CreateFromFile( @"C:\Windows\Regedit.exe", val is string? - 205 : -206, true, false)); }
internal void Init() { this.BeforeExpand += NativeTreeView_BeforeExpand; SetWindowTheme(this.Handle, "explorer", null); if (!this.ImageList.Images.ContainsKey("FolderIcon")) { this.ImageList.Images.Add("FolderIcon", ShellIcon.GetLargeFolderIcon()); this.ImageList.Images.Add("LockFolder", ShellIcon.GetIconFromIndex("shell32.dll", 47)); /// Detect icon base on Windows version var vs = Environment.OSVersion; switch (vs.Version.Major) { /// Windows vista, 7, 8, 8.1 case 6: this.ImageList.Images.Add("ComputerIcon", ShellIcon.GetIconFromIndex("shell32.dll", 15)); this.ImageList.Images.Add("LibrariesIcon", ShellIcon.GetIconFromIndex("imageres.dll", 202)); this.ImageList.Images.Add("FavoritesIcon", ShellIcon.GetIconFromIndex("imageres.dll", 203)); break; /// Windows 10 case 10: this.ImageList.Images.Add("ComputerIcon", ShellIcon.GetIconFromIndex("shell32.dll", 15)); this.ImageList.Images.Add("LibrariesIcon", ShellIcon.GetIconFromIndex("imageres.dll", 203)); this.ImageList.Images.Add("FavoritesIcon", ShellIcon.GetIconFromIndex("imageres.dll", 200)); break; default: throw new NotSupportedException("This windows version is not supported"); } } this.HideSelection = false; // FullRowSelect is ignored if ShowLines is set to true. this.ShowLines = false; this.FullRowSelect = true; AddFavorites(); AddLibraries(); AddComputer(); // change items height int nodeHeight = this.Nodes[0].Bounds.Height; this.ItemHeight = nodeHeight + 4; }
private void ApplyShellIcon() { ShellImageList.Images.Add(ShellIcon.GetIcon(15)); //PC Icon ShellImageList.Images.Add(ShellIcon.GetIcon(8)); //HDD Icon ShellImageList.Images.Add(ShellIcon.GetIcon(3)); //Folder Icon //now apply icon treePath.Nodes[0].SelectedImageIndex = 0; treePath.Nodes[0].ImageIndex = 0; for (int i = 0; i <= treePath.Nodes[0].Nodes.Count - 1; i++) { var n = treePath.Nodes[0].Nodes[i]; n.ImageIndex = 1; n.SelectedImageIndex = 1; } }
private void btnChangeIcon_Click(object sender, EventArgs e) { DialogResult result = iconPickerDialog.ShowDialog(this); if (result == DialogResult.OK) { _tempIconLocation = iconPickerDialog.FileName + "," + iconPickerDialog.IconIndex.ToString(); _tempIcon = ShellIcon.IconExtract(iconPickerDialog.FileName, iconPickerDialog.IconIndex, 1); _shortcut.FindIcon(); if (_shortcut.IconCacheLarge != null) { pBIcon.Image = _tempIcon.ToBitmap(); } } iconPickerDialog.Dispose(); }
/// <summary> /// Загружает изображение из файла, указанного в объекте типа <see cref="Options"/> /// </summary> /// <param name="file">Объект для обработки</param> private static BitmapSource LoadIconFromFile(Options file) { if (GlobalVariables.AppSettings.ImageExtensions.Contains(file.Ext)) { try { BitmapImage image = LoadThumbnailFromFile(file.FullPath); file.HasPreview = true; return(image); } catch (NotSupportedException) { return(ShellIcon.IconToBitmapSource(GetIconFromFile(file.FullPath)).FreezeIfCan()); } } return(ShellIcon.IconToBitmapSource(GetIconFromFile(file.FullPath)).FreezeIfCan()); }
private Image GetImage() { if (String.IsNullOrEmpty(_device.DeviceClassIconPath)) { return(null); } Icon icon; if (!ShellIcon.TryExtractIconByIdOrIndex(_device.DeviceClassIconPath, new Size(48, 48), out icon)) { return(null); } using (icon) { return(icon.ToBitmap()); } }