here's a quick example i knocked up just for you mate ...
PHP Code:
[StructLayout(LayoutKind.Sequential)]
private struct WINDOWPLACEMENT
{
internal int Length;
internal int flags;
internal int showCmd;
internal Point ptMinPosition;
internal Point ptMaxPosition;
internal Rectangle rcNormalPosition;
}
[DllImport("user32.dll")]
private static extern int GetWindowPlacement (int hwnd, ref WINDOWPLACEMENT lpwndpl);
[DllImport("user32.dll")]
private static extern int SetWindowPlacement (int hwnd, ref WINDOWPLACEMENT lpwndpl);
private const int SW_MINIMIZE = 6;
private WINDOWPLACEMENT oldWinPlace;
private WINDOWPLACEMENT newWinPlace;
private void button1_Click(object sender, System.EventArgs e)
{
Process[] procs = Process.GetProcesses();
foreach(Process p in procs)
{
ListViewItem lvi = new ListViewItem(p.ProcessName);
lvi.SubItems.Add(p.MainWindowHandle.ToString());
listView1.Items.Add(lvi);
}
}
private void listView1_Click(object sender, System.EventArgs e)
{
if(listView1.SelectedItems.Count != 0)
{
if(Convert.ToInt32(listView1.SelectedItems[0].SubItems[1].Text) != 0)
{
int hHandle = Convert.ToInt32(listView1.SelectedItems[0].SubItems[1].Text);
oldWinPlace = new WINDOWPLACEMENT(); // this will hold the window's existing Placement info ( For restoring the window later ).
newWinPlace = new WINDOWPLACEMENT();
GetWindowPlacement(hHandle , ref oldWinPlace);
newWinPlace.showCmd = SW_MINIMIZE;
newWinPlace.Length = Marshal.SizeOf(newWinPlace);
SetWindowPlacement(hHandle , ref newWinPlace);
}
}
}
private void button2_Click(object sender, System.EventArgs e)
{
// to restore the window to it's original state...
try
{
if(listView1.SelectedItems.Count != 0)
{
if(Convert.ToInt32(listView1.SelectedItems[0].SubItems[1].Text) != 0)
{
int hHandle = Convert.ToInt32(listView1.SelectedItems[0].SubItems[1].Text);
SetWindowPlacement(hHandle , ref oldWinPlace);
}
}
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
}