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. insert text into notepad

insert text into notepad

Scheduled Pinned Locked Moved C / C++ / MFC
tutorialquestion
11 Posts 6 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.
  • C Offline
    C Offline
    color Aljechin
    wrote on last edited by
    #1

    i am trying to insert text into notepad.

    CWnd *myWnd = FindWindow(_T("Notepad"), _T("Untitled - Notepad"));
    if(myWnd)
    {
    ::PostMessage(myWnd->GetSafeHwnd(),WM_CHAR,(BYTE)'a',0x000e0001);
    //::PostMessage(myWnd->GetSafeHwnd(),WM_DESTROY,0,0);
    }

    if i enable the second line, notepad is quitting. how to insert a character? it is not working.

    :rose:

    I B R 3 Replies Last reply
    0
    • C color Aljechin

      i am trying to insert text into notepad.

      CWnd *myWnd = FindWindow(_T("Notepad"), _T("Untitled - Notepad"));
      if(myWnd)
      {
      ::PostMessage(myWnd->GetSafeHwnd(),WM_CHAR,(BYTE)'a',0x000e0001);
      //::PostMessage(myWnd->GetSafeHwnd(),WM_DESTROY,0,0);
      }

      if i enable the second line, notepad is quitting. how to insert a character? it is not working.

      :rose:

      I Offline
      I Offline
      Iain Clarke Warrior Programmer
      wrote on last edited by
      #2

      http://dictionary.reference.com/browse/destroy[^] Destroy:

      1. to reduce (an object) to useless fragments, a useless form, or remains, as by rending, burning, or dissolving; injure beyond repair or renewal; demolish; ruin; annihilate.

      You're getting the main window for notepad.exe - so it shouldn't come as a great shock that if you send a DESTROY! message, it closes. What did you expect? Even if you actually had the text area for notepad, why on earth would you think WM_DESTROY would help you put a character there? I hope I'm missing out on something in your question that you didn't write down. Your idea of sending a WM_CHAR isn't bad - but you're sending it to the main window for the application. If I use Spy++ on notepad, there are two child windows - a big edit one, and a status bar window. You could get the child window, and try sending the WM_CHAR to that. But that is implementation dependent. For all I know, notepad.exe under Vista is built completely differently. Maybe it uses a richedit window, rather than an edit one? Or Notepad under windows 2000 didn't have subwindows, it just worked as you expected. I would have a look at WM_PASTE message. It's likely the notepad's parent window would pass it on to the child edit window to handle, and that would paste the contents of the clipboard into notepad. It is harder to set up some text on the clipboard - but there are samples on codeproject - and it would allow you to do more than one letter at a time. I hope that helps, Iain.

      Iain Clarke appearing in spite of being begged not to by CPallini.

      CPalliniC C 2 Replies Last reply
      0
      • C color Aljechin

        i am trying to insert text into notepad.

        CWnd *myWnd = FindWindow(_T("Notepad"), _T("Untitled - Notepad"));
        if(myWnd)
        {
        ::PostMessage(myWnd->GetSafeHwnd(),WM_CHAR,(BYTE)'a',0x000e0001);
        //::PostMessage(myWnd->GetSafeHwnd(),WM_DESTROY,0,0);
        }

        if i enable the second line, notepad is quitting. how to insert a character? it is not working.

        :rose:

        B Offline
        B Offline
        baerten
        wrote on last edited by
        #3

        I'm not an expert on such operations but do you have tried it already with a WM_KEY_DOWN?

        CPalliniC 1 Reply Last reply
        0
        • I Iain Clarke Warrior Programmer

          http://dictionary.reference.com/browse/destroy[^] Destroy:

          1. to reduce (an object) to useless fragments, a useless form, or remains, as by rending, burning, or dissolving; injure beyond repair or renewal; demolish; ruin; annihilate.

          You're getting the main window for notepad.exe - so it shouldn't come as a great shock that if you send a DESTROY! message, it closes. What did you expect? Even if you actually had the text area for notepad, why on earth would you think WM_DESTROY would help you put a character there? I hope I'm missing out on something in your question that you didn't write down. Your idea of sending a WM_CHAR isn't bad - but you're sending it to the main window for the application. If I use Spy++ on notepad, there are two child windows - a big edit one, and a status bar window. You could get the child window, and try sending the WM_CHAR to that. But that is implementation dependent. For all I know, notepad.exe under Vista is built completely differently. Maybe it uses a richedit window, rather than an edit one? Or Notepad under windows 2000 didn't have subwindows, it just worked as you expected. I would have a look at WM_PASTE message. It's likely the notepad's parent window would pass it on to the child edit window to handle, and that would paste the contents of the clipboard into notepad. It is harder to set up some text on the clipboard - but there are samples on codeproject - and it would allow you to do more than one letter at a time. I hope that helps, Iain.

          Iain Clarke appearing in spite of being begged not to by CPallini.

          CPalliniC Offline
          CPalliniC Offline
          CPallini
          wrote on last edited by
          #4

          Iain Clarke wrote:

          Iain Clarke appearing in spite of being begged not to by CPallini.

          :-D

          If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
          [my articles]

          In testa che avete, signor di Ceprano?

          I C 2 Replies Last reply
          0
          • B baerten

            I'm not an expert on such operations but do you have tried it already with a WM_KEY_DOWN?

            CPalliniC Offline
            CPalliniC Offline
            CPallini
            wrote on last edited by
            #5

            baerten wrote:

            WM_KEY_DOWN

            Uhmmm, are you sure the notepad is aware of such a message? :-D

            If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
            [my articles]

            In testa che avete, signor di Ceprano?

            1 Reply Last reply
            0
            • CPalliniC CPallini

              Iain Clarke wrote:

              Iain Clarke appearing in spite of being begged not to by CPallini.

              :-D

              If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
              [my articles]

              I Offline
              I Offline
              Iain Clarke Warrior Programmer
              wrote on last edited by
              #6

              I was wondering when you'd spot that... I'm going to have to change it now! Iain.

              Iain Clarke appearing in spite of being begged not to by CPallini.

              1 Reply Last reply
              0
              • I Iain Clarke Warrior Programmer

                http://dictionary.reference.com/browse/destroy[^] Destroy:

                1. to reduce (an object) to useless fragments, a useless form, or remains, as by rending, burning, or dissolving; injure beyond repair or renewal; demolish; ruin; annihilate.

                You're getting the main window for notepad.exe - so it shouldn't come as a great shock that if you send a DESTROY! message, it closes. What did you expect? Even if you actually had the text area for notepad, why on earth would you think WM_DESTROY would help you put a character there? I hope I'm missing out on something in your question that you didn't write down. Your idea of sending a WM_CHAR isn't bad - but you're sending it to the main window for the application. If I use Spy++ on notepad, there are two child windows - a big edit one, and a status bar window. You could get the child window, and try sending the WM_CHAR to that. But that is implementation dependent. For all I know, notepad.exe under Vista is built completely differently. Maybe it uses a richedit window, rather than an edit one? Or Notepad under windows 2000 didn't have subwindows, it just worked as you expected. I would have a look at WM_PASTE message. It's likely the notepad's parent window would pass it on to the child edit window to handle, and that would paste the contents of the clipboard into notepad. It is harder to set up some text on the clipboard - but there are samples on codeproject - and it would allow you to do more than one letter at a time. I hope that helps, Iain.

                Iain Clarke appearing in spite of being begged not to by CPallini.

                C Offline
                C Offline
                color Aljechin
                wrote on last edited by
                #7

                Iain Clarke wrote:

                I hope I'm missing out on something in your question that you didn't write down.

                i mean the destroy msg is working and the wm keydown msg was not working. destroy is commented. paste is not working. any other alternative? thanks for the reply.

                :rose:

                M 1 Reply Last reply
                0
                • CPalliniC CPallini

                  Iain Clarke wrote:

                  Iain Clarke appearing in spite of being begged not to by CPallini.

                  :-D

                  If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
                  [my articles]

                  C Offline
                  C Offline
                  color Aljechin
                  wrote on last edited by
                  #8

                  can u please tell me how to get the handle of notepad's edit window/

                  :rose:

                  CPalliniC 1 Reply Last reply
                  0
                  • C color Aljechin

                    can u please tell me how to get the handle of notepad's edit window/

                    :rose:

                    CPalliniC Offline
                    CPalliniC Offline
                    CPallini
                    wrote on last edited by
                    #9

                    What about EnumChildWindows [^]? :)

                    If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
                    [my articles]

                    In testa che avete, signor di Ceprano?

                    1 Reply Last reply
                    0
                    • C color Aljechin

                      i am trying to insert text into notepad.

                      CWnd *myWnd = FindWindow(_T("Notepad"), _T("Untitled - Notepad"));
                      if(myWnd)
                      {
                      ::PostMessage(myWnd->GetSafeHwnd(),WM_CHAR,(BYTE)'a',0x000e0001);
                      //::PostMessage(myWnd->GetSafeHwnd(),WM_DESTROY,0,0);
                      }

                      if i enable the second line, notepad is quitting. how to insert a character? it is not working.

                      :rose:

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

                      a plain dump solution, activate the notepad application and generate keyboard event (keybd_event() API)

                      modified on Thursday, February 07, 2008 6:54:00 AM

                      1 Reply Last reply
                      0
                      • C color Aljechin

                        Iain Clarke wrote:

                        I hope I'm missing out on something in your question that you didn't write down.

                        i mean the destroy msg is working and the wm keydown msg was not working. destroy is commented. paste is not working. any other alternative? thanks for the reply.

                        :rose:

                        M Offline
                        M Offline
                        Mark Salsbery
                        wrote on last edited by
                        #11

                        Aljechin wrote:

                        i mean the destroy msg is working

                        WM_DESTROY is a notification message from the system. Sending it to a window that actually isn't being destroyed isn't going to do anything except possibly leave the target application in an unstable state. What are you expecting sending that message to do? Mark

                        Mark Salsbery Microsoft MVP - Visual C++ :java:

                        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