Link to home
Start Free TrialLog in
Avatar of or1969
or1969

asked on

Minimize all opened windows of a selected process using C#

I'm using the following code to minimize selected process window using Process.MainWindowHandle.
public static void MinProcess(int PID)
{
	Process proc = Process.GetProcessById(PID);
	if (proc.ProcessName == string.Empty)
		return;

	ShowWindow(proc.MainWindowHandle, SW_MINIMIZE);
}

[DllImport("User32.DLL")]
private static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);
private const int SW_MINIMIZE = 6;
private const int SW_RESTORE = 9;

Open in new window

My problem is that this code will only minimize one of the opened windows of a selected process, for example: If Outlook is opened with several emails (1 window per email), the code will minimize only one of the windows.

What do I need to change/modify to minimize ALL windows of the selected process?
ASKER CERTIFIED SOLUTION
Avatar of jiangsheng
jiangsheng

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial