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 I paste data to other windows (who ever is accepting) ? [modified]

How can I paste data to other windows (who ever is accepting) ? [modified]

Scheduled Pinned Locked Moved C / C++ / MFC
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.
  • Y Offline
    Y Offline
    Yovav
    wrote on last edited by
    #1

    When I click a hot key combination (Ctrl+Shift+P) my program do copy some text to the clibboard, So I can paste it to any window by holding Ctrl+V Now I like to automate this and be able to do the Ctrl+V programatically, Lets assume I just want to paste just anything to other windows - so I can get started, I have tried this, but I guess I'm missing something: SendMessage(WM_PASTE, 0,0); also tried: BroadcastSystemMessage(BSF_POSTMESSAGE | BSF_IGNORECURRENTTASK, BSM_ALLCOMPONENTS, WM_PASTE, (WPARAM)NULL, (LPARAM)NULL); I'd like to broadcast a "paste" message (or "Ctrl+V") so I will not have to find the current active window and get its focus, Any suggestions ?

    Best Regards - Yovav Gad CEO and founder of MicroMighty, Inc.

    modified on Thursday, April 2, 2009 11:58 PM

    N I 2 Replies Last reply
    0
    • Y Yovav

      When I click a hot key combination (Ctrl+Shift+P) my program do copy some text to the clibboard, So I can paste it to any window by holding Ctrl+V Now I like to automate this and be able to do the Ctrl+V programatically, Lets assume I just want to paste just anything to other windows - so I can get started, I have tried this, but I guess I'm missing something: SendMessage(WM_PASTE, 0,0); also tried: BroadcastSystemMessage(BSF_POSTMESSAGE | BSF_IGNORECURRENTTASK, BSM_ALLCOMPONENTS, WM_PASTE, (WPARAM)NULL, (LPARAM)NULL); I'd like to broadcast a "paste" message (or "Ctrl+V") so I will not have to find the current active window and get its focus, Any suggestions ?

      Best Regards - Yovav Gad CEO and founder of MicroMighty, Inc.

      modified on Thursday, April 2, 2009 11:58 PM

      N Offline
      N Offline
      Niklas L
      wrote on last edited by
      #2

      I tried something similar a few yeras back to aid in filling in forms that required the same data over and over, and as far as I can remember, different applications needed different handling. You have to try sending keystrokes to some, and WM_PASTE to some, and some applications do not even use a window, but a custom made input and cannot be manipulated at all. Sorry, but to my knowledge there is no universal method that works everywhere.

      home

      Y 1 Reply Last reply
      0
      • Y Yovav

        When I click a hot key combination (Ctrl+Shift+P) my program do copy some text to the clibboard, So I can paste it to any window by holding Ctrl+V Now I like to automate this and be able to do the Ctrl+V programatically, Lets assume I just want to paste just anything to other windows - so I can get started, I have tried this, but I guess I'm missing something: SendMessage(WM_PASTE, 0,0); also tried: BroadcastSystemMessage(BSF_POSTMESSAGE | BSF_IGNORECURRENTTASK, BSM_ALLCOMPONENTS, WM_PASTE, (WPARAM)NULL, (LPARAM)NULL); I'd like to broadcast a "paste" message (or "Ctrl+V") so I will not have to find the current active window and get its focus, Any suggestions ?

        Best Regards - Yovav Gad CEO and founder of MicroMighty, Inc.

        modified on Thursday, April 2, 2009 11:58 PM

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

        In addition to Niklas' comments, I can see another problem. I'll pretend your idea works. You would then make EVERY top level window receive a paste message, so they'd all perform a paste. That includes explorer, Invisible windows controlling tray notification icons... And that may be a BAD THING(tm). Is it really so bad to have the user in control of their own PC? They spent the money on it, after all... Iain.

        In the process of moving to Sweden for love (awwww). If you're in Scandinavia and want an MVP on the payroll (or happy with a remote worker), give me a job!

        Y N 2 Replies Last reply
        0
        • N Niklas L

          I tried something similar a few yeras back to aid in filling in forms that required the same data over and over, and as far as I can remember, different applications needed different handling. You have to try sending keystrokes to some, and WM_PASTE to some, and some applications do not even use a window, but a custom made input and cannot be manipulated at all. Sorry, but to my knowledge there is no universal method that works everywhere.

          home

          Y Offline
          Y Offline
          Yovav
          wrote on last edited by
          #4

          Yea, you are probably right, I made some progress, however - it only works in some places (like notepad...) POINT pt; GetCursorPos(&pt); CWnd* editControl; editControl = WindowFromPoint(pt); editControl->GetFocus(); editControl->SendMessage(WM_PASTE, 0, 0); I also tried to programatically click Ctrl+V and cause a paste like this: ::SendMessage(GetForegroundWindow()->m_hWnd, WM_CHAR, 22, 0x56); But it seems to have the same problem - only works in some places (like notepad...) I wonder how can I better send the Ctrl+V and make the window/control think he got Ctrl+V clicked and do the paste for me (to which ever CEdit / CView control being used) Please let me know if you have any suggestions.

          Best Regards - Yovav Gad CEO and founder of MicroMighty, Inc.

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

            In addition to Niklas' comments, I can see another problem. I'll pretend your idea works. You would then make EVERY top level window receive a paste message, so they'd all perform a paste. That includes explorer, Invisible windows controlling tray notification icons... And that may be a BAD THING(tm). Is it really so bad to have the user in control of their own PC? They spent the money on it, after all... Iain.

            In the process of moving to Sweden for love (awwww). If you're in Scandinavia and want an MVP on the payroll (or happy with a remote worker), give me a job!

            Y Offline
            Y Offline
            Yovav
            wrote on last edited by
            #5

            Well, its not really a problem - because I am sending the "WM_PASTE" message only to that specific control on which the user had put the cursor on, POINT pt; GetCursorPos(&pt); editControl = WindowFromPoint(pt); editControl->GetFocus(); editControl->SendMessage(WM_PASTE, 0, 0); Also - the user is not going to lose control over anything, This program gonna help users run and paste data exactly like they want it.

            Best Regards - Yovav Gad CEO and founder of MicroMighty, Inc.

            1 Reply Last reply
            0
            • I Iain Clarke Warrior Programmer

              In addition to Niklas' comments, I can see another problem. I'll pretend your idea works. You would then make EVERY top level window receive a paste message, so they'd all perform a paste. That includes explorer, Invisible windows controlling tray notification icons... And that may be a BAD THING(tm). Is it really so bad to have the user in control of their own PC? They spent the money on it, after all... Iain.

              In the process of moving to Sweden for love (awwww). If you're in Scandinavia and want an MVP on the payroll (or happy with a remote worker), give me a job!

              N Offline
              N Offline
              Niklas L
              wrote on last edited by
              #6

              Iain Clarke wrote:

              Is it really so bad to have the user in control of their own PC?

              Well, yes and no :-D . In my specific case my friend got so tired of filling identical data (like company name and address) in some text fields over and over so I offerd a way to just put the cursor in the right place and hit a user defined short-cut-keystroke, et voila: User defined text -> clipboard -> edit control. I'm just saying there could be a good reason for doing this.

              home

              I D 2 Replies Last reply
              0
              • N Niklas L

                Iain Clarke wrote:

                Is it really so bad to have the user in control of their own PC?

                Well, yes and no :-D . In my specific case my friend got so tired of filling identical data (like company name and address) in some text fields over and over so I offerd a way to just put the cursor in the right place and hit a user defined short-cut-keystroke, et voila: User defined text -> clipboard -> edit control. I'm just saying there could be a good reason for doing this.

                home

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

                Well, my comment was more about the broadcast idea... I'll trust your domain expertise on this though. Or you mercenary desire for a customer to give you money! Iain.

                In the process of moving to Sweden for love (awwww). If you're in Scandinavia and want an MVP on the payroll (or happy with a remote worker), give me a job!

                1 Reply Last reply
                0
                • Y Yovav

                  Yea, you are probably right, I made some progress, however - it only works in some places (like notepad...) POINT pt; GetCursorPos(&pt); CWnd* editControl; editControl = WindowFromPoint(pt); editControl->GetFocus(); editControl->SendMessage(WM_PASTE, 0, 0); I also tried to programatically click Ctrl+V and cause a paste like this: ::SendMessage(GetForegroundWindow()->m_hWnd, WM_CHAR, 22, 0x56); But it seems to have the same problem - only works in some places (like notepad...) I wonder how can I better send the Ctrl+V and make the window/control think he got Ctrl+V clicked and do the paste for me (to which ever CEdit / CView control being used) Please let me know if you have any suggestions.

                  Best Regards - Yovav Gad CEO and founder of MicroMighty, Inc.

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

                  Yovav wrote:

                  I wonder how can I better send the Ctrl+V...

                  Have you tried keybd_event()?

                  "Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown

                  "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

                  1 Reply Last reply
                  0
                  • N Niklas L

                    Iain Clarke wrote:

                    Is it really so bad to have the user in control of their own PC?

                    Well, yes and no :-D . In my specific case my friend got so tired of filling identical data (like company name and address) in some text fields over and over so I offerd a way to just put the cursor in the right place and hit a user defined short-cut-keystroke, et voila: User defined text -> clipboard -> edit control. I'm just saying there could be a good reason for doing this.

                    home

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

                    Niklas Lindquist wrote:

                    I'm just saying there could be a good reason for doing this.

                    And calling BroadcastSystemMessage() is not a solution for that reason.

                    "Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown

                    "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

                    Y 1 Reply Last reply
                    0
                    • D David Crow

                      Niklas Lindquist wrote:

                      I'm just saying there could be a good reason for doing this.

                      And calling BroadcastSystemMessage() is not a solution for that reason.

                      "Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown

                      "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

                      Y Offline
                      Y Offline
                      Yovav
                      wrote on last edited by
                      #10

                      I don't understand exactly how the WM_PASTE message is getting picked up, but it might be safe to broardcast it everywhere if it only getting picked up in one place where the cursor and focus is, remember - my intention is to let the user who already have his cursor focused on some text control to paste specific data, but the user must put the focus first before it will do anything...

                      Best Regards - Yovav Gad CEO and founder of MicroMighty, Inc.

                      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