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. How can send message to an notepad ? [modified]

How can send message to an notepad ? [modified]

Scheduled Pinned Locked Moved C / C++ / MFC
question
6 Posts 5 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.
  • M Offline
    M Offline
    mesajflaviu
    wrote on last edited by
    #1

    I open an notepad application :

    void CTestMessageView::OnHelpStartapplication()
    {
    // TODO: Add your command handler code here

    ShellExecute(m\_hWnd,"open","notepad.exe",NULL,NULL,SW\_SHOWNORMAL);
    

    }

    and I want to send some message to notepad :

    void CTestMessageView::OnHelpSendmessage()
    {
    // TODO: Add your command handler code here

    CString sTemp = "Test message\\n";
    
    HWND hWnd = ::FindWindow("Notepad",NULL);
    if(hWnd)
    {
    

    // ::PostMessage(hWnd,WM_CLOSE,0,0);
    ::PostMessage(hWnd,WM_CHAR,(WPARAM)'1',0);
    ::PostMessage(hWnd,WM_KEYDOWN,'1',0);
    ::PostMessage(hWnd,WM_SETTEXT,0,(LPARAM)(LPCTSTR)sTemp);
    ::PostMessage(hWnd,EM_REPLACESEL,0,(LPARAM)(LPCTSTR)sTemp);
    }
    }

    but only first message WM_CLOSE ( comment one ) is receipt by notepad , other , not . I think that other message then WM_CLOSE is addressed for view of notepad , not the main frame window of the notepad . My question is , how can I send message to the view , not the main frame window of notepad ?

    modified on Saturday, January 1, 2011 9:13 AM

    E _ L 3 Replies Last reply
    0
    • M mesajflaviu

      I open an notepad application :

      void CTestMessageView::OnHelpStartapplication()
      {
      // TODO: Add your command handler code here

      ShellExecute(m\_hWnd,"open","notepad.exe",NULL,NULL,SW\_SHOWNORMAL);
      

      }

      and I want to send some message to notepad :

      void CTestMessageView::OnHelpSendmessage()
      {
      // TODO: Add your command handler code here

      CString sTemp = "Test message\\n";
      
      HWND hWnd = ::FindWindow("Notepad",NULL);
      if(hWnd)
      {
      

      // ::PostMessage(hWnd,WM_CLOSE,0,0);
      ::PostMessage(hWnd,WM_CHAR,(WPARAM)'1',0);
      ::PostMessage(hWnd,WM_KEYDOWN,'1',0);
      ::PostMessage(hWnd,WM_SETTEXT,0,(LPARAM)(LPCTSTR)sTemp);
      ::PostMessage(hWnd,EM_REPLACESEL,0,(LPARAM)(LPCTSTR)sTemp);
      }
      }

      but only first message WM_CLOSE ( comment one ) is receipt by notepad , other , not . I think that other message then WM_CLOSE is addressed for view of notepad , not the main frame window of the notepad . My question is , how can I send message to the view , not the main frame window of notepad ?

      modified on Saturday, January 1, 2011 9:13 AM

      E Offline
      E Offline
      Espen Harlinn
      wrote on last edited by
      #2

      Do an EnumChildWindows[^] on your hWnd and locate the edit control Regards Espen Harlinn

      M 1 Reply Last reply
      0
      • E Espen Harlinn

        Do an EnumChildWindows[^] on your hWnd and locate the edit control Regards Espen Harlinn

        M Offline
        M Offline
        mesajflaviu
        wrote on last edited by
        #3

        Thanks , can you give me an little sample code of what I get of the view child window ?

        modified on Saturday, January 1, 2011 11:00 AM

        1 Reply Last reply
        0
        • M mesajflaviu

          I open an notepad application :

          void CTestMessageView::OnHelpStartapplication()
          {
          // TODO: Add your command handler code here

          ShellExecute(m\_hWnd,"open","notepad.exe",NULL,NULL,SW\_SHOWNORMAL);
          

          }

          and I want to send some message to notepad :

          void CTestMessageView::OnHelpSendmessage()
          {
          // TODO: Add your command handler code here

          CString sTemp = "Test message\\n";
          
          HWND hWnd = ::FindWindow("Notepad",NULL);
          if(hWnd)
          {
          

          // ::PostMessage(hWnd,WM_CLOSE,0,0);
          ::PostMessage(hWnd,WM_CHAR,(WPARAM)'1',0);
          ::PostMessage(hWnd,WM_KEYDOWN,'1',0);
          ::PostMessage(hWnd,WM_SETTEXT,0,(LPARAM)(LPCTSTR)sTemp);
          ::PostMessage(hWnd,EM_REPLACESEL,0,(LPARAM)(LPCTSTR)sTemp);
          }
          }

          but only first message WM_CLOSE ( comment one ) is receipt by notepad , other , not . I think that other message then WM_CLOSE is addressed for view of notepad , not the main frame window of the notepad . My question is , how can I send message to the view , not the main frame window of notepad ?

          modified on Saturday, January 1, 2011 9:13 AM

          _ Offline
          _ Offline
          _Superman_
          wrote on last edited by
          #4

          What exactly are you trying to do here? Opening notepad and then sending it a WM_CLOSE does not make sense. Notepad also takes a command line parameter if you want to open a file in it. For eample - notepad.exe c:\windows\win.ini

          «_Superman_»  _I love work. It gives me something to do between weekends.

          _Microsoft MVP (Visual C++)

          Polymorphism in C

          N 1 Reply Last reply
          0
          • _ _Superman_

            What exactly are you trying to do here? Opening notepad and then sending it a WM_CLOSE does not make sense. Notepad also takes a command line parameter if you want to open a file in it. For eample - notepad.exe c:\windows\win.ini

            «_Superman_»  _I love work. It gives me something to do between weekends.

            _Microsoft MVP (Visual C++)

            Polymorphism in C

            N Offline
            N Offline
            normanS
            wrote on last edited by
            #5

            I think he's trying to open Notepad and insert some text (the sTemp string.) What he's found is 4 ways to insert text which do not work, and also found that sending a WM_CLOSE does work. It's a start.

            1 Reply Last reply
            0
            • M mesajflaviu

              I open an notepad application :

              void CTestMessageView::OnHelpStartapplication()
              {
              // TODO: Add your command handler code here

              ShellExecute(m\_hWnd,"open","notepad.exe",NULL,NULL,SW\_SHOWNORMAL);
              

              }

              and I want to send some message to notepad :

              void CTestMessageView::OnHelpSendmessage()
              {
              // TODO: Add your command handler code here

              CString sTemp = "Test message\\n";
              
              HWND hWnd = ::FindWindow("Notepad",NULL);
              if(hWnd)
              {
              

              // ::PostMessage(hWnd,WM_CLOSE,0,0);
              ::PostMessage(hWnd,WM_CHAR,(WPARAM)'1',0);
              ::PostMessage(hWnd,WM_KEYDOWN,'1',0);
              ::PostMessage(hWnd,WM_SETTEXT,0,(LPARAM)(LPCTSTR)sTemp);
              ::PostMessage(hWnd,EM_REPLACESEL,0,(LPARAM)(LPCTSTR)sTemp);
              }
              }

              but only first message WM_CLOSE ( comment one ) is receipt by notepad , other , not . I think that other message then WM_CLOSE is addressed for view of notepad , not the main frame window of the notepad . My question is , how can I send message to the view , not the main frame window of notepad ?

              modified on Saturday, January 1, 2011 9:13 AM

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

              you can't just pass pointers from one process to another process; they must be meaningful and accessible for the receiver, and in general buffers at the sender are neither to the receiver. It would take some calls to VirtualAllocEx, WriteProcessMemory, and the like to achieve such things. But then, why would you? if you want to open Notepad on an empty document and then "type" some, why not simply create a text file first, then open it with Notepad? You wouldn't need any Win32 API function to do that. :)

              Luc Pattyn [Forum Guidelines] [My Articles] [My CP bug tracking] Nil Volentibus Arduum

              Season's Greetings to all CPians.

              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