Capturing selected text of last active window?

Would anyone out there know how to capture the selected text of the last
active application's currently focused window? For instance, if I selected
some text in a text file being displayed in notepad, I'd like to be able to
copy that from my program into a string.

This is what I have so far but all I can really figure out how to do is to
get the last active program's main window. I have no idea how to figure out
which child window it has in focus.

const
  MaxBuffLen = 1024;
var
  LastWindow: HWND;
  i: Integer;
  Buff: String;
begin
    LastWindow := GetNextWindow(Application.Handle, GW_HWNDNEXT);
    if LastWindow <> NULL then
    begin

{------------------------------------------------------------------------
I had this to try and figure out the appropriate child window but I don't
think it
works.

      LastWindow := GetTopWindow(LastWindow);
--------------------------------------------------------------------------}

      if LastWindow <> NULL then
      begin
        SetLength(Buff, MaxBuffLen);
        i := GetWindowText(LastWindow, PChar(Buff), MaxBuffLen);
        Inform(Copy(Buff, 1, i)); // This is just a dialog box that
displays a string with                                                                      
// the Inform graphic.
      end;
    end;
end;

So, the way it is right now, it will at least display the title of the last
active program (ie. Notepad's Caption Bar), but I really need to figure out
how to display the selected text of the document notepad is currently
editing.

thanks,
mike.