Process.MainWindowTitle Właściwość

Definicja

Pobiera podpis głównego okna procesu.

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

Wartość właściwości

String

Główny tytuł okna procesu.

Wyjątki

Właściwość nie jest zdefiniowana MainWindowTitle , ponieważ proces zakończył się.

Próbujesz uzyskać dostęp do MainWindowTitle właściwości dla procesu uruchomionego na komputerze zdalnym. Ta właściwość jest dostępna tylko dla procesów uruchomionych na komputerze lokalnym.

Przykłady

Poniższy przykład uruchamia wystąpienie Notatnika i pobiera podpis głównego okna procesu.

#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

Uwagi

Proces ma skojarzone z nim okno główne tylko wtedy, gdy proces ma interfejs graficzny. Jeśli skojarzony proces nie ma okna głównego (czyli MainWindowHandle zero), lub jeśli system nie może ustalić, czy istnieje okno główne (takie jak może być w przypadku niektórych platform Unix), MainWindowTitle jest pustym ciągiem ("").

Jeśli właśnie rozpoczęto proces i chcesz użyć głównego tytułu okna, rozważ użycie WaitForInputIdle metody , aby umożliwić rozpoczęcie procesu, upewniając się, że główny uchwyt okna został utworzony. W przeciwnym razie system zgłasza wyjątek.

Uwaga

Głównym oknem jest okno, które obecnie ma fokus; Należy pamiętać, że może to nie być okno podstawowe dla tego procesu. Należy użyć Refresh metody , aby odświeżyć obiekt, Process aby uzyskać najbardziej aktualny uchwyt okna głównego, jeśli uległ zmianie.

Dotyczy