WindowClosedEventArgs.GetRuntimeId Méthode
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.
Récupère l’identificateur d’exécution (ID) UI Automation associé à cet événement.
public:
cli::array <int> ^ GetRuntimeId();
public int[] GetRuntimeId ();
member this.GetRuntimeId : unit -> int[]
Public Function GetRuntimeId () As Integer()
Retours
- Int32[]
ID d’exécution UI Automation de la fenêtre sur laquelle l’événement a été déclenché.
Exemples
Dans l’exemple suivant, le gestionnaire de l’événement de fermeture de fenêtre détermine si l’ID d’exécution de la fenêtre fermée figure dans une liste des ID des fenêtres ouvertes. Si l’ID d’exécution est présent, il est supprimé de la liste.
/// <summary>
/// Handles window-closed events. Removes the window from the top-level window list.
/// </summary>
/// <param name="sender">Object that raised the event.</param>
/// <param name="e">Event arguments.</param>
/// <remarks>
/// runtimteIds is an ArrayList that contains the runtime IDs of all top-level windows.
/// </remarks>
private void WindowClosedHandler(object sender, AutomationEventArgs e)
{
WindowClosedEventArgs windowEventArgs = (WindowClosedEventArgs)e;
int[] runtimeIdentifiers = windowEventArgs.GetRuntimeId();
int index = RuntimeIdListed(runtimeIdentifiers, savedRuntimeIds);
if (index >= 0)
{
savedRuntimeIds.RemoveAt(index);
Console.WriteLine("Window closed.");
}
}
/// <summary>
/// Ascertains whether the window is in the list.
/// </summary>
/// <param name="rid">Runtime ID of the window.</param>
/// <returns>Index of the ID in the list, or -1 if it is not listed.</returns>
/// <remarks>
/// runtimteIds is an ArrayList that contains the runtime IDs of all top-level windows.
/// </remarks>
private int RuntimeIdListed(int[] runtimeId, ArrayList runtimeIds)
{
for (int x = 0; x < runtimeIds.Count; x++)
{
int[] listedId = (int[])runtimeIds[x];
if (Automation.Compare(listedId, runtimeId))
{
return x;
}
}
return -1;
}
''' <summary>
''' Handles window-closed events. Removes the window from the top-level window list.
''' </summary>
''' <param name="sender">Object that raised the event.</param>
''' <param name="e">Event arguments.</param>
''' <remarks>
''' runtimteIds is an ArrayList that contains the runtime IDs of all top-level windows.
''' </remarks>
Private Sub WindowClosedHandler(ByVal sender As Object, ByVal e As AutomationEventArgs)
Dim windowEventArgs As WindowClosedEventArgs = CType(e, WindowClosedEventArgs)
Dim runtimeIdentifiers As Integer() = windowEventArgs.GetRuntimeId()
Dim index As Integer = RuntimeIdListed(runtimeIdentifiers, savedRuntimeIds)
If index >= 0 Then
savedRuntimeIds.RemoveAt(index)
Console.WriteLine("Window closed.")
End If
End Sub
''' <summary>
''' Ascertains whether the window is in the list.
''' </summary>
''' <param name="rid">Runtime ID of the window.</param>
''' <returns>Index of the ID in the list, or -1 if it is not listed.</returns>
''' <remarks>
''' runtimteIds is an ArrayList that contains the runtime IDs of all top-level windows.
''' </remarks>
Private Function RuntimeIdListed(ByVal runtimeId() As Integer, ByVal runtimeIds As ArrayList) As Integer
Dim x As Integer
For x = 0 To runtimeIds.Count - 1
Dim listedId As Integer() = CType(runtimeIds(x), Integer())
If Automation.Compare(listedId, runtimeId) Then
Return x
End If
Next x
Return - 1
End Function 'RuntimeIdListed
Remarques
Lorsque votre application reçoit un événement fermé par une fenêtre, le sender
paramètre du gestionnaire d’événements ne peut pas être utilisé pour obtenir des informations sur la fenêtre fermée, car l’élément Microsoft UI Automation correspondant n’est plus valide. Permet GetRuntimeId de faire correspondre la fenêtre à un identificateur connu.