I've been struggling for a while now with retrieving the highlighted/selected text from a window. I've used:

GetForegroundWindow
GetCursorPos
WindowFromPoint
SendMessage(... GETTEXT...)/SendMessage(...GETSELTEXT...)

But the best I can do is on some windows get back the entire text. In Word, IE, Firefox, etc. I get nothing back. I'm using C# to make the API calls but if anyone knows how to do it in any language, I would appreciate it.