【问题标题】:How do i a get a process window name and maintitlename by using the window handle or id?如何使用窗口句柄或 id 获取进程窗口名称和主标题名称?
【发布时间】:2015-12-31 03:24:32
【问题描述】:

在按钮单击事件中 IEnumerable res;

System.Threading.Thread.Sleep(10000);
var windows = FindWindowsWithText("GrADS 2.0.2.oga.2");
GetWindowThreadProcessId(windows,out res)

然后 FindWindowsWithText

public static IEnumerable<IntPtr> FindWindowsWithText(string titleText)
        {
            return FindWindows(delegate(IntPtr wnd, IntPtr param)
            {
                return GetWindowText(wnd).Contains(titleText);
            });
        }

然后在变量窗口中,在这种情况下我得到一个计数和句柄编号: [0] = 3343352

有了这个数字 3343352,我需要找到最后的进程,在这种情况下是外部进程名称和进程主窗口标题。

使用这个

IEnumerable<IntPtr> res;

不确定我认为获取 id 然后以某种方式使用 id 获取名称和主窗口标题是否有任何好处。我弄得一团糟。

【问题讨论】:

    标签: c# .net winforms


    【解决方案1】:

    只需使用process = Process.GetProcessById(id) 即可通过ID 获取进程。然后你可以使用process.MainWindowTitleprocess.ProcessName

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-11-12
    • 2013-05-09
    • 1970-01-01
    • 2013-12-08
    • 2010-12-25
    • 1970-01-01
    • 2011-02-26
    相关资源
    最近更新 更多