Code Comments
Programming Forum and web based access to our favorite programming groups.My objective: To get selected text in the foreground window. That
selected text may be in any kind of control, in .NET apps, and in
unmanaged apps.
So far, I can get the foreground window and get the window's text using
GetForegroundWindow and SendMessage from the Win32 API. However, I'm
having a heck of a time getting the selected text from the app. Here's
some of the code I'm using:
IntPtr hwnd = GetForegroundWindow();
if (!hwnd.Equals(IntPtr.Zero))
{
StringBuilder builder = new StringBuilder();
int result = SendMessage(hwnd.ToInt32(), WM_GETTEXT, 50, builder);
buffer = builder.ToString();
}
So far, I'm thinking that I need to:
1) Get the handle for the active control in my foreground window.
2) Use EM_GETSELTEXT to retrieve the message... now if I only had the
const value for EM_GETSELTEXT, since I can't seem to find it online
anywhere.
So, those 2 steps are what I need help with.
Oh, my app is written in C#.
Post Follow-up to this messagePowered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.