Process.MainWindowTitle 속성

정의

프로세스의 주 창 캡션을 가져옵니다.

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;
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}");
        }
    }
}
open System.Diagnostics

try
    // Create an instance of process component.
    use myProcess = new Process()
    // Create an instance of 'myProcessStartInfo'.
    let myProcessStartInfo = ProcessStartInfo()
    myProcessStartInfo.FileName <- "notepad"
    myProcess.StartInfo <- myProcessStartInfo
    // Start process.
    myProcess.Start() |> ignore
    // Allow the process to finish starting.
    myProcess.WaitForInputIdle() |> ignore
    printfn $"Main window Title : {myProcess.MainWindowTitle}"

    myProcess.CloseMainWindow() |> ignore
with e ->
    printfn $" 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

설명

프로세스에 그래픽 인터페이스가 있는 경우에만 프로세스와 연결된 주 창이 있습니다. 연결된 프로세스에 주 창(0)이 MainWindowHandle 없거나 시스템이 주 창(예: 일부 Unix 플랫폼 MainWindowTitle 의 경우)이 있는지 확인할 수 없는 경우 빈 문자열("")입니다.

프로세스를 시작한 후 주 창 제목을 사용하려는 경우 이 메서드를 사용하여 WaitForInputIdle 프로세스가 시작되도록 허용하고 주 창 핸들이 만들어졌는지 확인하는 것이 좋습니다. 그렇지 않으면 시스템에서 예외를 발생시킵니다.

Note

주 창은 현재 포커스가 있는 창입니다. 프로세스의 기본 창이 아닐 수 있습니다. 개체가 Refresh 변경된 경우 최신 주 창 핸들을 가져오려면 이 메서드를 사용하여 개체를 새로 고쳐 Process 야 합니다.

적용 대상