Exemple #1
0
        public void SaveWindowProperties(object sender, EventArgs e)
        {
            Process[] windowedProcesses = WindowUtils.WindowedProcesses();

            foreach (Process process in windowedProcesses)
            {
                Rect rect = new Rect();
                if (WindowUtils.GetWindowRect(process.MainWindowHandle, ref rect))
                {
                    windowProperties[process.ProcessName] = rect;
                }
            }

            // TODO: Save to disk.
        }
Exemple #2
0
        public void RestoreWindowProperties(object sender, EventArgs e)
        {
            Process[] windowedProcesses = WindowUtils.WindowedProcesses();

            foreach (Process process in windowedProcesses)
            {
                string processName = process.ProcessName;

                if (!windowProperties.ContainsKey(processName))
                {
                    continue;
                }

                Rect rect = windowProperties[processName];

                if (!WindowUtils.MoveWindow(process.MainWindowHandle, rect.left, rect.top, rect.width, rect.height, true))
                {
                    Debug.WriteLine("Could not restore window for process: " + processName);
                }
            }
        }
Exemple #3
0
        private void HandleEvent(Keys key)
        {
            var     workingArea = WindowUtils.CurrentWindowScreen().WorkingArea;
            var     newPosition = new Rect();
            EventId eventId     = (EventId)key;

            switch (eventId)
            {
            case EventId.Left:
                newPosition.width  = workingArea.Width / 2;
                newPosition.height = workingArea.Height;
                WindowUtils.SetCurrentWindowRect(newPosition);
                break;

            case EventId.Up:
                newPosition.width  = workingArea.Width;
                newPosition.height = workingArea.Height / 2;
                WindowUtils.SetCurrentWindowRect(newPosition);
                break;

            case EventId.Right:
                newPosition.left   = workingArea.Width / 2;
                newPosition.width  = workingArea.Width / 2;
                newPosition.height = workingArea.Height;
                WindowUtils.SetCurrentWindowRect(newPosition);
                break;

            case EventId.Down:
                newPosition.top    = workingArea.Height / 2;
                newPosition.width  = workingArea.Width;
                newPosition.height = workingArea.Height / 2;
                WindowUtils.SetCurrentWindowRect(newPosition);
                break;

            case EventId.TopLeft:
                newPosition.width  = workingArea.Width / 2;
                newPosition.height = workingArea.Height / 2;
                WindowUtils.SetCurrentWindowRect(newPosition);
                break;

            case EventId.TopRight:
                newPosition.left   = workingArea.Width / 2;
                newPosition.width  = workingArea.Width / 2;
                newPosition.height = workingArea.Height / 2;
                WindowUtils.SetCurrentWindowRect(newPosition);
                break;

            case EventId.BottomLeft:
                newPosition.top    = workingArea.Height / 2;
                newPosition.width  = workingArea.Width / 2;
                newPosition.height = workingArea.Height / 2;
                WindowUtils.SetCurrentWindowRect(newPosition);
                break;

            case EventId.BottomRight:
                newPosition.left   = workingArea.Width / 2;
                newPosition.top    = workingArea.Height / 2;
                newPosition.width  = workingArea.Width / 2;
                newPosition.height = workingArea.Height / 2;
                WindowUtils.SetCurrentWindowRect(newPosition);
                break;

            case EventId.LeftThird:
                newPosition.width  = workingArea.Width / 3;
                newPosition.height = workingArea.Height;
                WindowUtils.SetCurrentWindowRect(newPosition);
                break;

            case EventId.LeftTwoThirds:
                newPosition.width  = (workingArea.Width / 3) * 2;
                newPosition.height = workingArea.Height;
                WindowUtils.SetCurrentWindowRect(newPosition);
                break;

            case EventId.CenterThird:
                newPosition.left   = workingArea.Width / 3;
                newPosition.width  = workingArea.Width / 3;
                newPosition.height = workingArea.Height;
                WindowUtils.SetCurrentWindowRect(newPosition);
                break;

            case EventId.RightTwoThirds:
                newPosition.left   = workingArea.Width / 3;
                newPosition.width  = (workingArea.Width / 3) * 2;
                newPosition.height = workingArea.Height;
                WindowUtils.SetCurrentWindowRect(newPosition);
                break;

            case EventId.RightThird:
                newPosition.left   = (workingArea.Width / 3) * 2;
                newPosition.width  = workingArea.Width / 3;
                newPosition.height = workingArea.Height;
                WindowUtils.SetCurrentWindowRect(newPosition);
                break;

            case EventId.Maximize:
                // FIXME: a real windows ass maximize could be better
                newPosition.width  = workingArea.Width;
                newPosition.height = workingArea.Height;
                WindowUtils.SetCurrentWindowRect(newPosition);
                break;

            case EventId.Center:
                var currentWindowRect = WindowUtils.GetCurrentWindowRect();

                if (currentWindowRect.isValid)
                {
                    newPosition.left   = (workingArea.Width / 2) - (currentWindowRect.width / 2);
                    newPosition.top    = (workingArea.Height / 2) - (currentWindowRect.height / 2);
                    newPosition.width  = currentWindowRect.width;
                    newPosition.height = currentWindowRect.height;
                    WindowUtils.SetCurrentWindowRect(newPosition);
                }

                break;

            default:
                Debug.WriteLine("Unexpected key: " + key);
                break;
            }
        }