C#从窗口句柄获取父进程 [英] C# get parent process from window handle

查看:824
本文介绍了C#从窗口句柄获取父进程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个C#Windows应用程序,最终从互操作组件启动了一个对话框. 问题在于此对话框窗口有时会出现在c#应用程序主窗口的后面,迫使用户通过alt-tab键找到它.

I have a C# windows application and ultimately launches a dialog from an interop component. The problem is that this dialog window sometimes appears behind the c# application's main window, forcing a user to alt-tab to find it.

我已采取措施找到此对话框窗口并将其提出...

I've put measures into place to find this dialog window and bring it forward...

private static extern bool SetForegroundWindow(IntPtr hWnd);

public class SearchData
{
    public string Wndclass;
    public string Title;
    public IntPtr hWnd;
}

private static extern bool EnumWindows(EnumWindowsProc lpEnumFunc, ref SearchData data);
private delegate bool EnumWindowsProc(IntPtr hWnd, ref SearchData data);

public static bool EnumProc(IntPtr hWnd, ref SearchData data)
{
  //Code to determine whether the window from handle hWnd is our target window.
  //apply handle, title, class to data and halt the enumeration
}

...但是随着对话框的className和表单标题的更改,查找"对话框是有问题的.

...but 'finding' the dialog is problematic as the dialog's className and form title changes.

但是,对话框窗口的父进程(任务管理器">转到进程")与当前进程相同.因此,要正确地查找"该对话框窗口,我的目的是枚举所有窗口,找到父进程ID并与CurrentProcess进行比较.

However, the dialog window's parent process (Task Manager>Go To Process) is the same as the current process. So to correctly 'find' this dialog window, my aim is to enumerate through all the windows, find the parent processID and compare against CurrentProcess.

有没有办法从窗口句柄获取整个父进程?

Is there a way to obtain the overall parent process from a window handle?

推荐答案

查看全文

登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