示例#1
0
        private void InfoForm_Paint(object sender, PaintEventArgs e)
        {
            // Draw the background image, if we have one.
            if (Theming.AppInfoBackgroundImage != null)
            {
                e.Graphics.DrawImage(Theming.AppInfoBackgroundImage, 0, 0);
            }

            // Draw the application's icon.
            var rect = new RectangleF(ClientSize.Width - 70, 6, 64, 75);
            var icon = ExeIconMgmt.GetIconForExe(_processMode ? _proc.ExePath : _task.ExePath, true);

            if (icon != null)
            {
                if (icon.Height <= rect.Height && icon.Width <= rect.Width)
                {
                    e.Graphics.DrawIcon(icon, (int)rect.Width / 2 - icon.Width / 2 + (int)rect.X, (int)rect.Height / 2 - icon.Height / 2 + (int)rect.Y);
                }
                else
                {
                    var bmp = ExeIconMgmt.GetBitmapFromIcon(icon, true);
                    e.Graphics.DrawImage(bmp, Misc.CalculateCenteredScaledDestRect(rect, bmp.Size, false), new Rectangle(0, 0, bmp.Width, bmp.Height), GraphicsUnit.Pixel);
                    bmp.Dispose();
                }
            }
            else
            {
                e.Graphics.DrawImageAlphaChannel(MainForm.NoIconImage, Misc.CalculateCenteredScaledDestRect(rect, MainForm.NoIconImageSize, false));
            }

            // Initialize all the task or process strings that will be drawn.
            var mainString = _processMode ? Path.GetFileName(_proc.ExePath) : Path.GetFileName(_task.ExePath);
            var substring  = _processMode
                                ? string.Concat(NativeLang.GetNlsString("AppInfo", "Slot"), " ", _proc.SlotNumber)
                                : _task.Title;
            var location   = Path.GetDirectoryName(_processMode ? _proc.ExePath : _task.ExePath);
            var numModules = TaskMgmt.Instance.GetProcessModules(_processMode ? _proc.ProcessId : _task.ProcessId).ToString();
            var numThreads = TaskMgmt.Instance.GetProcessThreads(_processMode ? _proc.ProcessId : _task.ProcessId).ToString();

            // Output the filename and window title (or slot number in case of a raw process).

            rect.X     = 6;
            rect.Width = ClientSize.Width - 70;
            var mainStringSize = e.Graphics.MeasureString(mainString, MainFont);
            var subStringSize  = e.Graphics.MeasureString(substring, SubFont);
            var combinedHeight = mainStringSize.Height + subStringSize.Height + 1;
            var y        = rect.Height / 2 - combinedHeight / 2 + rect.Y;
            var mainRect = new RectangleF(rect.X + 2, y, rect.Width - 2, mainStringSize.Height);
            var subRect  = new RectangleF(rect.X + 2, y + mainStringSize.Height + 1, rect.Width - 2, subStringSize.Height);

            using (var brushPrimary = new SolidBrush(Theming.AppInfoTextColorPrimary))
                using (var brushSecondary = new SolidBrush(Theming.AppInfoTextColorSecondary))
                    using (var pen = new Pen(Theming.AppInfoDelimiterColor, 2))
                    {
                        e.Graphics.DrawString(mainString, MainFont, brushPrimary, mainRect, DefaultStringFormat);
                        e.Graphics.DrawString(substring, SubFont, brushSecondary, subRect, DefaultStringFormat);
                        e.Graphics.DrawLine(pen, 0, (int)rect.Y + (int)rect.Height + 7, ClientSize.Width, (int)rect.Y + (int)rect.Height + 7);
                    }

            // Output the rest of the strings.
            rect.Y     += 84;
            rect.Height = combinedHeight + 3;
            if (!location.EndsWith(@"\"))
            {
                location += @"\";
            }
            DrawStrings(e.Graphics, LocatedInString, location, rect);
            rect.Y += rect.Height + 2;
            DrawStrings(e.Graphics, NumModulesString, numModules, rect);
            rect.Y += rect.Height + 2;
            DrawStrings(e.Graphics, NumThreadsString, numThreads, rect);
        }
示例#2
0
        /// <summary>
        /// This event occurs when specific parts of the process ListView are to be drawn.
        /// </summary>
        /// <param name="hdc"></param>
        /// <param name="item"></param>
        /// <param name="subitem"></param>
        /// <param name="selected"></param>
        /// <param name="rect"></param>
        void ProcHandler_DrawEvent(IntPtr hdc, int item, int subitem, bool selected, RectangleF rect)
        {
            var proc = (ProcessItem)lsvProcesses.Items[item].Tag;

            using (var graphics = Graphics.FromHdc(hdc))
            {
                switch (subitem)
                {
                case -1:
                    // This is the prepaint event for the entire item.

                    if (selected)
                    {
                        if (Theming.ListSelectionRectangleImage != null)
                        {
                            // Draw the selection rectangle image, since we have one.
                            graphics.DrawImageAlphaChannel(Theming.ListSelectionRectangleImage, new Rectangle((int)rect.X, (int)rect.Y + 1, (int)rect.Width, (int)rect.Height - 1));
                        }
                        else if (Theming.ListSelectionRectangleColor.HasValue)
                        {
                            using (var bg = new SolidBrush(Theming.ListSelectionRectangleColor.Value))
                            {
                                // Draw the selection rectangle solid color, since we have that, but no image.
                                graphics.FillRectangle(bg, (int)rect.X, (int)rect.Y + 1, (int)rect.Width, (int)rect.Height - 1);
                            }
                        }
                    }
                    else     // not selected
                    {
                        if (Theming.ListItemBackgroundImage != null)
                        {
                            // Draw the deselected rectangle image, since we have one.
                            graphics.DrawImageAlphaChannel(Theming.ListItemBackgroundImage, new Rectangle((int)rect.X, (int)rect.Y + 1, (int)rect.Width, (int)rect.Height - 1));
                        }
                        else if (Theming.ListItemBackgroundColor.HasValue)
                        {
                            using (var bg = new SolidBrush(Theming.ListItemBackgroundColor.Value))
                            {
                                // Draw the deselected rectangle solid color, since we have that, but no image.
                                graphics.FillRectangle(bg, (int)rect.X, (int)rect.Y + 1, (int)rect.Width, (int)rect.Height - 1);
                            }
                        }
                    }
                    break;

                case 0:
                    // The first item is the application icon.

                    try
                    {
                        // If we're using Start menu icons, then try to get the one for the current task.
                        var customIcon = _usingStartIcons ? StartIconMgmt.GetCustomIconPathForExe(proc.ExePath) : null;
                        if (customIcon != null && File.Exists(customIcon))
                        {
                            // Retrieve it.
                            IImage img;
                            ImgFactory.CreateImageFromFile(customIcon, out img);
                            ImageInfo info;
                            img.GetImageInfo(out info);
                            var imgSize = new Size((int)info.Width, (int)info.Height);

                            // Draw it.
                            graphics.DrawImageAlphaChannel(img, Misc.CalculateCenteredScaledDestRect(rect, imgSize, false));
                        }
                        else
                        {
                            // Get the icon from the EXE itself.
                            var icon = ExeIconMgmt.GetIconForExe(proc.ExePath, true);
                            if (icon != null)
                            {
                                if (icon.Height <= rect.Height && icon.Width <= rect.Width)
                                {
                                    // If the icon is smaller or equal to the size of the space we have for it, just draw it directly, in the center.
                                    graphics.DrawIcon(icon, (int)rect.Width / 2 - icon.Width / 2 + (int)rect.X, (int)rect.Height / 2 - icon.Height / 2 + (int)rect.Y);
                                }
                                else
                                {
                                    // The icon is too big, so we have to resize it. Since there is no method provided to draw resized icons, we need a bitmap instead.

                                    // Get the bitmap representation of the icon.
                                    var bmp = ExeIconMgmt.GetBitmapFromIcon(icon, true);
                                    // Draw the bitmap, resizing it (and keeping the aspect ratio).
                                    graphics.DrawImage(bmp, Misc.CalculateCenteredScaledDestRect(rect, bmp.Size, false), new Rectangle(0, 0, bmp.Width, bmp.Height), GraphicsUnit.Pixel);
                                    bmp.Dispose();
                                }
                            }
                            else
                            {
                                // Draw the generic application icon.
                                graphics.DrawImageAlphaChannel(NoIconImage, Misc.CalculateCenteredScaledDestRect(rect, NoIconImageSize, false));
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(
                            "An error has occurred. ArkSwitch will try to continue. Please report this!" +
                            Environment.NewLine + "Error: " + ex.Message);
                    }
                    break;

                case 1:
                    // The second item is the EXE name and slot number.

                    // Generate the strings, determine their sizes, etc...
                    var infoString     = string.Concat(NativeLang.GetNlsString("Main", "Slot"), " ", proc.SlotNumber);
                    var nameStringSize = graphics.MeasureString(proc.ExeFilename, TaskListMainFont);
                    var infoStringSize = graphics.MeasureString(infoString, TaskListSubFont);
                    var combinedHeight = nameStringSize.Height + infoStringSize.Height + 1;
                    var y         = rect.Height / 2 - combinedHeight / 2 + rect.Y;
                    var titleRect = new RectangleF(rect.X + 2, y, rect.Width - 2, nameStringSize.Height);
                    var infoRect  = new RectangleF(rect.X + 2, y + nameStringSize.Height + 1, rect.Width - 2, infoStringSize.Height);

                    // Draw the strings.
                    using (var brushPrimary = new SolidBrush(selected ? Theming.ListTextColorPrimarySelected : Theming.ListTextColorPrimary))
                        using (var brushSecondary = new SolidBrush(selected ? Theming.ListTextColorSecondarySelected : Theming.ListTextColorSecondary))
                        {
                            graphics.DrawString(proc.ExeFilename, TaskListMainFont, brushPrimary, titleRect, TaskListStringFormat);
                            graphics.DrawString(infoString, TaskListSubFont, brushSecondary, infoRect, TaskListStringFormat);
                        }
                    break;
                }
            }
        }