Process.MainWindowTitle Propriété
Définition
Important
Certaines informations portent sur la préversion du produit qui est susceptible d’être en grande partie modifiée avant sa publication. Microsoft exclut toute garantie, expresse ou implicite, concernant les informations fournies ici.
Obtient la légende de la fenêtre principale du processus.
public:
property System::String ^ MainWindowTitle { System::String ^ get(); };
public string MainWindowTitle { get; }
member this.MainWindowTitle : string
Public ReadOnly Property MainWindowTitle As String
Valeur de propriété
Titre de la fenêtre principale du processus.
Exceptions
La propriété MainWindowTitle n’est pas définie, car le processus s’est fermé.
Vous tentez d’accéder à la propriété MainWindowTitle d’un processus en cours d’exécution sur un ordinateur distant. Cette propriété est disponible uniquement pour les processus en cours d’exécution sur l’ordinateur local.
Exemples
L’exemple suivant démarre une instance du Bloc-notes et récupère la légende de la fenêtre principale du processus.
#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
Remarques
Un processus a une fenêtre principale associée uniquement si le processus a une interface graphique. Si le processus associé n’a pas de fenêtre principale (c’est-à-dire MainWindowHandle zéro), ou si le système ne peut pas déterminer qu’il existe une fenêtre principale (par exemple, sur certaines plateformes Unix), MainWindowTitle il s’agit d’une chaîne vide (« »).
Si vous venez de démarrer un processus et que vous souhaitez utiliser son titre de fenêtre principale, envisagez d’utiliser la WaitForInputIdle méthode pour permettre au processus de terminer le démarrage, en veillant à ce que le handle de fenêtre principale ait été créé. Si cette consigne n'est pas respectée, le système lèvera une exception.
Notes
La fenêtre principale est la fenêtre qui a actuellement le focus ; Notez qu’il peut ne pas s’agir de la fenêtre principale du processus. Vous devez utiliser la Refresh méthode pour actualiser l’objet Process pour obtenir le handle de fenêtre principale le plus à jour s’il a changé.