From 6b31549a30e90952d0d8e18a9d5f8ab268d731b6 Mon Sep 17 00:00:00 2001 From: Jonathan Jenne Date: Mon, 21 Oct 2019 14:07:47 +0200 Subject: [PATCH] add debugging to profilefilter & window class --- GUIs.ClipboardWatcher/ProfileFilter.vb | 219 +++++++++++--------- Windows/NativeMethods.vb | 4 + Windows/Window.vb | 274 +++++++++++++++++-------- 3 files changed, 316 insertions(+), 181 deletions(-) diff --git a/GUIs.ClipboardWatcher/ProfileFilter.vb b/GUIs.ClipboardWatcher/ProfileFilter.vb index 0f07cf01..161dc4cb 100644 --- a/GUIs.ClipboardWatcher/ProfileFilter.vb +++ b/GUIs.ClipboardWatcher/ProfileFilter.vb @@ -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) Try - _ProfileMatch = New ProfileMatch(LogConfig) + _LogConfig = LogConfig + _Logger = LogConfig.GetLogger() + + _Logger.Debug("Initializing Profile Filter") + _Logger.Debug("Initializing Profile Data") _ProfileTable = ProfileDatatable _ProcessTable = ProcessTable _WindowTable = WindowDatatable _ControlTable = ControlDatatable - _Profiles = TransformProfiles() + + _Logger.Debug("Initializing Profile Debugging") _TreeView = TreeView - _LogConfig = LogConfig - _Logger = LogConfig.GetLogger() + _ProfileMatch = New ProfileMatch(LogConfig) + + _Logger.Debug("Transforming Profiles") + _Profiles = TransformProfiles() Catch ex As Exception _Logger.Error(ex) Throw ex @@ -209,19 +216,19 @@ Public Class ProfileFilter For Each oItem As KeyValuePair(Of String, Window.RectangleInfo) In oControlBounds Select Case oItem.Key - Case "TOPLEFT" + Case "TopLeft" If oControl.TopLeft.Top = oItem.Value.Top And oControl.TopLeft.Left = oItem.Value.Left Then oFound = True End If - Case "TOPRIGHT" + Case "TopRight" If oControl.TopRight.Top = oItem.Value.Top And oControl.TopLeft.Right = oItem.Value.Right Then oFound = True End If - Case "BOTTOMLEFT" + Case "BottomLeft" If oControl.BottomLeft.Bottom = oItem.Value.Bottom And oControl.TopLeft.Left = oItem.Value.Left Then oFound = True End If - Case "BOTTOMRIGHT" + Case "BottomRight" If oControl.BottomRight.Bottom = oItem.Value.Bottom And oControl.TopLeft.Right = oItem.Value.Right Then oFound = True End If @@ -385,106 +392,126 @@ Public Class ProfileFilter End Function Private Function TransformProfiles() As List(Of ProfileData) - Dim oList As New List(Of ProfileData) - - For Each oRow As DataRow In _ProfileTable.Rows - Dim oProfileId = oRow.Item("GUID") - Dim oProcessList As List(Of ProcessData) = TransformProcesses(oProfileId, _ProcessTable) - Dim oWindowList As List(Of WindowData) = TransformWindows(oProfileId, _WindowTable) - Dim oControlList As List(Of ControlData) = TransformControls(oProfileId, _ControlTable) - - oList.Add(New ProfileData() With { - .Guid = oRow.Item("GUID"), - .Regex = oRow.Item("REGEX_EXPRESSION"), - .Name = NotNull(oRow.Item("NAME"), String.Empty), - .Comment = NotNull(oRow.Item("COMMENT"), String.Empty), - .ProfileType = NotNull(oRow.Item("PROFILE_TYPE"), String.Empty), - .Processes = oProcessList, - .Windows = oWindowList, - .Controls = oControlList - }) - Next + Try + Dim oList As New List(Of ProfileData) - oList = oList. - Distinct(). - ToList() + For Each oRow As DataRow In _ProfileTable.Rows + Dim oProfileId = oRow.Item("GUID") + Dim oProcessList As List(Of ProcessData) = TransformProcesses(oProfileId, _ProcessTable) + Dim oWindowList As List(Of WindowData) = TransformWindows(oProfileId, _WindowTable) + Dim oControlList As List(Of ControlData) = TransformControls(oProfileId, _ControlTable) + + oList.Add(New ProfileData() With { + .Guid = oRow.Item("GUID"), + .Regex = oRow.Item("REGEX_EXPRESSION"), + .Name = NotNull(oRow.Item("NAME"), String.Empty), + .Comment = NotNull(oRow.Item("COMMENT"), String.Empty), + .ProfileType = NotNull(oRow.Item("PROFILE_TYPE"), String.Empty), + .Processes = oProcessList, + .Windows = oWindowList, + .Controls = oControlList + }) + Next + + oList = oList. + Distinct(). + ToList() - Return oList + Return oList + Catch ex As Exception + _Logger.Error(ex) + Throw ex + End Try End Function Private Function TransformControls(ProfileId As Integer, ControlDatatable As DataTable) As List(Of ControlData) - Dim oControlList As New List(Of ControlData) - - For Each oRow As DataRow In ControlDatatable.Rows - If oRow.Item("PROFILE_ID") = ProfileId Then - oControlList.Add(New ControlData() With { - .Guid = oRow.Item("GUID"), - .Description = NotNull(oRow.Item("DESCRIPTION"), String.Empty), - .WindowId = oRow.Item("WINDOW_ID"), - .TopLeft = New ControlBounds() With { - .Left = oRow.Item("TOPLEFT_LEFT"), - .Right = oRow.Item("TOPLEFT_RIGHT"), - .Top = oRow.Item("TOPLEFT_TOP"), - .Bottom = oRow.Item("TOPLEFT_BOTTOM") - }, - .TopRight = New ControlBounds() With { - .Left = oRow.Item("TOPRIGHT_LEFT"), - .Right = oRow.Item("TOPRIGHT_RIGHT"), - .Top = oRow.Item("TOPRIGHT_TOP"), - .Bottom = oRow.Item("TOPRIGHT_BOTTOM") - }, - .BottomLeft = New ControlBounds() With { - .Left = oRow.Item("BOTTOMLEFT_LEFT"), - .Right = oRow.Item("BOTTOMLEFT_RIGHT"), - .Top = oRow.Item("BOTTOMLEFT_TOP"), - .Bottom = oRow.Item("BOTTOMLEFT_BOTTOM") - }, - .BottomRight = New ControlBounds() With { - .Left = oRow.Item("BOTTOMRIGHT_LEFT"), - .Right = oRow.Item("BOTTOMRIGHT_RIGHT"), - .Top = oRow.Item("BOTTOMRIGHT_TOP"), - .Bottom = oRow.Item("BOTTOMRIGHT_BOTTOM") - } - }) - End If - Next + Try + Dim oControlList As New List(Of ControlData) + + For Each oRow As DataRow In ControlDatatable.Rows + If oRow.Item("PROFILE_ID") = ProfileId Then + oControlList.Add(New ControlData() With { + .Guid = oRow.Item("GUID"), + .Description = NotNull(oRow.Item("DESCRIPTION"), String.Empty), + .WindowId = oRow.Item("WINDOW_ID"), + .TopLeft = New ControlBounds() With { + .Left = oRow.Item("TOPLEFT_LEFT"), + .Right = oRow.Item("TOPLEFT_RIGHT"), + .Top = oRow.Item("TOPLEFT_TOP"), + .Bottom = oRow.Item("TOPLEFT_BOTTOM") + }, + .TopRight = New ControlBounds() With { + .Left = oRow.Item("TOPRIGHT_LEFT"), + .Right = oRow.Item("TOPRIGHT_RIGHT"), + .Top = oRow.Item("TOPRIGHT_TOP"), + .Bottom = oRow.Item("TOPRIGHT_BOTTOM") + }, + .BottomLeft = New ControlBounds() With { + .Left = oRow.Item("BOTTOMLEFT_LEFT"), + .Right = oRow.Item("BOTTOMLEFT_RIGHT"), + .Top = oRow.Item("BOTTOMLEFT_TOP"), + .Bottom = oRow.Item("BOTTOMLEFT_BOTTOM") + }, + .BottomRight = New ControlBounds() With { + .Left = oRow.Item("BOTTOMRIGHT_LEFT"), + .Right = oRow.Item("BOTTOMRIGHT_RIGHT"), + .Top = oRow.Item("BOTTOMRIGHT_TOP"), + .Bottom = oRow.Item("BOTTOMRIGHT_BOTTOM") + } + }) + End If + Next - Return oControlList + Return oControlList + Catch ex As Exception + _Logger.Error(ex) + Throw ex + End Try End Function Private Function TransformProcesses(ProfileId As Integer, ProcessDatatable As DataTable) As List(Of ProcessData) - Dim oProcessList As New List(Of ProcessData) - - For Each oRow As DataRow In ProcessDatatable.Rows - If oRow.Item("PROFILE_ID") = ProfileId Then - oProcessList.Add(New ProcessData() With { - .Guid = oRow.Item("GUID"), - .PROFILE_ID = oRow.Item("PROFILE_ID"), - .ProcessName = NotNull(oRow.Item("PROC_NAME"), String.Empty) - }) - End If - Next + Try + Dim oProcessList As New List(Of ProcessData) + + For Each oRow As DataRow In ProcessDatatable.Rows + If oRow.Item("PROFILE_ID") = ProfileId Then + oProcessList.Add(New ProcessData() With { + .Guid = oRow.Item("GUID"), + .PROFILE_ID = oRow.Item("PROFILE_ID"), + .ProcessName = NotNull(oRow.Item("PROC_NAME"), String.Empty) + }) + End If + Next - oProcessList = oProcessList. - Distinct(). - ToList() + oProcessList = oProcessList. + Distinct(). + ToList() - Return oProcessList + Return oProcessList + Catch ex As Exception + _Logger.Error(ex) + Throw ex + End Try End Function Private Function TransformWindows(ProfileId As Integer, WindowDatatable As DataTable) As List(Of WindowData) - Dim oWindowList As New List(Of WindowData) - - For Each oRow As DataRow In WindowDatatable.Rows - If oRow.Item("PROFILE_ID") = ProfileId Then - oWindowList.Add(New WindowData() With { - .Guid = oRow.Item("GUID"), - .WindowProcessID = oRow.Item("PROCESS_ID"), - .Title = NotNull(oRow.Item("DESCRIPTION"), String.Empty), - .Regex = NotNull(oRow.Item("REGEX"), String.Empty), - .Sequence = NotNull(oRow.Item("SEQUENCE"), 0) - }) - End If - Next + Try + Dim oWindowList As New List(Of WindowData) + + For Each oRow As DataRow In WindowDatatable.Rows + If oRow.Item("PROFILE_ID") = ProfileId Then + oWindowList.Add(New WindowData() With { + .Guid = oRow.Item("GUID"), + .WindowProcessID = oRow.Item("PROCESS_ID"), + .Title = NotNull(oRow.Item("DESCRIPTION"), String.Empty), + .Regex = NotNull(oRow.Item("REGEX"), String.Empty), + .Sequence = NotNull(oRow.Item("SEQUENCE"), 0) + }) + End If + Next - Return oWindowList + Return oWindowList + Catch ex As Exception + _Logger.Error(ex) + Throw ex + End Try End Function End Class diff --git a/Windows/NativeMethods.vb b/Windows/NativeMethods.vb index 1a42dcd1..ceda71c9 100644 --- a/Windows/NativeMethods.vb +++ b/Windows/NativeMethods.vb @@ -127,6 +127,10 @@ Public Class NativeMethods Public Top As Integer Public Right 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 diff --git a/Windows/Window.vb b/Windows/Window.vb index 7a3b8cc7..5fd51897 100644 --- a/Windows/Window.vb +++ b/Windows/Window.vb @@ -31,7 +31,7 @@ Public Class Window Public ClassName As String = "" Public ProcessId As Integer = 0 Public ControlName As String = "" - Public hWnd As IntPtr + Public hWnd As IntPtr = IntPtr.Zero End Class Public Sub New(LogConfig As LogConfig) @@ -42,45 +42,59 @@ Public Class Window ''' Returns Information about the currently focused window ''' Public Function GetWindowInfo() As WindowInfo - Dim hWnd As IntPtr = NativeMethods.GetForegroundWindow() - If hWnd = IntPtr.Zero Then - Return Nothing - End If - - Return GetWindowInfo(hWnd) + Try + Dim hWnd As IntPtr = NativeMethods.GetForegroundWindow() + Return GetWindowInfo(hWnd) + Catch ex As Exception + _Logger.Debug("Error in GetWindowInfo/0") + _Logger.Error(ex) + Throw ex + End Try End Function ''' ''' Returns Information about the Window with `hWnd` ''' Public Function GetWindowInfo(ByVal hWnd As IntPtr) As WindowInfo - Dim oPID As Integer = 0 - Dim oTitleLength As Int32 = NativeMethods.GetWindowTextLength(hWnd) - Dim oWindowTitle As String = StrDup(oTitleLength + 1, "*") - Dim oClassBuilder As New StringBuilder(64) + Try + _Logger.Debug("Getting Window Info") - NativeMethods.GetWindowText(hWnd, oWindowTitle, oTitleLength + 1) - NativeMethods.GetWindowThreadProcessId(hWnd, oPID) + Dim oPID As Integer = 0 + Dim oTitleLength As Int32 = NativeMethods.GetWindowTextLength(hWnd) + Dim oWindowTitle As String = StrDup(oTitleLength + 1, "*") + Dim oClassBuilder As New StringBuilder(64) - If oPID = 0 Then - Return Nothing - End If + _Logger.Debug("Getting Window Text and PID") - Dim oProcess As Process = Process.GetProcessById(oPID) + NativeMethods.GetWindowText(hWnd, oWindowTitle, oTitleLength + 1) + NativeMethods.GetWindowThreadProcessId(hWnd, oPID) - If oProcess Is Nothing Then - Return Nothing - End If + If oPID = 0 Then + Return Nothing + End If - NativeMethods.GetClassName(hWnd, oClassBuilder, 64) + Dim oProcess As Process = Process.GetProcessById(oPID) - Return New WindowInfo With { - .hWnd = hWnd, - .ClassName = oClassBuilder.ToString, - .ProcessId = oProcess.Id, - .ProcessName = oProcess.ProcessName, - .WindowTitle = oWindowTitle.Replace(vbNullChar, String.Empty) - } + If oProcess Is Nothing Then + Return Nothing + End If + + _Logger.Debug("Getting Class Name") + + 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 ''' @@ -92,6 +106,7 @@ Public Class Window Dim oWindow = GetWindowInfo() If oWindow Is Nothing Then + _Logger.Debug("Could not get Window Info!") Return Nothing End If @@ -104,12 +119,14 @@ Public Class Window Dim oControl As WindowInfo = GetWindowInfo(oControlhWnd) If oControl Is Nothing Then + _Logger.Debug("Could not get Control Info!") Return Nothing End If Dim oName = Utils.GetWinFormsId(oControlhWnd) oControl.ControlName = oName + Return oControl Catch ex As Exception _Logger.Error(ex) @@ -120,10 +137,10 @@ Public Class Window Return Nothing Catch ex As Exception + _Logger.Debug("Error in GetFocusedControl/1") _Logger.Error(ex) - Return Nothing + Throw ex End Try - End Function ''' @@ -134,11 +151,15 @@ Public Class Window Dim oControlRect As New NativeMethods.RectangleAPI Dim oResult As New RectangleInfo + _Logger.Debug("Getting Control Location") + 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 @@ -148,6 +169,8 @@ Public Class Window ' Calculate Coordinates relative to parent window oRect = GetRelativeRectangle(oControlRect, oWindowRect, Anchor) + _Logger.Debug("Control Location for Anchor {0}: {1}", Anchor, oRect) + oResult.Left = oRect.Left oResult.Right = oRect.Right oResult.Top = oRect.Top @@ -155,8 +178,49 @@ Public Class Window Return oResult Catch ex As Exception + _Logger.Debug("Error in GetControlLocation/3") _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 Function @@ -164,44 +228,55 @@ Public Class Window ''' Returns Bounds of the focused control. Relative to current form and `Anchor` value. ''' 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 oFocusedControl As WindowInfo - Dim oResult As New RectangleInfo Try oForegroundWindow = GetWindowInfo() 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) Catch ex As Exception + _Logger.Debug("Error in GetFocusedControlLocation/2") _Logger.Error(ex) - Return Nothing + Throw ex 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) + If oForegroundWindow Is Nothing Then + _Logger.Warn("Foreground Window is Nothing!") + End If - For Each oAnchor As Anchor In [Enum].GetValues(GetType(Anchor)) - oDict.Add(oAnchor.ToString.ToUpper, GetControlLocation(oFocusedControl.hWnd, oForegroundWindow.hWnd, oAnchor)) - Next + If oFocusedControl Is Nothing Then + _Logger.Warn("Focused Control is Nothing!") + End If + + Dim oDict As Dictionary(Of String, RectangleInfo) = GetControlLocations(oFocusedControl.hWnd, oForegroundWindow.hWnd) Return oDict Catch ex As Exception + _Logger.Debug("Error in GetFocusedControlLocation/1") _Logger.Error(ex) - Return Nothing + Throw ex End Try End Function @@ -226,67 +301,96 @@ Public Class Window Return GetControlLocation(oControlUnderCursor, oForegroundWindow, Anchor) Catch ex As Exception + _Logger.Debug("Error in GetHoveredControlLocation/1") _Logger.Error(ex) - Return Nothing + Throw ex End Try End Function 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 - Return Nothing - End If + If NativeMethods.GetWindowRect(New HandleRef(Me, Handle), oWindowRect) = False Then + Return Nothing + 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 Private Function GetRelativeRectangle(ControlRect As NativeMethods.RectangleAPI, WindowRect As NativeMethods.RectangleAPI, Anchor As Anchor) As NativeMethods.RectangleAPI - Dim oScreenRect As Rectangle = Screen.PrimaryScreen.Bounds - Dim oLeft, oBottom, oTop, oRight As Integer - - Select Case Anchor - 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 { - .Top = oTop, - .Bottom = oBottom, - .Left = oLeft, - .Right = oRight - } + Try + Dim oScreenRect As Rectangle = Screen.PrimaryScreen.Bounds + Dim oLeft, oBottom, oTop, oRight As Integer + + _Logger.Debug("Calculating Rectangle for Anchor {0}", Anchor.ToString) + + Select Case Anchor + 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 + + _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 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 - oHeight = Rect.Bottom - Rect.Top - oX = Rect.Left - ParentRect.Left - oY = Rect.Top - ParentRect.Top + oWidth = Rect.Right - Rect.Left + oHeight = Rect.Bottom - Rect.Top + oX = Rect.Left - ParentRect.Left + 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 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 - oHeight = Rect.Bottom - Rect.Top - oX = Rect.Left - ParentRect.X - oY = Rect.Top - ParentRect.Y + oWidth = Rect.Right - Rect.Left + oHeight = Rect.Bottom - Rect.Top + oX = Rect.Left - ParentRect.X + 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 Class