For Programmers: Free Programming Magazines  


Home > Archive > C# > May 2005 > Need to get the handle for active control... in other apps









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Need to get the handle for active control... in other apps
Kinryuu

2005-05-26, 3:59 pm

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#.

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com