Beispiel #1
0
        /// <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;
            }
        }
Beispiel #2
0
 /// <summary>
 /// Creates a new instance of the WindowListedEventArgs class
 /// </summary>
 /// <param name="name">Name of the window</param>
 /// <param name="handle">Handle to the window</param>
 public WindowListedEventArgs(string name, IntPtr handle)
 {
     _Wi = new WindowInformation(name, handle);
 }