This commit is contained in:
Jonathan Jenne
2019-09-19 16:21:13 +02:00
parent 0ec5829275
commit f3a3812993
7 changed files with 85 additions and 11 deletions

View File

@@ -163,18 +163,42 @@ Public Class Window
''' <summary>
''' Returns Bounds of the focused control. Relative to current form and `Anchor` value.
''' </summary>
Public Function GetFocusedControlLocation(Optional Anchor As Anchor = Anchor.TopLeft) As RectangleInfo
Public Function GetFocusedControlLocation(WindowHandle As IntPtr, Anchor As Anchor) As RectangleInfo
Dim oWindowRect As New NativeMethods.RectangleAPI
Dim oControlRect As New NativeMethods.RectangleAPI
Dim oForegroundWindow As IntPtr
Dim oFocusedControl As IntPtr
Dim oForegroundWindow As WindowInfo
Dim oFocusedControl As WindowInfo
Dim oResult As New RectangleInfo
Try
oForegroundWindow = NativeMethods.GetForegroundWindow()
oFocusedControl = NativeMethods.GetFocus()
oForegroundWindow = GetWindowInfo()
oFocusedControl = GetFocusedControl(WindowHandle)
Return GetControlLocation(oFocusedControl, oForegroundWindow, Anchor)
Return GetControlLocation(oFocusedControl.hWnd, oForegroundWindow.hWnd, Anchor)
Catch ex As Exception
_Logger.Error(ex)
Return Nothing
End Try
End Function
Public Function GetFocusedControlLocation(WindowHandle As IntPtr) As Dictionary(Of String, RectangleInfo)
Dim oWindowRect As New NativeMethods.RectangleAPI
Dim oControlRect As New NativeMethods.RectangleAPI
Dim oForegroundWindow As WindowInfo
Dim oFocusedControl As WindowInfo
Dim oResult As New RectangleInfo
Try
oForegroundWindow = GetWindowInfo()
oFocusedControl = GetFocusedControl(WindowHandle)
Dim oDict As New Dictionary(Of String, RectangleInfo)
For Each oAnchor As Anchor In [Enum].GetValues(GetType(Anchor))
oDict.Add(oAnchor.ToString.ToUpper, GetControlLocation(oFocusedControl.hWnd, oForegroundWindow.hWnd, oAnchor))
Next
Return oDict
Catch ex As Exception
_Logger.Error(ex)
Return Nothing