From c80c5aea7820cafc5a64874394a972a8ac028abf Mon Sep 17 00:00:00 2001 From: Jonathan Jenne Date: Fri, 25 Oct 2019 13:27:34 +0200 Subject: [PATCH] check if current control belongs to current process --- GUIs.ClipboardWatcher/ProfileFilter.vb | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/GUIs.ClipboardWatcher/ProfileFilter.vb b/GUIs.ClipboardWatcher/ProfileFilter.vb index 53257d31..b05cda61 100644 --- a/GUIs.ClipboardWatcher/ProfileFilter.vb +++ b/GUIs.ClipboardWatcher/ProfileFilter.vb @@ -205,7 +205,7 @@ Public Class ProfileFilter Return oProfiles End Function - Public Function FilterProfilesByFocusedControlLocation(Profiles As List(Of ProfileData), ClipboardContents As String, WindowHandle As IntPtr) As List(Of ProfileData) + Public Function FilterProfilesByFocusedControl(Profiles As List(Of ProfileData), ClipboardContents As String, WindowHandle As IntPtr) As List(Of ProfileData) Dim oFilteredProfiles As New List(Of ProfileData) Dim oWindow As New Window(_LogConfig) @@ -221,6 +221,18 @@ Public Class ProfileFilter For Each oControl In oProfile.Controls Dim oFound As Boolean = False + ' If current control does not belong to the current process, skip it + Try + Dim oFocusedWindow As Window.WindowInfo = oWindow.GetWindowInfo() + + If oFocusedWindow.ProcessName <> oControl.ProcessName Then + Continue For + End If + Catch ex As Exception + _Logger.Error(ex) + End Try + + ' If control name is empty, use coordinates If oControl.ControlName Is Nothing OrElse oControl.ControlName = String.Empty Then Dim oControlBounds As Dictionary(Of String, Window.RectangleInfo) @@ -471,6 +483,7 @@ Public Class ProfileFilter If oRow.Item("PROFILE_ID") = ProfileId Then oControlList.Add(New ControlData() With { .Guid = oRow.Item("GUID"), + .ProcessName = NotNull(oRow.Item("PROCESS_NAME"), String.Empty), .ControlName = NotNull(oRow.Item("CONTROL_NAME"), String.Empty), .Description = NotNull(oRow.Item("DESCRIPTION"), String.Empty), .WindowId = oRow.Item("WINDOW_ID"),