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. Setting the text in an edit box of another application

Setting the text in an edit box of another application

Scheduled Pinned Locked Moved C / C++ / MFC
question
11 Posts 4 Posters 3 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.
  • S Still learning how to code

    I am trying to interact programmatically with another application, and have succeeded in finding the handle of the correct edit box in the application's dialog. However, I can't seem to find a way to send text to the dialog control. The MSDN documetation for ::SetWindowText() states that it cannot be used to modify the text in another application. What other means is there to achieve the text transfer ? Doug

    S Offline
    S Offline
    Still learning how to code
    wrote on last edited by
    #2

    I have now managed to copy the text to the clipboard, and then send a WM_PASTE message to the other application. This works, but is it the only way to achieve this transfer ? Doug

    enhzflepE 1 Reply Last reply
    0
    • S Still learning how to code

      I have now managed to copy the text to the clipboard, and then send a WM_PASTE message to the other application. This works, but is it the only way to achieve this transfer ? Doug

      enhzflepE Offline
      enhzflepE Offline
      enhzflep
      wrote on last edited by
      #3

      Personally, I'd use WM_SETTEXT[^]. It's what SetWindowText uses internally.

      J S 2 Replies Last reply
      0
      • enhzflepE enhzflep

        Personally, I'd use WM_SETTEXT[^]. It's what SetWindowText uses internally.

        J Offline
        J Offline
        Jackson2010
        wrote on last edited by
        #4

        WM_SETTEXT is used to set the text of a window.

        Working is a happy thing! Enjoy the free partition manager!

        enhzflepE 1 Reply Last reply
        0
        • J Jackson2010

          WM_SETTEXT is used to set the text of a window.

          Working is a happy thing! Enjoy the free partition manager!

          enhzflepE Offline
          enhzflepE Offline
          enhzflep
          wrote on last edited by
          #5

          Which is precisely why I'd use it. Recall that an edit control may be created thusly:

          hwndEdit = CreateWindowEx(0, WC_EDIT, 0, WS_VISIBLE | WS_CHILD | WS_TABSTOP | WS_BORDER | ES_AUTOHSCROLL, 11, 11, 147, 23, hwnd, (HMENU)IDC_EDIT1, hInst, 0);

          Where

          • hwndEdit is derclared of type HWND
          • hwnd holds the parents HWND
          • hInst holds HINSTANCE of the program
          • IDC_EDIT has been defined as an integer used to identify messages from this control
          1 Reply Last reply
          0
          • enhzflepE enhzflep

            Personally, I'd use WM_SETTEXT[^]. It's what SetWindowText uses internally.

            S Offline
            S Offline
            Still learning how to code
            wrote on last edited by
            #6

            Yes, I originally made an error in using SendMessage in the way that I set up lParam !!! I've got it working now ! (Much neater than using the clipboard !) So, if ::SetWindowText() ultimately uses WM_SETTEXT, then it begs the question as to why MS doe not allow it to act on "other applications" windows ?? Doug

            L 1 Reply Last reply
            0
            • S Still learning how to code

              Yes, I originally made an error in using SendMessage in the way that I set up lParam !!! I've got it working now ! (Much neater than using the clipboard !) So, if ::SetWindowText() ultimately uses WM_SETTEXT, then it begs the question as to why MS doe not allow it to act on "other applications" windows ?? Doug

              L Offline
              L Offline
              Luc Pattyn
              wrote on last edited by
              #7

              Probably because SETTEXT needs a pointer to the text, and that pointer must be valid in the destination app's address space. :)

              Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum

              Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.

              S 1 Reply Last reply
              0
              • L Luc Pattyn

                Probably because SETTEXT needs a pointer to the text, and that pointer must be valid in the destination app's address space. :)

                Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum

                Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.

                S Offline
                S Offline
                Still learning how to code
                wrote on last edited by
                #8

                << Probably because SETTEXT needs a pointer to the text, and that pointer must be valid in the destination app's address space. >> But if SetWindowText() ends up using SendMessage, the text is in lParam. I'm confused ......... !! Doug

                L 2 Replies Last reply
                0
                • S Still learning how to code

                  << Probably because SETTEXT needs a pointer to the text, and that pointer must be valid in the destination app's address space. >> But if SetWindowText() ends up using SendMessage, the text is in lParam. I'm confused ......... !! Doug

                  L Offline
                  L Offline
                  Luc Pattyn
                  wrote on last edited by
                  #9

                  you're welcome. FYI: there are Win32 system calls that help you pass arbitrary amounts of data from one process to another; my LP#TrayIconBuster[^] article has an LP_Process class that shows how it's done in C#; similar techniques could be used in C/C++. :)

                  Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum

                  Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.

                  1 Reply Last reply
                  0
                  • S Still learning how to code

                    << Probably because SETTEXT needs a pointer to the text, and that pointer must be valid in the destination app's address space. >> But if SetWindowText() ends up using SendMessage, the text is in lParam. I'm confused ......... !! Doug

                    L Offline
                    L Offline
                    Luc Pattyn
                    wrote on last edited by
                    #10

                    lParam holds the pointer to the text, and is assumed to be a valid pointer within the process' address space. It can not be an address in some other process. :)

                    Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum

                    Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.

                    S 1 Reply Last reply
                    0
                    • L Luc Pattyn

                      lParam holds the pointer to the text, and is assumed to be a valid pointer within the process' address space. It can not be an address in some other process. :)

                      Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum

                      Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.

                      S Offline
                      S Offline
                      Still learning how to code
                      wrote on last edited by
                      #11

                      >>Param holds the pointer to the text, and is assumed to be a valid pointer within the process' address space. It can not be an address in some other process.<< Thanks for your patience, Luc !! So that I can just FULLY understand this, let me describe it back to you with a few extra words (!!):- The issuer of SendMessage() holds the variable containing the text (my app, in this case), and lParam is set up containing an address to this variable (within the senders address space ?). The receiver of SendMessage()(the 3rd party app, with which i'm endeavouring to interact) has access to lParam which contains the address of the original text, but as I'm alluding to above, is this address within the sender's address space ? I suspect that somewhere within the process, the text is COPIED to some global address space and it is THIS address that is contained within lParam. I can't see how else the process can work whilst protecting each app's memory space. I await your words of wisdom, and to be "sorted out" !! Again, thanks for your patience ! Doug

                      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