コード例 #1
0
        private void moveForeground_Click(object sender, EventArgs e)
        {
            var line = belowProcesses.SelectedItem;

            if (line == null)
            {
                return;
            }

            if (line is string val)
            {
                //Parse for the process id.
                var id      = val.Split(' ').First();
                int idValue = int.Parse(id);

                if (MovedProcesses.TryGetValue(idValue, out var processMatch))
                {
                    //Reset the process parent, moving it back above the desktop.
                    Natives.SetParent(processMatch.Process.MainWindowHandle, processMatch.OriginalParent);
                    //Focus the window
                    bringToFront(processMatch.Process.MainWindowHandle);

                    //Reset wallpaper and remove stored process info.
                    belowProcesses.Items.Remove(val);
                    SetImage();
                    MovedProcesses.Remove(idValue);
                }
            }
        }
コード例 #2
0
        public void RestoreMovedProcesses()
        {
            //Iterate through each moved process and restore it.
            foreach (var pair in MovedProcesses)
            {
                Natives.SetParent(pair.Value.Process.MainWindowHandle, pair.Value.OriginalParent);
                bringToFront(pair.Value.Process.MainWindowHandle);
            }

            //Clear stored info and reset wallpaper
            MovedProcesses.Clear();
            belowProcesses.Items.Clear();
            SetImage();
        }
コード例 #3
0
        private void moveToDesktop_Click(object sender, EventArgs e)
        {
            var line = processCombo.SelectedItem;

            if (line == null)
            {
                return;
            }

            if (line is string val)
            {
                //Parse the combobox item for it's process id.
                var id      = val.Split(' ').First();
                int idValue = int.Parse(id);

                var process = Processes.FirstOrDefault(x => x.Key == idValue);
                if (process.Value == null)
                {
                    //Show error if program was closed after being added to list but prior to being added to desktop.
                    MessageBox.Show("Program with the given ID was not found.");
                    return;
                }

                if (MovedProcesses.ContainsKey(idValue))
                {
                    //Ensure the process is not already on the desktop.
                    MessageBox.Show("Program is already below the desktop.");
                    return;
                }


                //Set the processes parent to be the workerW process
                var originalParent = Natives.SetParent(process.Value.MainWindowHandle, GetHandle());
                belowProcesses.Items.Add(val);
                MovedProcesses.Add(idValue, new MovedProcess(originalParent, process.Value));
            }
        }
コード例 #4
0
        private void button1_Click(object sender, EventArgs e)
        {
            var workerw = GetHandle();

            string gifPath = "";

            //Select a gif file to be placed in the picture box.
            using (OpenFileDialog openFileDialog = new OpenFileDialog
            {
                Filter = "Gif files (*.gif)|*.gif",
                Title = "Open gif file",
                AutoUpgradeEnabled = false
            })
            {
                if (openFileDialog.ShowDialog() != DialogResult.OK)
                {
                    return;
                }

                try
                {
                    //Set variables to match the data returned by the selected image
                    gifPath = openFileDialog.FileName;

                    //Set the value in the picturebox as a preview of the selected image
                    pictureBox1.ImageLocation = gifPath;
                    pictureBox1.SizeMode      = PictureBoxSizeMode.StretchImage;
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                    return;
                }
            }

            // Create a new background form
            var form = new BackgroundForm();

            //Fetch the selected monitor
            int monitorId = int.Parse(numericUpDown1.Value.ToString());

            //Attempt to remove previously allocated items from that monitor
            if (Forms.TryGetValue(monitorId, out var currentForm))
            {
                currentForm.Form.Close();
                Forms.Remove(monitorId);
            }
            Forms.Add(monitorId, form);

            // Set the background forum to be borderless
            form.Form.FormBorderStyle = FormBorderStyle.None;
            form.Form.Text            = "PassiveWallpaper";

            Screen selectedScreen = Screen.AllScreens[monitorId];

            //On the loading of the background form set the new properties
            form.Form.Load += (s, e2) =>
            {
                //Ensure the form takes up the entire screen size of the selected monitor
                form.Form.Width  = selectedScreen.Bounds.Width;
                form.Form.Height = selectedScreen.Bounds.Height;
                form.Form.Left   = selectedScreen.Bounds.X;
                form.Form.Top    = selectedScreen.Bounds.Y;

                //Create a new picturebox that fills the form and set it's image contents
                PictureBox pic = new PictureBox
                {
                    Width         = form.Form.Width,
                    Height        = form.Form.Height,
                    Left          = 0,
                    Top           = 0,
                    Name          = "PictureBox",
                    ImageLocation = gifPath,
                    SizeMode      = PictureBoxSizeMode.StretchImage
                };

                if (transparent.Checked)
                {
                    //Set the image to be transparent backgrounded and set it's background image to be the current desktop background.
                    pic.BackColor       = Color.Transparent;
                    pic.BackgroundImage = new Bitmap(GetCurrentWallpaperPath());
                }
                else
                {
                    pic.BackColor       = Color.White;
                    pic.BackgroundImage = null;
                }

                //Add the picturebox to the form
                form.Form.Controls.Add(pic);

                //Ensure the parent of the new form is the WorkerW process that was spawned between the desktop wallpaper and icons
                Natives.SetParent(form.Form.Handle, workerw);
            };

            //Ensure that the closing event of the form is set in order to re-set the current desktop wallpaper and 'refresh' it, removing any artifacts
            form.Form.Closing += (s2, a2) => SetImage();

            //Finally display the new form to the user.
            form.Form.Show();
        }