Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Get text from the focused control in another window

Get text from the focused control in another window

Scheduled Pinned Locked Moved C / C++ / MFC
helptutorialquestion
10 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    nc3b
    wrote on last edited by
    #1

    Hello. I have the hwnd of another window and I am trying to get the text. I know how to get text from another window (WM_GETTEXT) but I don't know hot to get the text from the currently focused control in that window. Unfortunately GetFocus() won't work so I am out of ideas.. I would even try using EnumChildWindows, but I don't know how to find out if a particular control is focused. Can anybody help? Thank you in advance.

    D C 2 Replies Last reply
    0
    • N nc3b

      Hello. I have the hwnd of another window and I am trying to get the text. I know how to get text from another window (WM_GETTEXT) but I don't know hot to get the text from the currently focused control in that window. Unfortunately GetFocus() won't work so I am out of ideas.. I would even try using EnumChildWindows, but I don't know how to find out if a particular control is focused. Can anybody help? Thank you in advance.

      D Offline
      D Offline
      David Crow
      wrote on last edited by
      #2

      nc3b wrote:

      Unfortunately GetFocus() won't work...

      Is it because the window (containing the control) is in another thread?

      "Love people and use things, not love things and use people." - Unknown

      "The brick walls are there for a reason...to stop the people who don't want it badly enough." - Randy Pausch

      N 1 Reply Last reply
      0
      • D David Crow

        nc3b wrote:

        Unfortunately GetFocus() won't work...

        Is it because the window (containing the control) is in another thread?

        "Love people and use things, not love things and use people." - Unknown

        "The brick walls are there for a reason...to stop the people who don't want it badly enough." - Randy Pausch

        N Offline
        N Offline
        nc3b
        wrote on last edited by
        #3

        Yes, it's in a different program.

        D 1 Reply Last reply
        0
        • N nc3b

          Yes, it's in a different program.

          D Offline
          D Offline
          David Crow
          wrote on last edited by
          #4

          Then you may need to use GetGUIThreadInfo() first.

          "Love people and use things, not love things and use people." - Unknown

          "The brick walls are there for a reason...to stop the people who don't want it badly enough." - Randy Pausch

          N 1 Reply Last reply
          0
          • N nc3b

            Hello. I have the hwnd of another window and I am trying to get the text. I know how to get text from another window (WM_GETTEXT) but I don't know hot to get the text from the currently focused control in that window. Unfortunately GetFocus() won't work so I am out of ideas.. I would even try using EnumChildWindows, but I don't know how to find out if a particular control is focused. Can anybody help? Thank you in advance.

            C Offline
            C Offline
            Code o mat
            wrote on last edited by
            #5

            I am assuming you mean getting who has the focus in a different process, so try this[^] for size.

            > The problem with computers is that they do what you tell them to do and not what you want them to do. < > Life: great graphics, but the gameplay sux. <

            1 Reply Last reply
            0
            • D David Crow

              Then you may need to use GetGUIThreadInfo() first.

              "Love people and use things, not love things and use people." - Unknown

              "The brick walls are there for a reason...to stop the people who don't want it badly enough." - Randy Pausch

              N Offline
              N Offline
              nc3b
              wrote on last edited by
              #6

              Can you please give an example? Suppose I have a HWND of a window (GetForegroundWindow()) and wnat to get it's focused child. How would I do that? Thank you.

              D R 2 Replies Last reply
              0
              • N nc3b

                Can you please give an example? Suppose I have a HWND of a window (GetForegroundWindow()) and wnat to get it's focused child. How would I do that? Thank you.

                D Offline
                D Offline
                David Crow
                wrote on last edited by
                #7

                First you need to get the list of processes that are running to find the one you are interested in. This can be done by calling CreateToolhelpSnapshot(), and then looping through each one with the ProcessFirst()/ProcessNext() pair. Once found, use the PID as the first argument to GetGUIThreadInfo().

                "Love people and use things, not love things and use people." - Unknown

                "The brick walls are there for a reason...to stop the people who don't want it badly enough." - Randy Pausch

                N 1 Reply Last reply
                0
                • D David Crow

                  First you need to get the list of processes that are running to find the one you are interested in. This can be done by calling CreateToolhelpSnapshot(), and then looping through each one with the ProcessFirst()/ProcessNext() pair. Once found, use the PID as the first argument to GetGUIThreadInfo().

                  "Love people and use things, not love things and use people." - Unknown

                  "The brick walls are there for a reason...to stop the people who don't want it badly enough." - Randy Pausch

                  N Offline
                  N Offline
                  nc3b
                  wrote on last edited by
                  #8

                  And then "hwndFocus" will contain the hwnd of the curently focused control? Thanks!

                  1 Reply Last reply
                  0
                  • N nc3b

                    Can you please give an example? Suppose I have a HWND of a window (GetForegroundWindow()) and wnat to get it's focused child. How would I do that? Thank you.

                    R Offline
                    R Offline
                    Rajkumar R
                    wrote on last edited by
                    #9

                    consider [GetWindowThreadProcessId^] also for getting the processid of the foreground window and thread id needed for GetGUIThreadInfo

                    N 1 Reply Last reply
                    0
                    • R Rajkumar R

                      consider [GetWindowThreadProcessId^] also for getting the processid of the foreground window and thread id needed for GetGUIThreadInfo

                      N Offline
                      N Offline
                      nc3b
                      wrote on last edited by
                      #10

                      Thank you!

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups