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>
        /// Refreshes the slot/memory info bar.
        /// </summary>
        internal void RefreshSystemRamInfo()
        {
            _showingSlots = !_showingSlots;

            if (_showingSlots)
            {
                var freeProcs = 32 - TaskMgmt.Instance.GetNumProcesses();
                _statusString = string.Format(NativeLang.GetNlsString("Main", "FreeTotalBar"), freeProcs, "32");
            }
            else
            {
                // Showing RAM.
                TaskMgmt.Instance.GetMemoryStatus(out _totalRam, out _freeRam);
                _statusString = string.Format(NativeLang.GetNlsString("Main", "FreeTotalBar"), TaskMgmt.FormatMemoryString(_freeRam), TaskMgmt.FormatMemoryString(_totalRam));
            }

            try
            {
                // Signal the PictureBox to redraw itself.
                pbxTopBar.Invalidate();

                // Tell the timer to start counting if the form is still visible and active.
                if (this.Visible && _activated)
                {
                    tmrRamRefresh.Enabled = true;
                }
            }
            catch (ObjectDisposedException)
            {
                // Ignore...
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Normal constructor...
        /// </summary>
        public OptionsForm()
        {
            InitializeComponent();

            // Initialize NLS strings.
            this.Text          = NativeLang.GetNlsString("Options", this.Text);
            mnuExclusions.Text = NativeLang.GetNlsString("Options", mnuExclusions.Text);
            for (int i = 0; i < lsvOptions.Items.Count; i++)
            {
                var item = lsvOptions.Items[i];
                var tag  = item.Tag as string;
                if (tag == "icons")
                {
                    item.SubItems[1].Text = NativeLang.GetNlsString("Options", "StartMenuIcons");
                }
                else if (tag == "boot")
                {
                    item.SubItems[1].Text = NativeLang.GetNlsString("Options", "RunAtBoot");
                }
                else if (tag == "tools")
                {
                    item.SubItems[1].Text = NativeLang.GetNlsString("Options", "ToolsShortcut");
                }
                else if (tag == "std")
                {
                    item.SubItems[1].Text = NativeLang.GetNlsString("Options", "WM65Compat");
                }
            }
        }
Ejemplo n.º 4
0
        public InfoForm()
        {
            InitializeComponent();

            // Initialize NLS strings.
            this.Text       = NativeLang.GetNlsString("AppInfo", this.Text);
            mnuExclude.Text = NativeLang.GetNlsString("AppInfo", mnuExclude.Text);
            mnuKill.Text    = NativeLang.GetNlsString("AppInfo", mnuKill.Text);
        }
Ejemplo n.º 5
0
        public ExclusionsForm()
        {
            InitializeComponent();

            // Initialize NLS strings.
            this.Text      = NativeLang.GetNlsString("Exclusions", this.Text);
            mnuAdd.Text    = NativeLang.GetNlsString("Exclusions", mnuAdd.Text);
            mnuRemove.Text = NativeLang.GetNlsString("Exclusions", mnuRemove.Text);
        }
Ejemplo n.º 6
0
        public ActivationRelocationForm()
        {
            InitializeComponent();

            // Initialize NLS strings.
            this.Text       = NativeLang.GetNlsString("ActivationRelocation", this.Text);
            mnuSave.Text    = NativeLang.GetNlsString("ActivationRelocation", mnuSave.Text);
            mnuDiscard.Text = NativeLang.GetNlsString("ActivationRelocation", mnuDiscard.Text);
        }
Ejemplo n.º 7
0
 /// <summary>
 /// Draws the text on the status bar.
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void pbxTopBar_Paint(object sender, PaintEventArgs e)
 {
     using (Brush brushLeft = new SolidBrush(Theming.StatusBarTextColorPrimary))
         using (Brush brushRight = new SolidBrush(Theming.StatusBarTextColorSecondary))
         {
             e.Graphics.DrawString(NativeLang.GetNlsString("Main", _processMode ? "Processes" : "Programs"), MemoryBarFontLeft, brushLeft, new RectangleF(4, 0, pbxTopBar.Width - 4, pbxTopBar.Height - 2), MemoryBarStringFormatLeft);
             e.Graphics.DrawString(_statusString, MemoryBarFontRight, brushRight, new RectangleF(0, 0, pbxTopBar.Width - 4, pbxTopBar.Height - 2), MemoryBarStringFormatRight);
         }
 }
Ejemplo n.º 8
0
        public ExcludeNewForm()
        {
            InitializeComponent();

            // Initialize NLS strings.
            this.Text      = NativeLang.GetNlsString("ExcludeEXE", this.Text);
            lblText.Text   = NativeLang.GetNlsString("ExcludeEXE", lblText.Text);
            menuItem1.Text = NativeLang.GetNlsString("ExcludeEXE", menuItem1.Text);
            menuItem2.Text = NativeLang.GetNlsString("ExcludeEXE", menuItem2.Text);
        }
Ejemplo n.º 9
0
        private void OptionsForm_Closing(object sender, CancelEventArgs e)
        {
            if (_restartChanges)
            {
                MessageBox.Show(NativeLang.GetNlsString("Options", "RestartChanges"));
            }

            // Clean up.
            _handler.ClickEvent -= Handler2_ClickEvent;
            _handler.DrawEvent  -= Handler2_DrawEvent;
            _handler             = null;
        }
Ejemplo n.º 10
0
 private void mnuKill_Click(object sender, EventArgs e)
 {
     if (MessageBox.Show(NativeLang.GetNlsString("AppInfo", "KillConfirmMsg"),
                         NativeLang.GetNlsString("AppInfo", "KillConfirmTitle"), MessageBoxButtons.YesNo,
                         MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button2) != DialogResult.Yes)
     {
         return;
     }
     Cursor.Current = Cursors.WaitCursor;
     OpenNETCF.Windows.Forms.ApplicationEx.DoEvents();
     TaskMgmt.Instance.KillProcess(_processMode ? _proc.ProcessId : _task.ProcessId);
     Program.TheForm.RefreshData();
     Cursor.Current = Cursors.Default;
     Close();
 }
Ejemplo n.º 11
0
        private void mnuKill_Click(object sender, EventArgs e)
        {
            if (lsvTasks.Items.Count < 1)
            {
                Visible = false;
                return;
            }

            if (!AppSettings.GetConfirmCloseAll() || MessageBox.Show(NativeLang.GetNlsString("Main", "CloseAllMsg"), NativeLang.GetNlsString("Main", "CloseAllTitle"), MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1) == DialogResult.Yes)
            {
                for (int i = 0; i < lsvTasks.Items.Count; i++)
                {
                    CloseTask(i, false);
                }

                // Hide this form after closing everything, since there's (theoretically) nothing left to close.
                Visible = false;
            }
        }
Ejemplo n.º 12
0
        private void mnuMenuActivationField_Click(object sender, EventArgs e)
        {
            if (!Program.Handle.IsAllocated)
            {
                // If WM65 compatibility mode is on, we can't do anything with the activation field.
                MessageBox.Show(NativeLang.GetNlsString("Main", "ActivationFieldNotAvailableMsg"));
                return;
            }

            Program.IsShowingDialog = true;
            try
            {
                var frm = new ActivationRelocationForm();
                Program.SetActivationFieldRelocationMode(true);
                var res = frm.ShowDialog();
                frm.Dispose();

                if (res == DialogResult.OK)
                {
                    // We don't need to tell the native DLL the new info because it already has it. Just store it in the registry.
                    AppSettings.SetActivationFieldValue(1, Program.ProcessEventsInstance.X);
                    AppSettings.SetActivationFieldValue(2, Program.ProcessEventsInstance.Y);
                }
                else
                {
                    // Reset back to the previous values.
                    Program.ProcessEventsInstance.EventType = 255;
                    Program.ProcessEventsInstance.X         = (uint)AppSettings.GetActivationFieldValue(1);
                    Program.ProcessEventsInstance.Y         = (uint)AppSettings.GetActivationFieldValue(2);
                    Program.Register(Program.Handle.AddrOfPinnedObject());
                }

                Program.SetActivationFieldRelocationMode(false);
            }
            catch (Exception ex)
            {
                // If there's an activation field-related problem, it's safer to just quit.
                MessageBox.Show("FATAL ERROR: " + ex.Message);
                Close();
            }
            Program.IsShowingDialog = false;
        }
Ejemplo n.º 13
0
 void Start()
 {
     textLangue.text  = NativeLang.GetSystemLanguage();
     textCountry.text = NativeLang.GetSystemCountry();
 }
Ejemplo n.º 14
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);
        }
