I would like to minimize an application by its process id. I have searched on SO and found the following code
private const int SW_MAXIMIZE = 3;
private const int SW_MINIMIZE = 6;
[DllImport("user32.dll", EntryPoint = "FindWindow")]
public static extern IntPtr FindWindowByCaption(IntPtr ZeroOnly, string lpWindowName);
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);
public void MinimizeWindow()
{
IntPtr hwnd = FindWindowByCaption(IntPtr.Zero, "NotePad");
ShowWindow(hwnd, SW_MINIMIZE);
}
But I don't want to find window by caption because the caption for an app changes. I have a given process id that is coming from another module that request minimize the app with the given process id.
Is there such a thing like this?
public static extern IntPtr FindWindowByProcess(IntPtr ZeroOnly, int lpProcessID);
Or if not, anyway to go around?
Just use the Process class.
Process.GetProcessById(YourProcessID).MainWindowHandle
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With