private void LoadFromPhysicalDirectory(string Path) { try { // Loading item file and creating new item object // get extra information on this file that the System.IO.FileInfo doesn't give us Win32.Shell32.SHFileInfo FileInfo = new Win32.Shell32.SHFileInfo(); Win32.Shell32.Shell32API.SHGetFileInfo(Path, 0, ref FileInfo, (uint)System.Runtime.InteropServices.Marshal.SizeOf(FileInfo), Win32.Shell32.ShellGetFileInfoFlags.DisplayName | Win32.Shell32.ShellGetFileInfoFlags.FileTypeName | Win32.Shell32.ShellGetFileInfoFlags.LargeIcon | Win32.Shell32.ShellGetFileInfoFlags.Icon); // set the item name to the file name this.Name = FileInfo.szDisplayName; // set the item description to the file type this.Description = FileInfo.szTypeName; // keep the path value this._Path = Path; // NON EXISTANT IN NEW CLASS //this.ItemPath=Path; // setting properties // NON EXISTANT IN NEW CLASS //this.Line=Line; // NON EXISTATN IN NEW CLASS //this.ColorKey=Color.FromArgb(0, Color.White); // Adding new Texture to registry // checking if it has a custom Icon string ExtensionImage = ""; string ToggledExtensionImage = ""; ExtensionImage = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(Application.ExecutablePath), @"extensions\folder.png"); ToggledExtensionImage = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(Application.ExecutablePath), @"extensions\folder_open.png"); if (System.IO.File.Exists(ExtensionImage)) { //ImagePath=ExtensionImage; if (OrbitTextureCache.IsInCache(ExtensionImage)) { this.SetIcon(OrbitTextureCache.GetReference(ExtensionImage)); } else { SetIcon(ExtensionImage); OrbitTextureCache.InsertInCache(this._Icon, ExtensionImage); } //SetIcon(ExtensionImage); if (System.IO.File.Exists(ToggledExtensionImage)) { //ToggledImagePath=ToggledExtensionImage; SetToggledIcon(ToggledExtensionImage); } } else { try { // getting the handle to the icon from the SHFileInfo structure using (Icon IconO = Icon.FromHandle(FileInfo.hIcon)) { // create the biggest possible icon using (Icon icon = new Icon(IconO, 256, 256)) { // convert to bitmap using (Bitmap IconPic = Orbit.Utilities.ImageHelper.GetBitmapFromIcon(icon)) { // setting it to be the icon this.SetIcon(IconPic); } } } } catch (Exception) { this.CannotLoadIcon(); } } // don't forget to destroy the handle to the other icon Win32.User32.User32API.DestroyIcon(FileInfo.hIcon); } catch (Exception) { throw; } }
/// <summary> /// Creates a new instance of a Task Item /// </summary> /// <param name="Device">Direct3D Device to load the resources into</param> /// <param name="WindowInformation">Information about the window that this object represents</param> public TaskItem(Device Device, Orbit.Utilities.WindowInformation WindowInformation) { // checking the values ValidateDevice(Device); // settng the basic properties display = Device; try { // initialize common resources InitializeResources(); // initialize needed HQ task preview resources InitializePreviewResources(); // set the context menu flags this._MenuFlags = ItemMenuFlags.IgnoreWindow; // get information from window _WindowName = WindowInformation.Name; //base.Name=WindowInformation.Name; //base.Description="Running Task"; this.Handle = WindowInformation.Handle; // load icon from window try { using (Icon ico = WindowsTaskManager.GetWindowIcon(WindowInformation.Handle)) { if (ico != null && ico.Width >= 32) // we don't want 16x16 icons here (we can get 32x32 icons on the other page for sure) { // got icon for the window using (Bitmap b = ImageHelper.GetBitmapFromIcon(ico)) { SetIcon(b); //SetOverlay(b); // overlay not needed anymore. will use standard icon } } else { try { // try to acquire icon from the process module string modulePath = WindowsTaskManager.GetExecutableName(WindowInformation.Handle); // or use the "C:\Windows\System32\more.com" file for dummy icon if (!System.IO.File.Exists(modulePath)) { modulePath = System.IO.Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.System), "more.com"); } Win32.Shell32.SHFileInfo FileInfo = new Win32.Shell32.SHFileInfo(); Win32.Shell32.Shell32API.SHGetFileInfo(modulePath, 0, ref FileInfo, (uint)System.Runtime.InteropServices.Marshal.SizeOf(FileInfo), Win32.Shell32.ShellGetFileInfoFlags.LargeIcon | Win32.Shell32.ShellGetFileInfoFlags.Icon); try { // getting the handle to the icon from the SHFileInfo structure using (Icon IconO = Icon.FromHandle(FileInfo.hIcon)) { // create the biggest possible icon using (Icon icon = new Icon(IconO, 128, 128)) { //System.Diagnostics.Debug.WriteLine("Icon size"+icon.Width); // convert to bitmap using (Bitmap IconPic = Orbit.Utilities.ImageHelper.GetBitmapFromIcon(icon)) { // setting it to be the icon this.SetIcon(IconPic); //this.SetOverlay(IconPic); // overlay not needed anymore. will use standard icon } } } } catch (Exception) {} // don't forget to destroy the handle to the other icon Win32.User32.User32API.DestroyIcon(FileInfo.hIcon); } catch (Exception) { CannotLoadIcon(); } } } } catch (Exception) { System.Diagnostics.Debug.WriteLine("failed to load icon"); } } catch (Exception) { throw; } }
private void LoadFromPhysicalFile(string Path) { try { // Loading item file and creating new item object // get extra information on this file that the System.IO.FileInfo doesn't give us Win32.Shell32.SHFileInfo FileInfo = new Win32.Shell32.SHFileInfo(); Win32.Shell32.Shell32API.SHGetFileInfo(Path, 0, ref FileInfo, (uint)System.Runtime.InteropServices.Marshal.SizeOf(FileInfo), Win32.Shell32.ShellGetFileInfoFlags.DisplayName | Win32.Shell32.ShellGetFileInfoFlags.FileTypeName | Win32.Shell32.ShellGetFileInfoFlags.LargeIcon | Win32.Shell32.ShellGetFileInfoFlags.Icon); // set the item name to the file name this.Name = FileInfo.szDisplayName; // set the item description to the file type this.Description = FileInfo.szTypeName; // keep the path value this._Path = Path; // NON EXISTANT IN NEW CLASS //this.ItemPath=Path.Substring(0, Path.Length-(Path.Length-Path.LastIndexOf("\\")))+"\\"; // setting properties // NON EXISTANT IN NEW CLASS //this.Line=Line; // NON EXISTANT IN NEW CLASS //this.ColorKey=Color.FromArgb(0, Color.White); // Adding new Texture to registry // checking if it has a custom Icon string ExtensionImage = ""; //string ToggledExtensionImage=""; // get the file extension string Extension = System.IO.Path.GetExtension(Path); // get the filename of the supposed image for this extension string ExtensionFileName = Extension.Replace(".", "").ToLower() + ".png"; // get the path for that file ExtensionImage = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(Application.ExecutablePath), @"extensions\" + ExtensionFileName); // if the file exists, assign it to be the image // else, load its default filetype icon if (System.IO.File.Exists(ExtensionImage)) { if (OrbitTextureCache.IsInCache(ExtensionImage)) { this.SetIcon(OrbitTextureCache.GetReference(ExtensionImage)); } else { SetIcon(ExtensionImage); OrbitTextureCache.InsertInCache(this._Icon, ExtensionImage); } //SetIcon(ExtensionImage); } else { string textureId = System.IO.Path.GetExtension(Path); if (textureId.ToLower() != ".lnk" && OrbitTextureCache.IsInCache(textureId)) { this.SetIcon(OrbitTextureCache.GetReference(textureId)); } else { try { // getting the handle to the icon from the SHFileInfo structure using (Icon IconO = Icon.FromHandle(FileInfo.hIcon)) { // create the biggest possible icon using (Icon icon = new Icon(IconO, 128, 128)) { // convert to bitmap using (Bitmap IconPic = Orbit.Utilities.ImageHelper.GetBitmapFromIcon(icon)) { // setting it to be the icon this.SetIcon(IconPic); //this.SetOverlay(IconPic); // overlay not needed anymore. will use standard icon } } } } catch (Exception) { this.CannotLoadIcon(); } if (textureId.ToLower() != ".lnk") { OrbitTextureCache.InsertInCache(this._Icon, textureId); } } } // don't forget to destroy the handle to the other icon Win32.User32.User32API.DestroyIcon(FileInfo.hIcon); } catch (Exception) { throw; } }