Minimize or hide an external program (vb.net)

  • Thread starter Thread starter news.microsoft.com
  • Start date Start date
N

news.microsoft.com

Hi,

I want to write a small program that can minimize another program running on
the computer.
If I press a button on the first program, the second program has to toggle
between minimized and maximized.

Are there any window calls that let you do that?

I can get the window handle from the program with
"process.start("secondprogram.exe").MainWindowHandle"
So I guess this can be a part of the solution?

Joris
 
Hi Joris,

You need to send windows messages to the process you are starting. Check the
code below:

public const int SW_HIDE = 0x00;
public const int SW_SHOWNORMAL = 0x01;
public const int SW_SHOWMINIMIZED = 0x02;
public const int SW_SHOWMAXIMIZED= 0x03;
public const int SW_SHOWNOACTIVATE = 0x04;
public const int SW_SHOW = 0x05;
public const int SW_MINIMIZE = 0x06;
public const int SW_SHOWMINNOACTIVATE = 0x07;
public const int SW_SHOWNA = 0x08;
public const int SW_RESTORE = 0x09;

[DllImport("USER32.DLL")]
public static extern bool ShowWindow(IntPtr hWnd, uint nCmdShow);

private Process p;
private IntPtr handle;

private void StartProcess_Click(object sender, System.EventArgs e)
{
p = Process.Start("IExplore.exe");
handle = p.MainWindowHandle;
}

private void Maximise_Click(object sender, System.EventArgs e)
{
ShowWindow(handle, SW_SHOWMAXIMIZED);
}

private void Minimise_Click(object sender, System.EventArgs e)
{
ShowWindow(handle, SW_SHOWMINIMIZED);
}


hope this helps

Fitim Skenderi
 
Back
Top