@@ -70,15 +70,15 @@ public static void VbeEventCallback(IntPtr hWinEventHook, uint eventType, IntPtr
70
70
{
71
71
if ( hwnd != IntPtr . Zero &&
72
72
idObject == ( int ) ObjId . Caret &&
73
- ( eventType == ( uint ) WinEvent . ObjectLocationChange || eventType == ( uint ) WinEvent . ObjectCreate ) &&
74
- hwnd . ToWindowType ( ) == WindowType . VbaWindow )
73
+ ( eventType == ( uint ) WinEvent . ObjectLocationChange || eventType == ( uint ) WinEvent . ObjectCreate ) &&
74
+ hwnd . ToWindowType ( ) == WindowType . CodePane )
75
75
{
76
76
OnSelectionChanged ( hwnd ) ;
77
77
}
78
78
else if ( idObject == ( int ) ObjId . Window && ( eventType == ( uint ) WinEvent . ObjectCreate || eventType == ( uint ) WinEvent . ObjectDestroy ) )
79
79
{
80
80
var type = hwnd . ToWindowType ( ) ;
81
- if ( type != WindowType . DesignerWindow && type != WindowType . VbaWindow )
81
+ if ( type != WindowType . DesignerWindow && type != WindowType . CodePane )
82
82
{
83
83
return ;
84
84
}
@@ -195,14 +195,23 @@ public enum WindowType
195
195
{
196
196
Indeterminate ,
197
197
VbaWindow ,
198
+ CodePane ,
198
199
DesignerWindow ,
199
200
Project
200
201
}
201
202
202
203
public static WindowType ToWindowType ( this IntPtr hwnd )
203
204
{
204
205
WindowType id ;
205
- return Enum . TryParse ( hwnd . ToClassName ( ) , true , out id ) ? id : WindowType . Indeterminate ;
206
+ var type = Enum . TryParse ( hwnd . ToClassName ( ) , true , out id ) ? id : WindowType . Indeterminate ;
207
+ if ( type != WindowType . VbaWindow )
208
+ {
209
+ return type ;
210
+ }
211
+ //A this point we only care about code panes - none of the other 4 types of VbaWindows (Immediate, Object Browser, Locals,
212
+ //and Watches) contain a tool bar at the top, so just see if the window has one as a child.
213
+ var toolbar = User32 . FindWindowEx ( hwnd , IntPtr . Zero , "ObtbarWndClass" , string . Empty ) ;
214
+ return toolbar == IntPtr . Zero ? WindowType . VbaWindow : WindowType . CodePane ;
206
215
}
207
216
208
217
public static string ToClassName ( this IntPtr hwnd )
0 commit comments