add debugging to profilefilter & window class
This commit is contained in:
parent
a767b9bcc0
commit
6b31549a30
@ -36,15 +36,22 @@ Public Class ProfileFilter
|
|||||||
|
|
||||||
Public Sub New(LogConfig As LogConfig, ProfileDatatable As DataTable, ProcessTable As DataTable, WindowDatatable As DataTable, ControlDatatable As DataTable, TreeView As TreeView)
|
Public Sub New(LogConfig As LogConfig, ProfileDatatable As DataTable, ProcessTable As DataTable, WindowDatatable As DataTable, ControlDatatable As DataTable, TreeView As TreeView)
|
||||||
Try
|
Try
|
||||||
_ProfileMatch = New ProfileMatch(LogConfig)
|
_LogConfig = LogConfig
|
||||||
|
_Logger = LogConfig.GetLogger()
|
||||||
|
|
||||||
|
_Logger.Debug("Initializing Profile Filter")
|
||||||
|
_Logger.Debug("Initializing Profile Data")
|
||||||
_ProfileTable = ProfileDatatable
|
_ProfileTable = ProfileDatatable
|
||||||
_ProcessTable = ProcessTable
|
_ProcessTable = ProcessTable
|
||||||
_WindowTable = WindowDatatable
|
_WindowTable = WindowDatatable
|
||||||
_ControlTable = ControlDatatable
|
_ControlTable = ControlDatatable
|
||||||
_Profiles = TransformProfiles()
|
|
||||||
|
_Logger.Debug("Initializing Profile Debugging")
|
||||||
_TreeView = TreeView
|
_TreeView = TreeView
|
||||||
_LogConfig = LogConfig
|
_ProfileMatch = New ProfileMatch(LogConfig)
|
||||||
_Logger = LogConfig.GetLogger()
|
|
||||||
|
_Logger.Debug("Transforming Profiles")
|
||||||
|
_Profiles = TransformProfiles()
|
||||||
Catch ex As Exception
|
Catch ex As Exception
|
||||||
_Logger.Error(ex)
|
_Logger.Error(ex)
|
||||||
Throw ex
|
Throw ex
|
||||||
@ -209,19 +216,19 @@ Public Class ProfileFilter
|
|||||||
|
|
||||||
For Each oItem As KeyValuePair(Of String, Window.RectangleInfo) In oControlBounds
|
For Each oItem As KeyValuePair(Of String, Window.RectangleInfo) In oControlBounds
|
||||||
Select Case oItem.Key
|
Select Case oItem.Key
|
||||||
Case "TOPLEFT"
|
Case "TopLeft"
|
||||||
If oControl.TopLeft.Top = oItem.Value.Top And oControl.TopLeft.Left = oItem.Value.Left Then
|
If oControl.TopLeft.Top = oItem.Value.Top And oControl.TopLeft.Left = oItem.Value.Left Then
|
||||||
oFound = True
|
oFound = True
|
||||||
End If
|
End If
|
||||||
Case "TOPRIGHT"
|
Case "TopRight"
|
||||||
If oControl.TopRight.Top = oItem.Value.Top And oControl.TopLeft.Right = oItem.Value.Right Then
|
If oControl.TopRight.Top = oItem.Value.Top And oControl.TopLeft.Right = oItem.Value.Right Then
|
||||||
oFound = True
|
oFound = True
|
||||||
End If
|
End If
|
||||||
Case "BOTTOMLEFT"
|
Case "BottomLeft"
|
||||||
If oControl.BottomLeft.Bottom = oItem.Value.Bottom And oControl.TopLeft.Left = oItem.Value.Left Then
|
If oControl.BottomLeft.Bottom = oItem.Value.Bottom And oControl.TopLeft.Left = oItem.Value.Left Then
|
||||||
oFound = True
|
oFound = True
|
||||||
End If
|
End If
|
||||||
Case "BOTTOMRIGHT"
|
Case "BottomRight"
|
||||||
If oControl.BottomRight.Bottom = oItem.Value.Bottom And oControl.TopLeft.Right = oItem.Value.Right Then
|
If oControl.BottomRight.Bottom = oItem.Value.Bottom And oControl.TopLeft.Right = oItem.Value.Right Then
|
||||||
oFound = True
|
oFound = True
|
||||||
End If
|
End If
|
||||||
@ -385,6 +392,7 @@ Public Class ProfileFilter
|
|||||||
End Function
|
End Function
|
||||||
|
|
||||||
Private Function TransformProfiles() As List(Of ProfileData)
|
Private Function TransformProfiles() As List(Of ProfileData)
|
||||||
|
Try
|
||||||
Dim oList As New List(Of ProfileData)
|
Dim oList As New List(Of ProfileData)
|
||||||
|
|
||||||
For Each oRow As DataRow In _ProfileTable.Rows
|
For Each oRow As DataRow In _ProfileTable.Rows
|
||||||
@ -410,9 +418,14 @@ Public Class ProfileFilter
|
|||||||
ToList()
|
ToList()
|
||||||
|
|
||||||
Return oList
|
Return oList
|
||||||
|
Catch ex As Exception
|
||||||
|
_Logger.Error(ex)
|
||||||
|
Throw ex
|
||||||
|
End Try
|
||||||
End Function
|
End Function
|
||||||
|
|
||||||
Private Function TransformControls(ProfileId As Integer, ControlDatatable As DataTable) As List(Of ControlData)
|
Private Function TransformControls(ProfileId As Integer, ControlDatatable As DataTable) As List(Of ControlData)
|
||||||
|
Try
|
||||||
Dim oControlList As New List(Of ControlData)
|
Dim oControlList As New List(Of ControlData)
|
||||||
|
|
||||||
For Each oRow As DataRow In ControlDatatable.Rows
|
For Each oRow As DataRow In ControlDatatable.Rows
|
||||||
@ -450,8 +463,13 @@ Public Class ProfileFilter
|
|||||||
Next
|
Next
|
||||||
|
|
||||||
Return oControlList
|
Return oControlList
|
||||||
|
Catch ex As Exception
|
||||||
|
_Logger.Error(ex)
|
||||||
|
Throw ex
|
||||||
|
End Try
|
||||||
End Function
|
End Function
|
||||||
Private Function TransformProcesses(ProfileId As Integer, ProcessDatatable As DataTable) As List(Of ProcessData)
|
Private Function TransformProcesses(ProfileId As Integer, ProcessDatatable As DataTable) As List(Of ProcessData)
|
||||||
|
Try
|
||||||
Dim oProcessList As New List(Of ProcessData)
|
Dim oProcessList As New List(Of ProcessData)
|
||||||
|
|
||||||
For Each oRow As DataRow In ProcessDatatable.Rows
|
For Each oRow As DataRow In ProcessDatatable.Rows
|
||||||
@ -469,8 +487,13 @@ Public Class ProfileFilter
|
|||||||
ToList()
|
ToList()
|
||||||
|
|
||||||
Return oProcessList
|
Return oProcessList
|
||||||
|
Catch ex As Exception
|
||||||
|
_Logger.Error(ex)
|
||||||
|
Throw ex
|
||||||
|
End Try
|
||||||
End Function
|
End Function
|
||||||
Private Function TransformWindows(ProfileId As Integer, WindowDatatable As DataTable) As List(Of WindowData)
|
Private Function TransformWindows(ProfileId As Integer, WindowDatatable As DataTable) As List(Of WindowData)
|
||||||
|
Try
|
||||||
Dim oWindowList As New List(Of WindowData)
|
Dim oWindowList As New List(Of WindowData)
|
||||||
|
|
||||||
For Each oRow As DataRow In WindowDatatable.Rows
|
For Each oRow As DataRow In WindowDatatable.Rows
|
||||||
@ -486,5 +509,9 @@ Public Class ProfileFilter
|
|||||||
Next
|
Next
|
||||||
|
|
||||||
Return oWindowList
|
Return oWindowList
|
||||||
|
Catch ex As Exception
|
||||||
|
_Logger.Error(ex)
|
||||||
|
Throw ex
|
||||||
|
End Try
|
||||||
End Function
|
End Function
|
||||||
End Class
|
End Class
|
||||||
|
|||||||
@ -127,6 +127,10 @@ Public Class NativeMethods
|
|||||||
Public Top As Integer
|
Public Top As Integer
|
||||||
Public Right As Integer
|
Public Right As Integer
|
||||||
Public Bottom As Integer
|
Public Bottom As Integer
|
||||||
|
|
||||||
|
Public Overrides Function ToString() As String
|
||||||
|
Return String.Format("Top: {0}, Bottom: {1}, Left: {2}, Right: {3}", Top, Bottom, Left, Right)
|
||||||
|
End Function
|
||||||
End Structure
|
End Structure
|
||||||
|
|
||||||
<System.Runtime.InteropServices.StructLayout(Runtime.InteropServices.LayoutKind.Sequential)>
|
<System.Runtime.InteropServices.StructLayout(Runtime.InteropServices.LayoutKind.Sequential)>
|
||||||
|
|||||||
@ -31,7 +31,7 @@ Public Class Window
|
|||||||
Public ClassName As String = ""
|
Public ClassName As String = ""
|
||||||
Public ProcessId As Integer = 0
|
Public ProcessId As Integer = 0
|
||||||
Public ControlName As String = ""
|
Public ControlName As String = ""
|
||||||
Public hWnd As IntPtr
|
Public hWnd As IntPtr = IntPtr.Zero
|
||||||
End Class
|
End Class
|
||||||
|
|
||||||
Public Sub New(LogConfig As LogConfig)
|
Public Sub New(LogConfig As LogConfig)
|
||||||
@ -42,23 +42,30 @@ Public Class Window
|
|||||||
''' Returns Information about the currently focused window
|
''' Returns Information about the currently focused window
|
||||||
''' </summary>
|
''' </summary>
|
||||||
Public Function GetWindowInfo() As WindowInfo
|
Public Function GetWindowInfo() As WindowInfo
|
||||||
|
Try
|
||||||
Dim hWnd As IntPtr = NativeMethods.GetForegroundWindow()
|
Dim hWnd As IntPtr = NativeMethods.GetForegroundWindow()
|
||||||
If hWnd = IntPtr.Zero Then
|
|
||||||
Return Nothing
|
|
||||||
End If
|
|
||||||
|
|
||||||
Return GetWindowInfo(hWnd)
|
Return GetWindowInfo(hWnd)
|
||||||
|
Catch ex As Exception
|
||||||
|
_Logger.Debug("Error in GetWindowInfo/0")
|
||||||
|
_Logger.Error(ex)
|
||||||
|
Throw ex
|
||||||
|
End Try
|
||||||
End Function
|
End Function
|
||||||
|
|
||||||
''' <summary>
|
''' <summary>
|
||||||
''' Returns Information about the Window with `hWnd`
|
''' Returns Information about the Window with `hWnd`
|
||||||
''' </summary>
|
''' </summary>
|
||||||
Public Function GetWindowInfo(ByVal hWnd As IntPtr) As WindowInfo
|
Public Function GetWindowInfo(ByVal hWnd As IntPtr) As WindowInfo
|
||||||
|
Try
|
||||||
|
_Logger.Debug("Getting Window Info")
|
||||||
|
|
||||||
Dim oPID As Integer = 0
|
Dim oPID As Integer = 0
|
||||||
Dim oTitleLength As Int32 = NativeMethods.GetWindowTextLength(hWnd)
|
Dim oTitleLength As Int32 = NativeMethods.GetWindowTextLength(hWnd)
|
||||||
Dim oWindowTitle As String = StrDup(oTitleLength + 1, "*")
|
Dim oWindowTitle As String = StrDup(oTitleLength + 1, "*")
|
||||||
Dim oClassBuilder As New StringBuilder(64)
|
Dim oClassBuilder As New StringBuilder(64)
|
||||||
|
|
||||||
|
_Logger.Debug("Getting Window Text and PID")
|
||||||
|
|
||||||
NativeMethods.GetWindowText(hWnd, oWindowTitle, oTitleLength + 1)
|
NativeMethods.GetWindowText(hWnd, oWindowTitle, oTitleLength + 1)
|
||||||
NativeMethods.GetWindowThreadProcessId(hWnd, oPID)
|
NativeMethods.GetWindowThreadProcessId(hWnd, oPID)
|
||||||
|
|
||||||
@ -72,6 +79,8 @@ Public Class Window
|
|||||||
Return Nothing
|
Return Nothing
|
||||||
End If
|
End If
|
||||||
|
|
||||||
|
_Logger.Debug("Getting Class Name")
|
||||||
|
|
||||||
NativeMethods.GetClassName(hWnd, oClassBuilder, 64)
|
NativeMethods.GetClassName(hWnd, oClassBuilder, 64)
|
||||||
|
|
||||||
Return New WindowInfo With {
|
Return New WindowInfo With {
|
||||||
@ -81,6 +90,11 @@ Public Class Window
|
|||||||
.ProcessName = oProcess.ProcessName,
|
.ProcessName = oProcess.ProcessName,
|
||||||
.WindowTitle = oWindowTitle.Replace(vbNullChar, String.Empty)
|
.WindowTitle = oWindowTitle.Replace(vbNullChar, String.Empty)
|
||||||
}
|
}
|
||||||
|
Catch ex As Exception
|
||||||
|
_Logger.Debug("Error in GetWindowInfo/1")
|
||||||
|
_Logger.Error(ex)
|
||||||
|
Throw ex
|
||||||
|
End Try
|
||||||
End Function
|
End Function
|
||||||
|
|
||||||
''' <summary>
|
''' <summary>
|
||||||
@ -92,6 +106,7 @@ Public Class Window
|
|||||||
Dim oWindow = GetWindowInfo()
|
Dim oWindow = GetWindowInfo()
|
||||||
|
|
||||||
If oWindow Is Nothing Then
|
If oWindow Is Nothing Then
|
||||||
|
_Logger.Debug("Could not get Window Info!")
|
||||||
Return Nothing
|
Return Nothing
|
||||||
End If
|
End If
|
||||||
|
|
||||||
@ -104,12 +119,14 @@ Public Class Window
|
|||||||
Dim oControl As WindowInfo = GetWindowInfo(oControlhWnd)
|
Dim oControl As WindowInfo = GetWindowInfo(oControlhWnd)
|
||||||
|
|
||||||
If oControl Is Nothing Then
|
If oControl Is Nothing Then
|
||||||
|
_Logger.Debug("Could not get Control Info!")
|
||||||
Return Nothing
|
Return Nothing
|
||||||
End If
|
End If
|
||||||
|
|
||||||
Dim oName = Utils.GetWinFormsId(oControlhWnd)
|
Dim oName = Utils.GetWinFormsId(oControlhWnd)
|
||||||
oControl.ControlName = oName
|
oControl.ControlName = oName
|
||||||
|
|
||||||
|
|
||||||
Return oControl
|
Return oControl
|
||||||
Catch ex As Exception
|
Catch ex As Exception
|
||||||
_Logger.Error(ex)
|
_Logger.Error(ex)
|
||||||
@ -120,10 +137,10 @@ Public Class Window
|
|||||||
|
|
||||||
Return Nothing
|
Return Nothing
|
||||||
Catch ex As Exception
|
Catch ex As Exception
|
||||||
|
_Logger.Debug("Error in GetFocusedControl/1")
|
||||||
_Logger.Error(ex)
|
_Logger.Error(ex)
|
||||||
Return Nothing
|
Throw ex
|
||||||
End Try
|
End Try
|
||||||
|
|
||||||
End Function
|
End Function
|
||||||
|
|
||||||
''' <summary>
|
''' <summary>
|
||||||
@ -134,11 +151,15 @@ Public Class Window
|
|||||||
Dim oControlRect As New NativeMethods.RectangleAPI
|
Dim oControlRect As New NativeMethods.RectangleAPI
|
||||||
Dim oResult As New RectangleInfo
|
Dim oResult As New RectangleInfo
|
||||||
|
|
||||||
|
_Logger.Debug("Getting Control Location")
|
||||||
|
|
||||||
Try
|
Try
|
||||||
|
_Logger.Debug("Trying to get Window Rectangle")
|
||||||
If NativeMethods.GetWindowRect(New HandleRef(Me, WindowHandle), oWindowRect) = False Then
|
If NativeMethods.GetWindowRect(New HandleRef(Me, WindowHandle), oWindowRect) = False Then
|
||||||
Return Nothing
|
Return Nothing
|
||||||
End If
|
End If
|
||||||
|
|
||||||
|
_Logger.Debug("Trying to get Control Rectangle")
|
||||||
If NativeMethods.GetWindowRect(New HandleRef(Me, ControlHandle), oControlRect) = False Then
|
If NativeMethods.GetWindowRect(New HandleRef(Me, ControlHandle), oControlRect) = False Then
|
||||||
Return Nothing
|
Return Nothing
|
||||||
End If
|
End If
|
||||||
@ -148,6 +169,8 @@ Public Class Window
|
|||||||
' Calculate Coordinates relative to parent window
|
' Calculate Coordinates relative to parent window
|
||||||
oRect = GetRelativeRectangle(oControlRect, oWindowRect, Anchor)
|
oRect = GetRelativeRectangle(oControlRect, oWindowRect, Anchor)
|
||||||
|
|
||||||
|
_Logger.Debug("Control Location for Anchor {0}: {1}", Anchor, oRect)
|
||||||
|
|
||||||
oResult.Left = oRect.Left
|
oResult.Left = oRect.Left
|
||||||
oResult.Right = oRect.Right
|
oResult.Right = oRect.Right
|
||||||
oResult.Top = oRect.Top
|
oResult.Top = oRect.Top
|
||||||
@ -155,8 +178,49 @@ Public Class Window
|
|||||||
|
|
||||||
Return oResult
|
Return oResult
|
||||||
Catch ex As Exception
|
Catch ex As Exception
|
||||||
|
_Logger.Debug("Error in GetControlLocation/3")
|
||||||
_Logger.Error(ex)
|
_Logger.Error(ex)
|
||||||
|
Throw ex
|
||||||
|
End Try
|
||||||
|
End Function
|
||||||
|
|
||||||
|
Public Function GetControlLocations(ControlHandle As IntPtr, WindowHandle As IntPtr) As Dictionary(Of String, RectangleInfo)
|
||||||
|
Dim oWindowRect As New NativeMethods.RectangleAPI
|
||||||
|
Dim oControlRect As New NativeMethods.RectangleAPI
|
||||||
|
Dim oResults As New Dictionary(Of String, RectangleInfo)
|
||||||
|
|
||||||
|
_Logger.Debug("Getting Control Locations")
|
||||||
|
|
||||||
|
Try
|
||||||
|
_Logger.Debug("Trying to get Window Rectangle")
|
||||||
|
If NativeMethods.GetWindowRect(New HandleRef(Me, WindowHandle), oWindowRect) = False Then
|
||||||
Return Nothing
|
Return Nothing
|
||||||
|
End If
|
||||||
|
|
||||||
|
_Logger.Debug("Trying to get Control Rectangle")
|
||||||
|
If NativeMethods.GetWindowRect(New HandleRef(Me, ControlHandle), oControlRect) = False Then
|
||||||
|
Return Nothing
|
||||||
|
End If
|
||||||
|
|
||||||
|
|
||||||
|
For Each oAnchor As Anchor In [Enum].GetValues(GetType(Anchor))
|
||||||
|
Dim oRect As NativeMethods.RectangleAPI = GetRelativeRectangle(oControlRect, oWindowRect, oAnchor)
|
||||||
|
|
||||||
|
_Logger.Debug("Control Location for Anchor {0}: {1}", oAnchor, oRect)
|
||||||
|
|
||||||
|
oResults.Add(oAnchor.ToString, New RectangleInfo() With {
|
||||||
|
.Left = oRect.Left,
|
||||||
|
.Right = oRect.Right,
|
||||||
|
.Top = oRect.Top,
|
||||||
|
.Bottom = oRect.Bottom
|
||||||
|
})
|
||||||
|
Next
|
||||||
|
|
||||||
|
Return oResults
|
||||||
|
Catch ex As Exception
|
||||||
|
_Logger.Debug("Error in GetControlLocations/2")
|
||||||
|
_Logger.Error(ex)
|
||||||
|
Throw ex
|
||||||
End Try
|
End Try
|
||||||
End Function
|
End Function
|
||||||
|
|
||||||
@ -164,44 +228,55 @@ Public Class Window
|
|||||||
''' Returns Bounds of the focused control. Relative to current form and `Anchor` value.
|
''' Returns Bounds of the focused control. Relative to current form and `Anchor` value.
|
||||||
''' </summary>
|
''' </summary>
|
||||||
Public Function GetFocusedControlLocation(WindowHandle As IntPtr, Anchor As Anchor) 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 WindowInfo
|
Dim oForegroundWindow As WindowInfo
|
||||||
Dim oFocusedControl As WindowInfo
|
Dim oFocusedControl As WindowInfo
|
||||||
Dim oResult As New RectangleInfo
|
|
||||||
|
|
||||||
Try
|
Try
|
||||||
oForegroundWindow = GetWindowInfo()
|
oForegroundWindow = GetWindowInfo()
|
||||||
oFocusedControl = GetFocusedControl(WindowHandle)
|
oFocusedControl = GetFocusedControl(WindowHandle)
|
||||||
|
|
||||||
|
If IsNothing(oForegroundWindow) Then
|
||||||
|
_Logger.Debug("Foreground Window is nothing!")
|
||||||
|
End If
|
||||||
|
|
||||||
|
If IsNothing(oFocusedControl) Then
|
||||||
|
_Logger.Debug("Focused Contol is nothing!")
|
||||||
|
End If
|
||||||
|
|
||||||
|
_Logger.Debug("Control Handle: {0}", oFocusedControl.hWnd)
|
||||||
|
_Logger.Debug("Window Handle: {0}", oForegroundWindow.hWnd)
|
||||||
|
|
||||||
Return GetControlLocation(oFocusedControl.hWnd, oForegroundWindow.hWnd, Anchor)
|
Return GetControlLocation(oFocusedControl.hWnd, oForegroundWindow.hWnd, Anchor)
|
||||||
Catch ex As Exception
|
Catch ex As Exception
|
||||||
|
_Logger.Debug("Error in GetFocusedControlLocation/2")
|
||||||
_Logger.Error(ex)
|
_Logger.Error(ex)
|
||||||
Return Nothing
|
Throw ex
|
||||||
End Try
|
End Try
|
||||||
End Function
|
End Function
|
||||||
|
|
||||||
Public Function GetFocusedControlLocation(WindowHandle As IntPtr) As Dictionary(Of String, RectangleInfo)
|
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 oForegroundWindow As WindowInfo
|
||||||
Dim oFocusedControl As WindowInfo
|
Dim oFocusedControl As WindowInfo
|
||||||
Dim oResult As New RectangleInfo
|
|
||||||
|
|
||||||
Try
|
Try
|
||||||
oForegroundWindow = GetWindowInfo()
|
oForegroundWindow = GetWindowInfo()
|
||||||
oFocusedControl = GetFocusedControl(WindowHandle)
|
oFocusedControl = GetFocusedControl(WindowHandle)
|
||||||
|
|
||||||
Dim oDict As New Dictionary(Of String, RectangleInfo)
|
If oForegroundWindow Is Nothing Then
|
||||||
|
_Logger.Warn("Foreground Window is Nothing!")
|
||||||
|
End If
|
||||||
|
|
||||||
For Each oAnchor As Anchor In [Enum].GetValues(GetType(Anchor))
|
If oFocusedControl Is Nothing Then
|
||||||
oDict.Add(oAnchor.ToString.ToUpper, GetControlLocation(oFocusedControl.hWnd, oForegroundWindow.hWnd, oAnchor))
|
_Logger.Warn("Focused Control is Nothing!")
|
||||||
Next
|
End If
|
||||||
|
|
||||||
|
Dim oDict As Dictionary(Of String, RectangleInfo) = GetControlLocations(oFocusedControl.hWnd, oForegroundWindow.hWnd)
|
||||||
|
|
||||||
Return oDict
|
Return oDict
|
||||||
Catch ex As Exception
|
Catch ex As Exception
|
||||||
|
_Logger.Debug("Error in GetFocusedControlLocation/1")
|
||||||
_Logger.Error(ex)
|
_Logger.Error(ex)
|
||||||
Return Nothing
|
Throw ex
|
||||||
End Try
|
End Try
|
||||||
End Function
|
End Function
|
||||||
|
|
||||||
@ -226,12 +301,14 @@ Public Class Window
|
|||||||
|
|
||||||
Return GetControlLocation(oControlUnderCursor, oForegroundWindow, Anchor)
|
Return GetControlLocation(oControlUnderCursor, oForegroundWindow, Anchor)
|
||||||
Catch ex As Exception
|
Catch ex As Exception
|
||||||
|
_Logger.Debug("Error in GetHoveredControlLocation/1")
|
||||||
_Logger.Error(ex)
|
_Logger.Error(ex)
|
||||||
Return Nothing
|
Throw ex
|
||||||
End Try
|
End Try
|
||||||
End Function
|
End Function
|
||||||
|
|
||||||
Public Function GetWindowRect(Handle As IntPtr)
|
Public Function GetWindowRect(Handle As IntPtr)
|
||||||
|
Try
|
||||||
Dim oWindowRect As New NativeMethods.RectangleAPI
|
Dim oWindowRect As New NativeMethods.RectangleAPI
|
||||||
|
|
||||||
If NativeMethods.GetWindowRect(New HandleRef(Me, Handle), oWindowRect) = False Then
|
If NativeMethods.GetWindowRect(New HandleRef(Me, Handle), oWindowRect) = False Then
|
||||||
@ -239,12 +316,20 @@ Public Class Window
|
|||||||
End If
|
End If
|
||||||
|
|
||||||
Return oWindowRect
|
Return oWindowRect
|
||||||
|
Catch ex As Exception
|
||||||
|
_Logger.Debug("Error in GetWindowRect/1")
|
||||||
|
_Logger.Error(ex)
|
||||||
|
Throw ex
|
||||||
|
End Try
|
||||||
End Function
|
End Function
|
||||||
|
|
||||||
Private Function GetRelativeRectangle(ControlRect As NativeMethods.RectangleAPI, WindowRect As NativeMethods.RectangleAPI, Anchor As Anchor) As NativeMethods.RectangleAPI
|
Private Function GetRelativeRectangle(ControlRect As NativeMethods.RectangleAPI, WindowRect As NativeMethods.RectangleAPI, Anchor As Anchor) As NativeMethods.RectangleAPI
|
||||||
|
Try
|
||||||
Dim oScreenRect As Rectangle = Screen.PrimaryScreen.Bounds
|
Dim oScreenRect As Rectangle = Screen.PrimaryScreen.Bounds
|
||||||
Dim oLeft, oBottom, oTop, oRight As Integer
|
Dim oLeft, oBottom, oTop, oRight As Integer
|
||||||
|
|
||||||
|
_Logger.Debug("Calculating Rectangle for Anchor {0}", Anchor.ToString)
|
||||||
|
|
||||||
Select Case Anchor
|
Select Case Anchor
|
||||||
Case Anchor.TopLeft
|
Case Anchor.TopLeft
|
||||||
oLeft = ControlRect.Left - WindowRect.Left
|
oLeft = ControlRect.Left - WindowRect.Left
|
||||||
@ -260,15 +345,23 @@ Public Class Window
|
|||||||
oBottom = ControlRect.Bottom - WindowRect.Bottom
|
oBottom = ControlRect.Bottom - WindowRect.Bottom
|
||||||
End Select
|
End Select
|
||||||
|
|
||||||
|
_Logger.Debug("Done Calculating Rectangle for Anchor {0}", Anchor.ToString)
|
||||||
|
|
||||||
Return New NativeMethods.RectangleAPI() With {
|
Return New NativeMethods.RectangleAPI() With {
|
||||||
.Top = oTop,
|
.Top = oTop,
|
||||||
.Bottom = oBottom,
|
.Bottom = oBottom,
|
||||||
.Left = oLeft,
|
.Left = oLeft,
|
||||||
.Right = oRight
|
.Right = oRight
|
||||||
}
|
}
|
||||||
|
Catch ex As Exception
|
||||||
|
_Logger.Debug("Error in GetRelativeRectangle/3")
|
||||||
|
_Logger.Error(ex)
|
||||||
|
Throw ex
|
||||||
|
End Try
|
||||||
End Function
|
End Function
|
||||||
|
|
||||||
Private Function GetRect(Rect As NativeMethods.RectangleAPI, ParentRect As NativeMethods.RectangleAPI) As Rectangle
|
Private Function GetRect(Rect As NativeMethods.RectangleAPI, ParentRect As NativeMethods.RectangleAPI) As Rectangle
|
||||||
|
Try
|
||||||
Dim oX, oY, oWidth, oHeight As Integer
|
Dim oX, oY, oWidth, oHeight As Integer
|
||||||
|
|
||||||
oWidth = Rect.Right - Rect.Left
|
oWidth = Rect.Right - Rect.Left
|
||||||
@ -277,9 +370,15 @@ Public Class Window
|
|||||||
oY = Rect.Top - ParentRect.Top
|
oY = Rect.Top - ParentRect.Top
|
||||||
|
|
||||||
Return New Rectangle(oX, oY, oWidth, oHeight)
|
Return New Rectangle(oX, oY, oWidth, oHeight)
|
||||||
|
Catch ex As Exception
|
||||||
|
_Logger.Debug("Error in GetRect/2")
|
||||||
|
_Logger.Error(ex)
|
||||||
|
Throw ex
|
||||||
|
End Try
|
||||||
End Function
|
End Function
|
||||||
|
|
||||||
Private Function GetRect(Rect As NativeMethods.RectangleAPI, ParentRect As Rectangle) As Rectangle
|
Private Function GetRect(Rect As NativeMethods.RectangleAPI, ParentRect As Rectangle) As Rectangle
|
||||||
|
Try
|
||||||
Dim oX, oY, oWidth, oHeight As Integer
|
Dim oX, oY, oWidth, oHeight As Integer
|
||||||
|
|
||||||
oWidth = Rect.Right - Rect.Left
|
oWidth = Rect.Right - Rect.Left
|
||||||
@ -288,5 +387,10 @@ Public Class Window
|
|||||||
oY = Rect.Top - ParentRect.Y
|
oY = Rect.Top - ParentRect.Y
|
||||||
|
|
||||||
Return New Rectangle(oX, oY, oWidth, oHeight)
|
Return New Rectangle(oX, oY, oWidth, oHeight)
|
||||||
|
Catch ex As Exception
|
||||||
|
_Logger.Debug("Error in GetRect/2")
|
||||||
|
_Logger.Error(ex)
|
||||||
|
Throw ex
|
||||||
|
End Try
|
||||||
End Function
|
End Function
|
||||||
End Class
|
End Class
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user