Sehen Sie sich die AutomationElement.FromPoint() an, die Teil der UI-Automatisierung ist - diese API-Suite wird häufig von automatisierten Test- und Barrierefreiheits-Apps verwendet, die Informationen über die Benutzeroberfläche anderer Prozesse abrufen möchten. Für Apps, die dies unterstützen (die meisten Benutzeroberflächen in Windows und den meisten MS-Anwendungen), können Sie Informationen über das Benutzeroberflächenelement erhalten, nicht nur das äußere Fenster. Diese Beispiel-App gibt den Namen und den Typ (z. B. "Schaltfläche") des Elements unter dem Cursor aus.
Es wird nicht überall unterstützt, funktioniert möglicherweise nicht in vielen Nicht-MS-Anwendungen (obwohl es von Firefox unterstützt wird); aber wird Ihnen mindestens bessere Ergebnisse als WindowFromPoint usw.
// Compile using: csc ItemAtPoint.cs /r:UIAutomationClient.dll /r:WindowsBase.dll
using System;
using System.Windows.Automation;
using System.Windows.Forms;
class ItemAtPoint
{
public static void Main()
{
Console.WriteLine("Place pointer over item and hit return...");
Console.ReadLine();
// Get the AutomationElement that represents the window handle...
System.Windows.Point point = new System.Windows.Point(Cursor.Position.X, Cursor.Position.Y);
AutomationElement el = AutomationElement.FromPoint(point);
// Print out the type of the item and its name
Console.WriteLine("item is a \"{0}\" with name \"{1}\"", el.Current.LocalizedControlType, el.Current.Name);
}
}
Ist die Art, wie Sie vorschlagen, wird für jede Anwendung funktionieren, die ich auf dem Bildschirm sehen kann? – naokikun