加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

C#如何通过给定的进程ID最小化另一个应用程序?

发布时间:2020-12-15 23:35:21 所属栏目:百科 来源:网络整理
导读:我想通过其进程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 ZeroOnl
我想通过其进程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);

或者如果没有,无论如何要到处走走?

解决方法

只需使用 Process课程.

Process.GetProcessById(YourProcessID).MainWindowHandle

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读