Share via


Process.MainWindowTitle Properti

Definisi

Mendapatkan caption jendela utama proses.

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

Nilai Properti

Judul jendela utama proses.

Pengecualian

Properti MainWindowTitle tidak ditentukan karena proses telah keluar.

Anda mencoba mengakses MainWindowTitle properti untuk proses yang berjalan pada komputer jarak jauh. Properti ini hanya tersedia untuk proses yang berjalan pada komputer lokal.

Contoh

Contoh berikut memulai instans Notepad dan mengambil caption jendela utama proses.

#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

Keterangan

Proses memiliki jendela utama yang terkait dengannya hanya jika proses memiliki antarmuka grafis. Jika proses terkait tidak memiliki jendela utama (sehingga MainWindowHandle nol), atau jika sistem tidak dapat menentukan bahwa ada jendela utama (seperti mungkin terjadi pada beberapa platform Unix), MainWindowTitle adalah string kosong ("").

Jika Anda baru saja memulai proses dan ingin menggunakan judul jendela utamanya, pertimbangkan untuk menggunakan WaitForInputIdle metode untuk memungkinkan proses selesai dimulai, memastikan bahwa handel jendela utama telah dibuat. Jika tidak, sistem akan memberikan pengecualian.

Catatan

Jendela utama adalah jendela yang saat ini memiliki fokus; perhatikan bahwa ini mungkin bukan jendela utama untuk proses. Anda harus menggunakan Refresh metode untuk menyegarkan Process objek untuk mendapatkan handel jendela utama terbaru jika telah berubah.

Berlaku untuk