This repository was archived by the owner on Dec 5, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWindowController.cs
More file actions
70 lines (57 loc) · 2.11 KB
/
WindowController.cs
File metadata and controls
70 lines (57 loc) · 2.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
using System;
using System.Linq;
using System.Windows.Forms;
namespace MultiAppLauncher
{
public class WindowController
{
private readonly IMainFormView _view;
public WindowController(IMainFormView view)
{
_view = view;
}
public void AutoLayout(IntPtr mainWindowHandle)
{
var screenRect = Screen.PrimaryScreen.WorkingArea;
var windows = _view.GetListViewItems()
.Where(t => t.Tag != null)
.Select(y => y.GetProcessHolder().Process.MainWindowHandle)
.ToList();
if (windows.Any())
{
int columns = (int)Math.Sqrt(windows.Count);
int rows = windows.Count / columns;
if (rows * columns < windows.Count)
rows++;
int windowWidth = screenRect.Width / columns;
int windowHeigth = screenRect.Height / rows;
int i = 0;
for (int y = 0; y < rows; y++)
{
for (int x = 0; x < columns && i < windows.Count; x++, i++)
{
Unmanaged.SetWindowPos(
windows[i],
Unmanaged.HWND_TOPMOST,
x * windowWidth,
y * windowHeigth,
windowWidth,
windowHeigth,
SetWindowPosFlags.SWP_SHOWWINDOW | SetWindowPosFlags.SWP_NOZORDER);
}
}
}
// bring this window to front
Unmanaged.RECT mainWindowRect;
Unmanaged.GetWindowRect(mainWindowHandle, out mainWindowRect);
Unmanaged.SetWindowPos(
mainWindowHandle,
Unmanaged.HWND_TOPMOST,
screenRect.Width - mainWindowRect.Width,
screenRect.Height - mainWindowRect.Height,
mainWindowRect.Width,
mainWindowRect.Height,
SetWindowPosFlags.SWP_SHOWWINDOW);
}
}
}