Process.MainWindowTitle プロパティ

定義

プロセスのメイン ウィンドウのキャプションを取得します。

public:
 property System::String ^ MainWindowTitle { System::String ^ get(); };
public string MainWindowTitle { get; }
member this.MainWindowTitle : string
Public ReadOnly Property MainWindowTitle As String

プロパティ値

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 0) 場合、またはシステムがメイン ウィンドウ (一部の Unix プラットフォームの場合など) MainWindowTitle があると判断できない場合は、空の文字列 ("") です。

プロセスを開始したばかりの場合は、メイン ウィンドウ のタイトルを使用する場合は、メイン ウィンドウ ハンドルが作成されていることを確認して、プロセスの開始を完了できるように、メソッドを使用 WaitForInputIdle することを検討してください。 それ以外の場合、例外がスローされます。

注意

メイン ウィンドウは、現在フォーカスがあるウィンドウです。これは、プロセスのプライマリ ウィンドウではない可能性があることに注意してください。 このメソッドを Refresh 使用して、オブジェクトが Process 変更された場合に最新のメイン ウィンドウ ハンドルを取得するようにオブジェクトを更新する必要があります。

適用対象