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,106 +392,126 @@ Public Class ProfileFilter
|
|||||||
End Function
|
End Function
|
||||||
|
|
||||||
Private Function TransformProfiles() As List(Of ProfileData)
|
Private Function TransformProfiles() As List(Of ProfileData)
|
||||||
Dim oList As New List(Of ProfileData)
|
Try
|
||||||
|
Dim oList As New List(Of ProfileData)
|
||||||
|
|
||||||
For Each oRow As DataRow In _ProfileTable.Rows
|
For Each oRow As DataRow In _ProfileTable.Rows
|
||||||
Dim oProfileId = oRow.Item("GUID")
|
Dim oProfileId = oRow.Item("GUID")
|
||||||
Dim oProcessList As List(Of ProcessData) = TransformProcesses(oProfileId, _ProcessTable)
|
Dim oProcessList As List(Of ProcessData) = TransformProcesses(oProfileId, _ProcessTable)
|
||||||
Dim oWindowList As List(Of WindowData) = TransformWindows(oProfileId, _WindowTable)
|
Dim oWindowList As List(Of WindowData) = TransformWindows(oProfileId, _WindowTable)
|
||||||
Dim oControlList As List(Of ControlData) = TransformControls(oProfileId, _ControlTable)
|
Dim oControlList As List(Of ControlData) = TransformControls(oProfileId, _ControlTable)
|
||||||
|
|
||||||
oList.Add(New ProfileData() With {
|
oList.Add(New ProfileData() With {
|
||||||
.Guid = oRow.Item("GUID"),
|
.Guid = oRow.Item("GUID"),
|
||||||
.Regex = oRow.Item("REGEX_EXPRESSION"),
|
.Regex = oRow.Item("REGEX_EXPRESSION"),
|
||||||
.Name = NotNull(oRow.Item("NAME"), String.Empty),
|
.Name = NotNull(oRow.Item("NAME"), String.Empty),
|
||||||
.Comment = NotNull(oRow.Item("COMMENT"), String.Empty),
|
.Comment = NotNull(oRow.Item("COMMENT"), String.Empty),
|
||||||
.ProfileType = NotNull(oRow.Item("PROFILE_TYPE"), String.Empty),
|
.ProfileType = NotNull(oRow.Item("PROFILE_TYPE"), String.Empty),
|
||||||
.Processes = oProcessList,
|
.Processes = oProcessList,
|
||||||
.Windows = oWindowList,
|
.Windows = oWindowList,
|
||||||
.Controls = oControlList
|
.Controls = oControlList
|
||||||
})
|
})
|
||||||
Next
|
Next
|
||||||
|
|
||||||
oList = oList.
|
oList = oList.
|
||||||
Distinct().
|
Distinct().
|
||||||
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)
|
||||||
Dim oControlList As New List(Of ControlData)
|
Try
|
||||||
|
Dim oControlList As New List(Of ControlData)
|
||||||
|
|
||||||
For Each oRow As DataRow In ControlDatatable.Rows
|
For Each oRow As DataRow In ControlDatatable.Rows
|
||||||
If oRow.Item("PROFILE_ID") = ProfileId Then
|
If oRow.Item("PROFILE_ID") = ProfileId Then
|
||||||
oControlList.Add(New ControlData() With {
|
oControlList.Add(New ControlData() With {
|
||||||
.Guid = oRow.Item("GUID"),
|
.Guid = oRow.Item("GUID"),
|
||||||
.Description = NotNull(oRow.Item("DESCRIPTION"), String.Empty),
|
.Description = NotNull(oRow.Item("DESCRIPTION"), String.Empty),
|
||||||
.WindowId = oRow.Item("WINDOW_ID"),
|
.WindowId = oRow.Item("WINDOW_ID"),
|
||||||
.TopLeft = New ControlBounds() With {
|
.TopLeft = New ControlBounds() With {
|
||||||
.Left = oRow.Item("TOPLEFT_LEFT"),
|
.Left = oRow.Item("TOPLEFT_LEFT"),
|
||||||
.Right = oRow.Item("TOPLEFT_RIGHT"),
|
.Right = oRow.Item("TOPLEFT_RIGHT"),
|
||||||
.Top = oRow.Item("TOPLEFT_TOP"),
|
.Top = oRow.Item("TOPLEFT_TOP"),
|
||||||
.Bottom = oRow.Item("TOPLEFT_BOTTOM")
|
.Bottom = oRow.Item("TOPLEFT_BOTTOM")
|
||||||
},
|
},
|
||||||
.TopRight = New ControlBounds() With {
|
.TopRight = New ControlBounds() With {
|
||||||
.Left = oRow.Item("TOPRIGHT_LEFT"),
|
.Left = oRow.Item("TOPRIGHT_LEFT"),
|
||||||
.Right = oRow.Item("TOPRIGHT_RIGHT"),
|
.Right = oRow.Item("TOPRIGHT_RIGHT"),
|
||||||
.Top = oRow.Item("TOPRIGHT_TOP"),
|
.Top = oRow.Item("TOPRIGHT_TOP"),
|
||||||
.Bottom = oRow.Item("TOPRIGHT_BOTTOM")
|
.Bottom = oRow.Item("TOPRIGHT_BOTTOM")
|
||||||
},
|
},
|
||||||
.BottomLeft = New ControlBounds() With {
|
.BottomLeft = New ControlBounds() With {
|
||||||
.Left = oRow.Item("BOTTOMLEFT_LEFT"),
|
.Left = oRow.Item("BOTTOMLEFT_LEFT"),
|
||||||
.Right = oRow.Item("BOTTOMLEFT_RIGHT"),
|
.Right = oRow.Item("BOTTOMLEFT_RIGHT"),
|
||||||
.Top = oRow.Item("BOTTOMLEFT_TOP"),
|
.Top = oRow.Item("BOTTOMLEFT_TOP"),
|
||||||
.Bottom = oRow.Item("BOTTOMLEFT_BOTTOM")
|
.Bottom = oRow.Item("BOTTOMLEFT_BOTTOM")
|
||||||
},
|
},
|
||||||
.BottomRight = New ControlBounds() With {
|
.BottomRight = New ControlBounds() With {
|
||||||
.Left = oRow.Item("BOTTOMRIGHT_LEFT"),
|
.Left = oRow.Item("BOTTOMRIGHT_LEFT"),
|
||||||
.Right = oRow.Item("BOTTOMRIGHT_RIGHT"),
|
.Right = oRow.Item("BOTTOMRIGHT_RIGHT"),
|
||||||
.Top = oRow.Item("BOTTOMRIGHT_TOP"),
|
.Top = oRow.Item("BOTTOMRIGHT_TOP"),
|
||||||
.Bottom = oRow.Item("BOTTOMRIGHT_BOTTOM")
|
.Bottom = oRow.Item("BOTTOMRIGHT_BOTTOM")
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
End If
|
End If
|
||||||
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)
|
||||||
Dim oProcessList As New List(Of ProcessData)
|
Try
|
||||||
|
Dim oProcessList As New List(Of ProcessData)
|
||||||
|
|
||||||
For Each oRow As DataRow In ProcessDatatable.Rows
|
For Each oRow As DataRow In ProcessDatatable.Rows
|
||||||
If oRow.Item("PROFILE_ID") = ProfileId Then
|
If oRow.Item("PROFILE_ID") = ProfileId Then
|
||||||
oProcessList.Add(New ProcessData() With {
|
oProcessList.Add(New ProcessData() With {
|
||||||
.Guid = oRow.Item("GUID"),
|
.Guid = oRow.Item("GUID"),
|
||||||
.PROFILE_ID = oRow.Item("PROFILE_ID"),
|
.PROFILE_ID = oRow.Item("PROFILE_ID"),
|
||||||
.ProcessName = NotNull(oRow.Item("PROC_NAME"), String.Empty)
|
.ProcessName = NotNull(oRow.Item("PROC_NAME"), String.Empty)
|
||||||
})
|
})
|
||||||
End If
|
End If
|
||||||
Next
|
Next
|
||||||
|
|
||||||
oProcessList = oProcessList.
|
oProcessList = oProcessList.
|
||||||
Distinct().
|
Distinct().
|
||||||
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)
|
||||||
Dim oWindowList As New List(Of WindowData)
|
Try
|
||||||
|
Dim oWindowList As New List(Of WindowData)
|
||||||
|
|
||||||
For Each oRow As DataRow In WindowDatatable.Rows
|
For Each oRow As DataRow In WindowDatatable.Rows
|
||||||
If oRow.Item("PROFILE_ID") = ProfileId Then
|
If oRow.Item("PROFILE_ID") = ProfileId Then
|
||||||
oWindowList.Add(New WindowData() With {
|
oWindowList.Add(New WindowData() With {
|
||||||
.Guid = oRow.Item("GUID"),
|
.Guid = oRow.Item("GUID"),
|
||||||
.WindowProcessID = oRow.Item("PROCESS_ID"),
|
.WindowProcessID = oRow.Item("PROCESS_ID"),
|
||||||
.Title = NotNull(oRow.Item("DESCRIPTION"), String.Empty),
|
.Title = NotNull(oRow.Item("DESCRIPTION"), String.Empty),
|
||||||
.Regex = NotNull(oRow.Item("REGEX"), String.Empty),
|
.Regex = NotNull(oRow.Item("REGEX"), String.Empty),
|
||||||
.Sequence = NotNull(oRow.Item("SEQUENCE"), 0)
|
.Sequence = NotNull(oRow.Item("SEQUENCE"), 0)
|
||||||
})
|
})
|
||||||
End If
|
End If
|
||||||
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,45 +42,59 @@ 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
|
||||||
Dim hWnd As IntPtr = NativeMethods.GetForegroundWindow()
|
Try
|
||||||
If hWnd = IntPtr.Zero Then
|
Dim hWnd As IntPtr = NativeMethods.GetForegroundWindow()
|
||||||
Return Nothing
|
Return GetWindowInfo(hWnd)
|
||||||
End If
|
Catch ex As Exception
|
||||||
|
_Logger.Debug("Error in GetWindowInfo/0")
|
||||||
Return GetWindowInfo(hWnd)
|
_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
|
||||||
Dim oPID As Integer = 0
|
Try
|
||||||
Dim oTitleLength As Int32 = NativeMethods.GetWindowTextLength(hWnd)
|
_Logger.Debug("Getting Window Info")
|
||||||
Dim oWindowTitle As String = StrDup(oTitleLength + 1, "*")
|
|
||||||
Dim oClassBuilder As New StringBuilder(64)
|
|
||||||
|
|
||||||
NativeMethods.GetWindowText(hWnd, oWindowTitle, oTitleLength + 1)
|
Dim oPID As Integer = 0
|
||||||
NativeMethods.GetWindowThreadProcessId(hWnd, oPID)
|
Dim oTitleLength As Int32 = NativeMethods.GetWindowTextLength(hWnd)
|
||||||
|
Dim oWindowTitle As String = StrDup(oTitleLength + 1, "*")
|
||||||
|
Dim oClassBuilder As New StringBuilder(64)
|
||||||
|
|
||||||
If oPID = 0 Then
|
_Logger.Debug("Getting Window Text and PID")
|
||||||
Return Nothing
|
|
||||||
End If
|
|
||||||
|
|
||||||
Dim oProcess As Process = Process.GetProcessById(oPID)
|
NativeMethods.GetWindowText(hWnd, oWindowTitle, oTitleLength + 1)
|
||||||
|
NativeMethods.GetWindowThreadProcessId(hWnd, oPID)
|
||||||
|
|
||||||
If oProcess Is Nothing Then
|
If oPID = 0 Then
|
||||||
Return Nothing
|
Return Nothing
|
||||||
End If
|
End If
|
||||||
|
|
||||||
NativeMethods.GetClassName(hWnd, oClassBuilder, 64)
|
Dim oProcess As Process = Process.GetProcessById(oPID)
|
||||||
|
|
||||||
Return New WindowInfo With {
|
If oProcess Is Nothing Then
|
||||||
.hWnd = hWnd,
|
Return Nothing
|
||||||
.ClassName = oClassBuilder.ToString,
|
End If
|
||||||
.ProcessId = oProcess.Id,
|
|
||||||
.ProcessName = oProcess.ProcessName,
|
_Logger.Debug("Getting Class Name")
|
||||||
.WindowTitle = oWindowTitle.Replace(vbNullChar, String.Empty)
|
|
||||||
}
|
NativeMethods.GetClassName(hWnd, oClassBuilder, 64)
|
||||||
|
|
||||||
|
Return New WindowInfo With {
|
||||||
|
.hWnd = hWnd,
|
||||||
|
.ClassName = oClassBuilder.ToString,
|
||||||
|
.ProcessId = oProcess.Id,
|
||||||
|
.ProcessName = oProcess.ProcessName,
|
||||||
|
.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)
|
||||||
Return Nothing
|
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
|
||||||
|
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,67 +301,96 @@ 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)
|
||||||
Dim oWindowRect As New NativeMethods.RectangleAPI
|
Try
|
||||||
|
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
|
||||||
Return Nothing
|
Return Nothing
|
||||||
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
|
||||||
Dim oScreenRect As Rectangle = Screen.PrimaryScreen.Bounds
|
Try
|
||||||
Dim oLeft, oBottom, oTop, oRight As Integer
|
Dim oScreenRect As Rectangle = Screen.PrimaryScreen.Bounds
|
||||||
|
Dim oLeft, oBottom, oTop, oRight As Integer
|
||||||
|
|
||||||
Select Case Anchor
|
_Logger.Debug("Calculating Rectangle for Anchor {0}", Anchor.ToString)
|
||||||
Case Anchor.TopLeft
|
|
||||||
oLeft = ControlRect.Left - WindowRect.Left
|
|
||||||
oTop = ControlRect.Top - WindowRect.Top
|
|
||||||
Case Anchor.BottomLeft
|
|
||||||
oLeft = ControlRect.Left - WindowRect.Left
|
|
||||||
oBottom = ControlRect.Bottom - WindowRect.Bottom
|
|
||||||
Case Anchor.TopRight
|
|
||||||
oRight = ControlRect.Right - WindowRect.Right
|
|
||||||
oTop = ControlRect.Top - WindowRect.Top
|
|
||||||
Case Anchor.BottomRight
|
|
||||||
oRight = ControlRect.Right - WindowRect.Right
|
|
||||||
oBottom = ControlRect.Bottom - WindowRect.Bottom
|
|
||||||
End Select
|
|
||||||
|
|
||||||
Return New NativeMethods.RectangleAPI() With {
|
Select Case Anchor
|
||||||
.Top = oTop,
|
Case Anchor.TopLeft
|
||||||
.Bottom = oBottom,
|
oLeft = ControlRect.Left - WindowRect.Left
|
||||||
.Left = oLeft,
|
oTop = ControlRect.Top - WindowRect.Top
|
||||||
.Right = oRight
|
Case Anchor.BottomLeft
|
||||||
}
|
oLeft = ControlRect.Left - WindowRect.Left
|
||||||
|
oBottom = ControlRect.Bottom - WindowRect.Bottom
|
||||||
|
Case Anchor.TopRight
|
||||||
|
oRight = ControlRect.Right - WindowRect.Right
|
||||||
|
oTop = ControlRect.Top - WindowRect.Top
|
||||||
|
Case Anchor.BottomRight
|
||||||
|
oRight = ControlRect.Right - WindowRect.Right
|
||||||
|
oBottom = ControlRect.Bottom - WindowRect.Bottom
|
||||||
|
End Select
|
||||||
|
|
||||||
|
_Logger.Debug("Done Calculating Rectangle for Anchor {0}", Anchor.ToString)
|
||||||
|
|
||||||
|
Return New NativeMethods.RectangleAPI() With {
|
||||||
|
.Top = oTop,
|
||||||
|
.Bottom = oBottom,
|
||||||
|
.Left = oLeft,
|
||||||
|
.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
|
||||||
Dim oX, oY, oWidth, oHeight As Integer
|
Try
|
||||||
|
Dim oX, oY, oWidth, oHeight As Integer
|
||||||
|
|
||||||
oWidth = Rect.Right - Rect.Left
|
oWidth = Rect.Right - Rect.Left
|
||||||
oHeight = Rect.Bottom - Rect.Top
|
oHeight = Rect.Bottom - Rect.Top
|
||||||
oX = Rect.Left - ParentRect.Left
|
oX = Rect.Left - ParentRect.Left
|
||||||
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
|
||||||
Dim oX, oY, oWidth, oHeight As Integer
|
Try
|
||||||
|
Dim oX, oY, oWidth, oHeight As Integer
|
||||||
|
|
||||||
oWidth = Rect.Right - Rect.Left
|
oWidth = Rect.Right - Rect.Left
|
||||||
oHeight = Rect.Bottom - Rect.Top
|
oHeight = Rect.Bottom - Rect.Top
|
||||||
oX = Rect.Left - ParentRect.X
|
oX = Rect.Left - ParentRect.X
|
||||||
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