【发布时间】:2017-01-20 08:20:42
【问题描述】:
我想通过进程 ID 最小化应用程序。我在SO上搜索并找到了以下代码
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);
}
但我不想按标题查找窗口,因为应用程序的标题会更改。我有一个来自另一个模块的给定进程 ID,该模块请求使用给定的进程 ID 最小化应用程序。
有这样的事情吗?
public static extern IntPtr FindWindowByProcess(IntPtr ZeroOnly, int lpProcessID);
或者如果没有,无论如何都要绕过去?
【问题讨论】:
-
这是 C++ 中的一个类似问题,其答案可能对您有所帮助:stackoverflow.com/questions/1888863/…
-
看看这个之前的 SO 答案....stackoverflow.com/questions/1888863/… 看起来它为您的问题提供了解决方案。
标签: c#