Skip to content

Commit dc43ca9

Browse files
committed
Issues #13 More correct fix for the 2000 character limit issue
1 parent ec1c87a commit dc43ca9

File tree

3 files changed

+14
-18
lines changed

3 files changed

+14
-18
lines changed

WindowTextExtractor/Forms/MainForm.cs

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -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
{

WindowTextExtractor/Native/Constants.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,6 @@ static class Constants
2929
public const int DWL_DLGPROC = 4;
3030
public const int DWL_USER = 8;
3131

32-
// WindowStyle
33-
public const long WS_CAPTION = 0x00C00000L;
34-
public const long WS_SYSMENU = 0x00080000L;
35-
public const long WS_POPUP = 0x80000000L;
36-
3732
// LayeredWindowAttributes
3833
public const int LWA_ALPHA = 0x00000002;
3934

WindowTextExtractor/Utils/WindowUtils.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,7 @@ public static void SetOpacity(IntPtr handle, byte opacity)
368368
User32.SetLayeredWindowAttributes(handle, 0, opacity, Constants.LWA_ALPHA);
369369
}
370370

371-
private static string GetWindowText(IntPtr handle)
371+
public static string GetWindowText(IntPtr handle)
372372
{
373373
var length = User32.GetWindowTextLength(handle);
374374
if (length > 0)

0 commit comments

Comments
 (0)