Ejemplo n.º 1
0
        /// <summary>
        /// Normal constructor...
        /// </summary>
        public MainForm()
        {
            InitializeComponent();

            // Initialize some default stuff.
            lsvTasks.Font     = new Font(FontFamily.GenericSansSerif, TaskListMainFont.Size + TaskListSubFont.Size + 3, FontStyle.Regular);
            lsvProcesses.Font = lsvTasks.Font;
            _usingStartIcons  = AppSettings.GetStartMenuIcons();
            if (_usingStartIcons)
            {
                StartIconMgmt.CacheStartMenuIcons();
            }
            pbxTopBar.Image = Theming.StatusBarImage;
            Visible         = false;

            // Initialize NLS strings.
            mnuKill.Text                = NativeLang.GetNlsString("Main", mnuKill.Text);
            mnuMenu.Text                = NativeLang.GetNlsString("Main", mnuMenu.Text);
            mnuMenuSwitchTo.Text        = NativeLang.GetNlsString("Main", mnuMenuSwitchTo.Text);
            mnuMenuKill.Text            = NativeLang.GetNlsString("Main", mnuMenuKill.Text);
            mnuMenuTaskDetails.Text     = NativeLang.GetNlsString("Main", mnuMenuTaskDetails.Text);
            mnuMenuOptions.Text         = NativeLang.GetNlsString("Main", mnuMenuOptions.Text);
            mnuMenuActivationField.Text = NativeLang.GetNlsString("Main", mnuMenuActivationField.Text);
            mnuMenuQuit.Text            = NativeLang.GetNlsString("Main", mnuMenuQuit.Text);
        }
Ejemplo n.º 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;
                }
            }
        }