Skip to content

Commit eb45a04

Browse files
committed
Test for treeview focus before firing OnWindowFocusChange for selection changes.
1 parent 79a5bbc commit eb45a04

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

Rubberduck.VBEEditor/Events/VBENativeServices.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,7 @@ public static void VbeEventCallback(IntPtr hWinEventHook, uint eventType, IntPtr
9393
{
9494
//Test to see if it was a selection change in the project window.
9595
var parent = User32.GetParent(hwnd);
96-
//TODO: Need to test to see if the Project window is active before raising this.
97-
if (parent != IntPtr.Zero && parent.ToWindowType() == WindowType.Project)
96+
if (parent != IntPtr.Zero && parent.ToWindowType() == WindowType.Project && hwnd == User32.GetFocus())
9897
{
9998
FocusDispatcher(_vbe, new WindowChangedEventArgs(parent, null, null, FocusType.ChildFocus));
10099
}

Rubberduck.VBEEditor/WindowsApi/User32.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,12 @@ public static class User32
5656
[DllImport("user32.dll")]
5757
public static extern IntPtr GetForegroundWindow();
5858

59+
[DllImport("user32.dll")]
60+
public static extern IntPtr GetActiveWindow();
61+
62+
[DllImport("user32.dll")]
63+
public static extern IntPtr GetFocus();
64+
5965
/// <summary>
6066
/// Gets the underlying class name for a window handle.
6167
/// https://msdn.microsoft.com/en-us/library/windows/desktop/ms633582(v=vs.85).aspx

0 commit comments

Comments
 (0)