implement search by control bounds

This commit is contained in:
Jonathan Jenne
2019-09-19 16:20:09 +02:00
parent 88bae3ee92
commit a765fe4cce
13 changed files with 1673 additions and 416 deletions

View File

@@ -1,75 +1,66 @@
Imports System.Windows.Automation
Imports DD_Clipboard_Watcher.ClassWindowAPI
Imports DigitalData.Modules.Windows
Imports DigitalData.Modules.Windows.Window
Public Class frmControlCapture
Public ControlName As String
Public ProcessName As String
Public AutomationId As String
Public FrameworkId As String
Public Property TopLeft As RectangleInfo
Public Property TopRight As RectangleInfo
Public Property BottomLeft As RectangleInfo
Public Property BottomRight As RectangleInfo
Public Automation As ClassAutomation
Private WithEvents Watcher As ClipboardWatcher = ClipboardWatcher.Singleton
Private Window As Window
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
Dim oResult As WindowInfo = GetFocusedControl(Handle)
Dim newoResult As IntPtr = FocusedControlinActiveWindow(Handle)
Private Sub frmControlCapture_Load(sender As Object, e As EventArgs) Handles Me.Load
Window = New Window(LogConfig)
If oResult IsNot Nothing Then
txtPID.Text = oResult.ClassName
txtName.Text = oResult.ProcessName
txtControlName.Text = oResult.ControlName
txtAutomationId.Text = Automation.AutomationId
txtFrameworkId.Text = Automation.FrameworkId
Console.WriteLine($"Automation.AutomationId: {Automation.AutomationId}")
FrameworkId = Automation.FrameworkId
ControlName = oResult.ControlName
Console.WriteLine($"oResult.ControlName: {oResult.ControlName}")
txtNewFocusControlHandle.Text = newoResult.ToString
AutomationId = newoResult.ToString
Console.WriteLine($"newoResult: {newoResult.ToString}")
ProcessName = oResult.ProcessName
End If
AddHandler Watcher.Changed, AddressOf Watcher_Changed
End Sub
Private Sub frmControlCapture_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Automation = New ClassAutomation(LogConfig)
End Sub
Private Sub Watcher_Changed(sender As Object, e As EventArgs)
For Each oAnchor As Anchor In [Enum].GetValues(GetType(Anchor))
Dim oRect = Window.GetFocusedControlLocation(Handle, oAnchor)
Private Sub frmControlCapture_FormClosing(sender As Object, e As FormClosingEventArgs) Handles Me.FormClosing
Timer1.Stop()
Automation.RemoveHandler()
End Sub
Select Case oAnchor
Case Window.Anchor.TopLeft
If oRect IsNot Nothing Then
TopLeft = oRect
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
If chkAutomationId.Checked = False Then
AutomationId = String.Empty
End If
txtTLLeft.Text = oRect.Left
txtTLRight.Text = oRect.Right
txtTLTop.Text = oRect.Top
txtTLBottom.Text = oRect.Bottom
End If
If chkControlName.Checked = False Then
ControlName = String.Empty
End If
Case Window.Anchor.TopRight
If oRect IsNot Nothing Then
TopRight = oRect
If chkAutomationId.Checked = False And chkControlName.Checked = False Then
MsgBox("Es muss entweder die AutomationId oder der Feldname ausgewählt sein!", MsgBoxStyle.Exclamation, Text)
DialogResult = DialogResult.None
End If
Timer1.Stop()
End Sub
txtTRLeft.Text = oRect.Left
txtTRRight.Text = oRect.Right
txtTRTop.Text = oRect.Top
txtTRBottom.Text = oRect.Bottom
End If
Private Sub chkControlName_CheckedChanged(sender As Object, e As EventArgs) Handles chkControlName.CheckedChanged
If chkControlName.Checked Then
chkAutomationId.Checked = False
End If
End Sub
Case Window.Anchor.BottomLeft
If oRect IsNot Nothing Then
BottomLeft = oRect
Private Sub chkAutomationId_CheckedChanged(sender As Object, e As EventArgs) Handles chkAutomationId.CheckedChanged
If chkAutomationId.Checked Then
chkControlName.Checked = False
End If
End Sub
txtBLLeft.Text = oRect.Left
txtBLRight.Text = oRect.Right
txtBLTop.Text = oRect.Top
txtBLBottom.Text = oRect.Bottom
End If
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
Timer1.Stop()
Case Window.Anchor.BottomRight
If oRect IsNot Nothing Then
BottomRight = oRect
txtBRLeft.Text = oRect.Left
txtBRRight.Text = oRect.Right
txtBRTop.Text = oRect.Top
txtBRBottom.Text = oRect.Bottom
End If
End Select
Next
End Sub
End Class