static void PlaceWindowOnScreen(IntPtr hWnd)
{
if (IsZoomed(hWnd))
{
return;
}
WindowInfo wi = Utils.GetWindowInfo(hWnd);
int maxVisibleArea = 0;
Rectangle resultWindowRect = new Rectangle();
bool found = false;
foreach (var s in Screen.AllScreens)
{
int visibleArea = GetWindowVisibleArea(wi, s);
if (visibleArea > maxVisibleArea)
{
maxVisibleArea = visibleArea;
resultWindowRect = GetVisibleRectangle(wi, s);
found = true;
}
}
if (found)
{
MoveWindow(hWnd, resultWindowRect.X, resultWindowRect.Y, resultWindowRect.Width, resultWindowRect.Height, true);
}
}