Ejemplo n.º 15
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;
                }
            }
        }
Ejemplo n.º 16
0
        void Handler2_ClickEvent(Point location, int itemNum, int subitem)
        {
            // Only process stuff if the checkmark area is clicked.
            if (subitem != 0)
            {
                return;
            }

            var newVal = !lsvOptions.Items[itemNum].Checked;

            // Update the ListView.
            lsvOptions.Items[itemNum].Checked = newVal;
            lsvOptions.Invalidate();

            // Save the changes immediately.
            var item = lsvOptions.Items[itemNum];
            var tag  = item.Tag as string;

            if (tag == "icons")
            {
                AppSettings.SetStartMenuIcons(newVal);
                // This requires a restart.
                _restartChanges = true;
            }
            else if (tag == "boot")
            {
                var path = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Startup), "ArkSwitch.lnk");
                if (newVal)
                {
                    // Create the file.
                    if (!File.Exists(path))
                    {
                        var sr  = new StreamWriter(path, false);
                        var app = "\"" + Assembly.GetExecutingAssembly().GetModules()[0].FullyQualifiedName + "\"";
                        sr.Write(app.Length + "#" + app);
                        sr.Flush();
                        sr.Close();
                    }
                }
                else
                {
                    // Delete the file.
                    if (File.Exists(path))
                    {
                        File.Delete(path);
                    }
                }
            }
            else if (tag == "tools")
            {
                var path = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Programs), @"Tools\ArkSwitch.lnk");
                if (newVal)
                {
                    // Create the file.
                    if (!File.Exists(path))
                    {
                        var dir = Path.GetDirectoryName(path);
                        if (!Directory.Exists(dir))
                        {
                            Directory.CreateDirectory(dir);
                        }

                        var sr  = new StreamWriter(path, false);
                        var app = "\"" + Assembly.GetExecutingAssembly().GetModules()[0].FullyQualifiedName + "\"";
                        sr.Write(app.Length + "#" + app);
                        sr.Flush();
                        sr.Close();
                    }
                }
                else
                {
                    // Delete the file.
                    if (File.Exists(path))
                    {
                        File.Delete(path);
                    }
                }
            }
            else if (tag == "std")
            {
                AppSettings.SetTaskbarTakeover(!newVal);
                if (newVal)
                {
                    MessageBox.Show(NativeLang.GetNlsString("Options", "WM65Warning"));
                }
                // This requires a restart.
                _restartChanges = true;
            }
        }