【问题标题】:C# How to minimize another application by a given process id?C#如何通过给定的进程ID最小化另一个应用程序?
【发布时间】: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#


【解决方案1】:

只需使用Process 类。

Process.GetProcessById(YourProcessID).MainWindowHandle

【讨论】:

  • 谢谢 MethodMan,这正是我需要的:通过进程 ID 获取句柄。然后我可以用手柄做最小化工作。再次感谢。
猜你喜欢
  • 1970-01-01
  • 2014-06-30
  • 1970-01-01
  • 2016-03-11
  • 2012-02-24
  • 2021-09-15
  • 1970-01-01
  • 1970-01-01
  • 2013-11-28
相关资源
最近更新 更多