using System;
using System.Collections.Generic;
using System.Windows.Forms;
using System.Threading;
namespace MinimiseWindow
{
static class Program
{
///
/// The main entry point for the application.
///
[STAThread]
static void Main(string[] args)
{
if (args.Length < 1 || args.Length > 2)
{
MessageBox.Show("Syntax: MinimiseWindow [secondsToWait]\n\n can be the full caption, or the ending part.\n[secondsToWait] Keep looking for the window until this amount of time has elapsed.", "Minimise Window", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
int secondsToWait = 0;
Int32.TryParse(args[1], out secondsToWait);
bool foundWindow = false;
while (!foundWindow && secondsToWait >= 0)
{
Windows windows = new Windows(false, false);
foreach (Window w in windows)
{
if (w.Title.EndsWith(args[0]))
{
foundWindow = true;
NativeMethods.PostMessage(w.hWnd, NativeMethods.WM_SYSCOMMAND, NativeMethods.SC_MINIMIZE, 0);
break;
}
}
if (!foundWindow)
{
if (secondsToWait > 0)
{
Thread.Sleep(1000);
}
secondsToWait--;
}
}
}
}
}