Exemplo n.º 1
0
        private ListBoxProcessItem GetListBoxItemForWindowOutOfBounds(IntPtr winHandlePtr)
        {
            ListBoxProcessItem listBoxProcessItem = null;

            Rect windowPosition = new Rect();

            GetWindowRect(winHandlePtr, ref windowPosition);
            int winHeight = Math.Max(windowPosition.Bottom - windowPosition.Top, 25);
            int winWidth  = Math.Max(windowPosition.Left - windowPosition.Right, 25);

            if (windowPosition.Top < 0 || windowPosition.Bottom > Screen.PrimaryScreen.Bounds.Height || (windowPosition.Right < winHeight) ||
                (windowPosition.Left + winWidth) > Screen.PrimaryScreen.Bounds.Width)
            {
                StringBuilder windowTitle = new StringBuilder();
                GetWindowText(winHandlePtr, windowTitle, 1024);
                listBoxProcessItem = new ListBoxProcessItem
                {
                    Name         = windowTitle.ToString(),
                    WindowHandle = winHandlePtr,
                    Value        = winHandlePtr.ToInt64().ToString(CultureInfo.InvariantCulture)
                };
            }

            return(listBoxProcessItem);
        }
Exemplo n.º 2
0
        private void UpdateProcessList()
        {
            try
            {
                listBoxWindows.Items.Clear();
                Process[] processes = Process.GetProcesses();
                foreach (Process process in processes)
                {
                    try
                    {
                        if (process.MainWindowHandle != IntPtr.Zero)
                        {
                            List <IntPtr> childWindows = GetChildWindows(process.MainWindowHandle);

                            ListBoxProcessItem mainItem = GetListBoxItemForWindowOutOfBounds(process.MainWindowHandle);
                            if (mainItem != null)
                            {
                                listBoxWindows.Items.Add(mainItem);
                            }

                            foreach (IntPtr childWindowRef in childWindows)
                            {
                                ListBoxProcessItem listBoxProcessItem = GetListBoxItemForWindowOutOfBounds(childWindowRef);
                                if (listBoxProcessItem != null)
                                {
                                    listBoxWindows.Items.Add(listBoxProcessItem);
                                }
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message);
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Exemplo n.º 3
0
        private void btnMoveWindows_Click(object sender, EventArgs e)
        {
            foreach (var listItem in listBoxWindows.SelectedItems)
            {
                ListBoxProcessItem listBoxProcessItem = listItem as ListBoxProcessItem;

                if (listBoxProcessItem != null)
                {
                    IntPtr mainWindowHandle = listBoxProcessItem.WindowHandle;

                    Rect windowPosition = new Rect();
                    GetWindowRect(mainWindowHandle, ref windowPosition);
                    int winHeight = Math.Max(Math.Abs(windowPosition.Bottom - windowPosition.Top), 25);
                    int winWidth  = Math.Max(Math.Abs(windowPosition.Left - windowPosition.Right), 25);

                    winWidth  = Math.Min(winWidth, Screen.PrimaryScreen.Bounds.Width / 2);
                    winHeight = Math.Min(winHeight, Screen.PrimaryScreen.Bounds.Height / 2);

                    MoveWindow(mainWindowHandle, 25, 25, winWidth, winHeight, true);
                }
            }

            UpdateProcessList();
        }