@@ -867,22 +867,23 @@ public bool PreFilterMessage(ref Message m)
867867 User32 . SetCursor ( cursorHandle ) ;
868868 var cursorPosition = Cursor . Position ;
869869 var element = AutomationElement . FromPoint ( new System . Windows . Point ( cursorPosition . X , cursorPosition . Y ) ) ;
870- var windowProcessId = element . Current . ProcessId ;
871- if ( element != null && windowProcessId != _processId )
870+ if ( element != null && element . Current . ProcessId != _processId )
872871 {
873872 var windowHandle = new IntPtr ( element . Current . NativeWindowHandle ) ;
874873 if ( windowHandle == IntPtr . Zero )
875874 {
876875 windowHandle = User32 . WindowFromPoint ( new Point ( cursorPosition . X , cursorPosition . Y ) ) ;
877- if ( windowHandle != IntPtr . Zero )
878- {
879- User32 . GetWindowThreadProcessId ( windowHandle , out windowProcessId ) ;
880- var windowStyle = User32 . GetWindowLong ( windowHandle , Constants . GWL_STYLE ) ;
881- if ( ( ( windowStyle & Constants . WS_CAPTION ) != 0 || ( windowStyle & Constants . WS_SYSMENU ) != 0 || ( windowStyle & Constants . WS_POPUP ) != 0 ) )
882- {
883- element = AutomationElement . FromHandle ( windowHandle ) ;
884- }
885- }
876+ }
877+
878+ var windowProcessId = element . Current . ProcessId ;
879+ if ( windowProcessId == 0 )
880+ {
881+ User32 . GetWindowThreadProcessId ( windowHandle , out windowProcessId ) ;
882+ }
883+
884+ if ( ! element . Current . IsContentElement )
885+ {
886+ element = AutomationElement . FromHandle ( windowHandle ) ;
886887 }
887888
888889 var previousHandle = IntPtr . Zero ;
@@ -946,7 +947,7 @@ public bool PreFilterMessage(ref Message m)
946947 }
947948 else
948949 {
949- var text = WindowUtils . ExtractTextFromConsoleWindow ( windowProcessId ) ?? element . GetTextFromWindow ( ) ;
950+ var text = WindowUtils . ExtractTextFromConsoleWindow ( windowProcessId ) ?? ( element . Current . IsContentElement ? element . GetTextFromWindow ( ) : WindowUtils . GetWindowText ( windowHandle ) ) ;
950951 text = text == null ? "" : text . TrimEnd ( ) . TrimEnd ( Environment . NewLine ) ;
951952 if ( _settings . ShowEmptyItems || ( ! _settings . ShowEmptyItems && ! string . IsNullOrEmpty ( text ) ) )
952953 {
0 commit comments