EnumChildWindows and EM_GETSELTEXT

  • Thread starter Thread starter kinryuu
  • Start date Start date
K

kinryuu

I'm trying to write a program that captures selected text from the
active window. I have everything setup as far as getting the foreground
window (with GetForegroundWindow()) and I'm using EnumChildWindows to
iterate through the child windows until I get something useful.

The problem is that every single child window of the foreground window
returns a single space as the selected text, even if I know that a
control on that window has highlighted text.

Is EM_GETSELTEXT not the right message? I've also tried WM_GETTEXT and
that simply returns an empty string for each child window.

Here's the pertinent code:

public static bool Enum(int hwndChild, int lParam)
{
StringBuilder builder = new StringBuilder();
SendMessage(hwndChild, Win32.User.EM_GETSELTEXT, 50, builder);
if (builder.Length != 0)
{
buffer = builder.ToString();
return false;
}
else
{
return true;
}
}
 
Back
Top