diff --git a/GUIs.ClipboardWatcher/ProfileFilter.vb b/GUIs.ClipboardWatcher/ProfileFilter.vb index 0c9954dd..53257d31 100644 --- a/GUIs.ClipboardWatcher/ProfileFilter.vb +++ b/GUIs.ClipboardWatcher/ProfileFilter.vb @@ -142,8 +142,8 @@ Public Class ProfileFilter Catch ex As Exception _Logger.Warn("Unexpected error in FilterProfilesByProcess...") _Logger.Error(ex) + Return Profiles End Try - End Function Public Function FilterWindowsByWindowTitleRegex(Profiles As List(Of ProfileData), WindowTitle As String) As List(Of ProfileData) Dim oProfiles As New List(Of ProfileData) @@ -219,29 +219,52 @@ Public Class ProfileFilter Dim oControls As New List(Of ControlData) For Each oControl In oProfile.Controls - Dim oControlBounds = oWindow.GetFocusedControlLocation(WindowHandle) Dim oFound As Boolean = False - For Each oItem As KeyValuePair(Of String, Window.RectangleInfo) In oControlBounds - Select Case oItem.Key - Case "TopLeft" - If oControl.TopLeft.Top = oItem.Value.Top And oControl.TopLeft.Left = oItem.Value.Left Then - oFound = True - End If - Case "TopRight" - If oControl.TopRight.Top = oItem.Value.Top And oControl.TopLeft.Right = oItem.Value.Right Then - oFound = True - End If - Case "BottomLeft" - If oControl.BottomLeft.Bottom = oItem.Value.Bottom And oControl.TopLeft.Left = oItem.Value.Left Then - oFound = True - End If - Case "BottomRight" - If oControl.BottomRight.Bottom = oItem.Value.Bottom And oControl.TopLeft.Right = oItem.Value.Right Then - oFound = True - End If - End Select - Next + If oControl.ControlName Is Nothing OrElse oControl.ControlName = String.Empty Then + Dim oControlBounds As Dictionary(Of String, Window.RectangleInfo) + + Try + oControlBounds = oWindow.GetFocusedControlLocation(WindowHandle) + + For Each oItem As KeyValuePair(Of String, Window.RectangleInfo) In oControlBounds + Select Case oItem.Key + Case "TopLeft" + If oControl.TopLeft.Top = oItem.Value.Top And oControl.TopLeft.Left = oItem.Value.Left Then + oFound = True + End If + Case "TopRight" + If oControl.TopRight.Top = oItem.Value.Top And oControl.TopLeft.Right = oItem.Value.Right Then + oFound = True + End If + Case "BottomLeft" + If oControl.BottomLeft.Bottom = oItem.Value.Bottom And oControl.TopLeft.Left = oItem.Value.Left Then + oFound = True + End If + Case "BottomRight" + If oControl.BottomRight.Bottom = oItem.Value.Bottom And oControl.TopLeft.Right = oItem.Value.Right Then + oFound = True + End If + End Select + Next + Catch ex As Exception + _Logger.Warn("Error while getting focused control location") + _Logger.Error(ex) + End Try + Else + Dim oControlName As String = oControl.ControlName + + Try + Dim oFocusedControl = oWindow.GetFocusedControl(WindowHandle) + + If oFocusedControl.ControlName = oControlName Then + oFound = True + End If + Catch ex As Exception + _Logger.Warn("Error while getting focused control name") + _Logger.Error(ex) + End Try + End If If oFound Then oControls.Add(oControl) @@ -448,6 +471,7 @@ Public Class ProfileFilter If oRow.Item("PROFILE_ID") = ProfileId Then oControlList.Add(New ControlData() With { .Guid = oRow.Item("GUID"), + .ControlName = NotNull(oRow.Item("CONTROL_NAME"), String.Empty), .Description = NotNull(oRow.Item("DESCRIPTION"), String.Empty), .WindowId = oRow.Item("WINDOW_ID"), .TopLeft = New ControlBounds() With {