UIオートメーションの一部であるAutomationElement.FromPoint()をチェックしてください。この一連のAPIは、他のプロセスのUIに関する情報を取得したい自動テストおよびアクセシビリティアプリケーションでよく使用されます。それをサポートするアプリケーション(WindowsとほとんどのMSアプリケーションのほとんどのUI)では、外側のウィンドウだけでなく、UI要素に関する情報を取得できます。このサンプルアプリケーションは、カーソルの下にあるアイテムの名前とタイプ(「ボタン」など)を表示します。
どこでもサポートされているわけではありません。多くの非MSアプリケーションでは動作しない可能性があります(Firefoxではサポートされていますが)。少なくともWindowFromPointなどより優れた結果を得ることができます。
// 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);
}
}
私は画面上に表示されているアプリケーションでどのように動作することを提案しますか? – naokikun