Process.MainWindowTitle 属性
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
获取进程的主窗口标题。
public:
property System::String ^ MainWindowTitle { System::String ^ get(); };
public string MainWindowTitle { get; }
member this.MainWindowTitle : string
Public ReadOnly Property MainWindowTitle As String
属性值
进程的主窗口标题。
例外
未定义 MainWindowTitle 属性,因为进程已退出。
你正尝试访问在远程计算机上运行的进程的 MainWindowTitle 属性。 此属性仅可用于本地计算机上运行的进程。
示例
以下示例启动记事本的实例,并检索进程主窗口的标题。
#using <System.dll>
using namespace System;
using namespace System::Diagnostics;
int main()
{
try
{
// Create an instance of process component.
Process^ myProcess = gcnew Process;
// Create an instance of 'myProcessStartInfo'.
ProcessStartInfo^ myProcessStartInfo = gcnew ProcessStartInfo;
myProcessStartInfo->FileName = "notepad";
myProcess->StartInfo = myProcessStartInfo;
// Start process.
myProcess->Start();
// Allow the process to finish starting.
myProcess->WaitForInputIdle();
Console::Write( "Main window Title : {0}", myProcess->MainWindowTitle );
myProcess->CloseMainWindow();
myProcess->Close();
}
catch ( Exception^ e )
{
Console::Write( " Message : {0}", e->Message );
}
}
using System;
using System.Diagnostics;
class MainWindowTitleClass
{
public static void Main()
{
try
{
// Create an instance of process component.
using (Process myProcess = new Process())
{
// Create an instance of 'myProcessStartInfo'.
ProcessStartInfo myProcessStartInfo = new ProcessStartInfo();
myProcessStartInfo.FileName = "notepad";
myProcess.StartInfo = myProcessStartInfo;
// Start process.
myProcess.Start();
// Allow the process to finish starting.
myProcess.WaitForInputIdle();
Console.Write("Main window Title : " + myProcess.MainWindowTitle);
myProcess.CloseMainWindow();
}
}
catch (Exception e)
{
Console.Write($" Message : {e.Message}");
}
}
}
Imports System.Diagnostics
Class MainWindowTitleClass
Public Shared Sub Main()
Try
' Create an instance of process component.
Using myProcess As New Process()
' Create an instance of 'myProcessStartInfo'.
Dim myProcessStartInfo As New ProcessStartInfo()
myProcessStartInfo.FileName = "notepad"
myProcess.StartInfo = myProcessStartInfo
' Start process.
myProcess.Start()
' Allow the process to finish starting.
myProcess.WaitForInputIdle()
Console.Write("Main window Title : " + myProcess.MainWindowTitle)
myProcess.CloseMainWindow()
End Using
Catch e As Exception
Console.Write($" Message : {e.Message}")
End Try
End Sub
End Class
注解
仅当进程具有图形界面时,进程才具有与之关联的主窗口。 如果关联的进程没有主窗口 (以便为 MainWindowHandle 零) ,或者系统无法确定存在主窗口 ((例如某些 Unix 平台上 MainWindowTitle) 的情况),则为空字符串 (“”) 。
如果刚启动一个进程并想要使用其主窗口标题,请考虑使用 WaitForInputIdle 该方法让进程完成启动,确保已创建主窗口句柄。 否则,系统将引发异常。