|  | ■No87882 (サンタクロース村 さん) に返信 > 知りたいのは、どのような関数を使ってマウスカーソルがあたった箇所のコントロールなどを認識できるんでしょうか?
 
 
 API 宣言無しで、.NET Framework のみで検出してみたパターン。
 とりあえず VB + WinForms で書いてみました。
 
 フォームに 幅広の ListBox を 2 つと
 Timer を 1 つ貼っておいてください。
 
 
 Option Strict On
 Public Class Form1
 Private desktop As AccessibleObject
 Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
 Dim ao = Me.AccessibilityObject
 desktop = ao.Parent.Parent
 Timer1.Interval = 64
 Timer1.Start()
 End Sub
 
 Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
 Dim p = MousePosition
 Me.Text = p.ToString()
 
 Dim o1 = desktop.HitTest(p.X, p.Y)
 Dim o2 = o1
 If o1 IsNot Nothing Then
 Dim o3 = o2.HitTest(p.X, p.Y)
 Do Until o3 Is Nothing
 o2 = o3
 o3 = o2.HitTest(p.X, p.Y)
 Loop
 End If
 
 ListBox1.DataSource = GetInfo(o1).ToArray()
 ListBox2.DataSource = GetInfo(o2).ToArray()
 End Sub
 
 Private Iterator Function GetInfo(ao As AccessibleObject) As IEnumerable(Of String)
 Yield "Bounds = " & ReadValue(Function() ao.Bounds).ToString()
 Yield "Name = " & ReadValue(Function() ao.Name,)
 Yield "KeyboardShortcut = " & ReadValue(Function() ao.KeyboardShortcut)
 Yield "Description = " & ReadValue(Function() ao.Description)
 Yield "Help = " & ReadValue(Function() ao.Help)
 Yield "State = " & ReadValue(Function() ao.State).ToString("F")
 Yield "Value = " & ReadValue(Function() ao.Value)
 End Function
 
 Private Function ReadValue(Of T)(lamda As Func(Of T), Optional defaultValue As T = Nothing) As T
 Try
 Return lamda()
 Catch
 Return defaultValue
 End Try
 End Function
 End Class
 
 |