Process.MainWindowHandle Process.MainWindowHandle Process.MainWindowHandle Process.MainWindowHandle Property

定义

获取关联进程主窗口的窗口句柄。Gets the window handle of the main window of the associated process.

public:
 property IntPtr MainWindowHandle { IntPtr get(); };
public IntPtr MainWindowHandle { get; }
member this.MainWindowHandle : nativeint
Public ReadOnly Property MainWindowHandle As IntPtr

属性值

关联进程主窗口的系统生成的窗口句柄。The system-generated window handle of the main window of the associated process.

异常

未定义 MainWindowHandle,因为已退出进程。The MainWindowHandle is not defined because the process has exited.

你正尝试访问在远程计算机上运行的进程的 MainWindowHandle 属性。You are trying to access the MainWindowHandle property for a process that is running on a remote computer. 此属性仅可用于本地计算机上运行的进程。This property is available only for processes that are running on the local computer.

该平台是 Windows 98 或 Windows Millennium Edition (Windows Me);将 UseShellExecute 设置为 false,以在 Windows 98 和 Windows Me 上访问此属性。The platform is Windows 98 or Windows Millennium Edition (Windows Me); set UseShellExecute to false to access this property on Windows 98 and Windows Me.

注解

主窗口是当前具有焦点的进程打开的窗口 (TopLevel窗体)。The main window is the window opened by the process that currently has the focus (the TopLevel form). 必须使用Refresh方法来刷新Process要获取当前的主窗口句柄已更改对象。You must use the Refresh method to refresh the Process object to get the current main window handle if it has changed. 一般情况下,由于缓存的窗口句柄,因此使用Refresh事先以保证,将检索当前句柄。In general, because the window handle is cached, use Refresh beforehand to guarantee that you'll retrieve the current handle.

可以获取MainWindowHandle仅对本地计算机运行的进程的属性。You can get the MainWindowHandle property only for processes that are running on the local computer. MainWindowHandle属性是唯一标识与该进程关联的窗口的值。The MainWindowHandle property is a value that uniquely identifies the window that is associated with the process.

某个进程拥有仅当该过程具有图形界面与之关联的主窗口。A process has a main window associated with it only if the process has a graphical interface. 如果关联的进程没有主窗口、MainWindowHandle值为零。If the associated process does not have a main window, the MainWindowHandle value is zero. 值也为零的进程的已被隐藏,即,处理不可见的任务栏中的。The value is also zero for processes that have been hidden, that is, processes that are not visible in the taskbar. 这可以是任务栏的以图标在通知区域中,在最右侧中显示的进程这种情况。This can be the case for processes that appear as icons in the notification area, at the far right of the taskbar.

如果你只需启动了一个进程,并想要使用其主窗口句柄,请考虑使用WaitForInputIdle方法,以允许该进程完成后从开始,确保已创建了主窗口句柄。If you have just started a process and want to use its main window handle, consider using the WaitForInputIdle method to allow the process to finish starting, ensuring that the main window handle has been created. 否则,将引发异常。Otherwise, an exception will be thrown.

安全性

LinkDemand
对于直接调用方的完全信任。for full trust for the immediate caller. 此成员不能由部分信任的代码使用。This member cannot be used by partially trusted code.

适用于

另请参阅