Get Selected Text from other application

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • cbbibleboy
    New Member
    • Apr 2007
    • 29

    Get Selected Text from other application

    Howdy!
    I need a bit of direction...
    I am in need (as the title suggests) of a way to get the selected text from any application. Of course, I understand I will need to get the application's handle, but that's no problem. I'm just not sure how I would go about getting the text after that. Is there an API that would help? This should work for all selected text in nearly all applications (Word, Works, Excel, IE, etc.).
    I've seen it done before so I know that it's possible, I'm just not sure where to go next...

    Thanks in advance!
  • AdrianH
    Recognized Expert Top Contributor
    • Feb 2007
    • 1251

    #2
    Originally posted by cbbibleboy
    Howdy!
    I need a bit of direction...
    I am in need (as the title suggests) of a way to get the selected text from any application. Of course, I understand I will need to get the application's handle, but that's no problem. I'm just not sure how I would go about getting the text after that. Is there an API that would help? This should work for all selected text in nearly all applications (Word, Works, Excel, IE, etc.).
    I've seen it done before so I know that it's possible, I'm just not sure where to go next...

    Thanks in advance!
    I'm not sure as to what you mean. Are you going to randomly go to different task windows and get the selected text in them? This doesn't make sense to me.

    You can read the clipboard. But that is an entirly different question.

    Could you clarify please.


    Adrian

    Comment

    • Banfa
      Recognized Expert Expert
      • Feb 2006
      • 9067

      #3
      Originally posted by cbbibleboy
      Of course, I understand I will need to get the application's handle, but that's no problem. I'm just not sure how I would go about getting the text after that.
      Having the application Window handle would not be good enough, you would need the handle of the actual window containing the text (at the very least).

      To understand what I have just said you need to understand that everything is a Window, when you see an editbox that editbox is, in fact, a window with a very specialised style. If you had the handle of the edit box window then you could request the selected text from it.

      When you view an application like Word then you are seeing many windows, there is the main frame window, this contains a window for the toolbar area, which contains a window for each tool bar which in turn contain a window for each button. Then there is also a window for the client area (where the text is drawn) and probably sub windows with-in that.

      It is possible to walk the window list of an application starting from the top most frame window using EnumChildWindow s but then you would have to try and ascertain if each window enumerated had selected text and if it was the text you where interested in.

      It sounds to me like you have set yourself quite a hard task if it is indeed possible.

      Comment

      • cbbibleboy
        New Member
        • Apr 2007
        • 29

        #4
        No, I know about the windows and such--I'm very experienced with low level window control (Win32, no MFC). I know I would need the child window, and again, that would be no problem.

        I've seen it (getting selected text) done before though, so I know it's possible.

        I just need to know how...

        Comment

        • AdrianH
          Recognized Expert Top Contributor
          • Feb 2007
          • 1251

          #5
          Originally posted by cbbibleboy
          No, I know about the windows and such--I'm very experienced with low level window control (Win32, no MFC). I know I would need the child window, and again, that would be no problem.

          I've seen it (getting selected text) done before though, so I know it's possible.

          I just need to know how...
          Go to sysinternals.co m. They had a lot of stuff there pretaining to window tools and development before being bought out by M$. They may have what you need.

          EDIT: If you find what you are looking for, perhaps you could post back here and let us know. I would be interested in your findings.



          Adrian

          Comment

          • Banfa
            Recognized Expert Expert
            • Feb 2006
            • 9067

            #6
            Originally posted by cbbibleboy
            I've seen it (getting selected text) done before though, so I know it's possible.

            I just need to know how...
            I suspect a combination of the WM_GETTEXT and EM_GETSEL messages.

            Comment

            • JohnTravolta
              New Member
              • May 2007
              • 1

              #7
              Originally posted by Banfa
              I suspect a combination of the WM_GETTEXT and EM_GETSEL messages.
              <snipped> or <snipped> might do the same job but they are not free (LOL).
              Last edited by Banfa; May 30 '07, 09:07 AM. Reason: URLs removed as per posting guidelines

              Comment

              Working...