Custom Copy/Paste

This is a discussion on Custom Copy/Paste within the Windows Programming forums, part of the Platform Specific Boards category; Can you simulate the copy/paste mechanism of windows? So you would have a program that can read selected text and ...

  1. #1
    Registered User C_ntua's Avatar
    Join Date
    Jun 2008
    Posts
    1,853

    Custom Copy/Paste

    Can you simulate the copy/paste mechanism of windows? So you would have a program that can read selected text and write text where the cursor is.

  2. #2
    System Novice siavoshkc's Avatar
    Join Date
    Jan 2006
    Location
    Tehran
    Posts
    1,231
    Yes its possible.

    If you have a program that needs Copy/Paste functionality its fairly easy. But if you want to make a program that services other application, first its not a good idea, second you may need hooks.
    Learn C++ (C++ Books, C Books, FAQ, Forum Search)
    Code painter latest version on sourceforge DOWNLOAD NOW!
    Download FSB Data Integrity Tester.
    Siavosh K C

  3. #3
    Registered User C_ntua's Avatar
    Join Date
    Jun 2008
    Posts
    1,853
    I am looking fro the second, a program where it could service other applications.
    Why it is not a good idea? The idea is to be able to create multiple clipboards shared through a network. I could use the standard clipboard when somebody tries to custom paste, but that is not the fastest way.
    Can you elaborate a little about hooks? In what way would I do this?

  4. #4
    System Novice siavoshkc's Avatar
    Join Date
    Jan 2006
    Location
    Tehran
    Posts
    1,231
    The programs that use clipboard in Windows use components that are clipboard aware. Its a Windows service that programs use. You cannot make programs use a facility they don't know about without modifying their code.

    One way is to replace Windows clipboard which I don't know how.

    Another way is to place a layer between user and program which intecepts mouse and keyboard events. This way you can for example copy a text into your own clipboard using your shoosen shortcut key (exp. Ctrl+Middle Mouse Button). To be able to do so you must use a Win32 functionality named hook and inject your code into other programs memory space. I say its bad because if your hook crashes it will crash other applications, it will slow down system and many anti virus programs will stop your program.

    I see hooks as an advance programming area. Use MSDN and other tutorials to know more about it. See my sig.
    Learn C++ (C++ Books, C Books, FAQ, Forum Search)
    Code painter latest version on sourceforge DOWNLOAD NOW!
    Download FSB Data Integrity Tester.
    Siavosh K C

  5. #5
    Registered User C_ntua's Avatar
    Join Date
    Jun 2008
    Posts
    1,853
    Hmmm. I will read about hooks.
    Though, kind of thinking about it, I see it impossible to do this without the help of the standard clipboard. Because I would have to add a function to every clipboard saying "print data from here". Applications just have the functionality "print from the clipboard". Except if there is a built-in functionality "print from this memory section"? In which case I could use a hook to add information on that section.

    If I go with standard clipboard. Something like
    1) Copy information to memory with specific keystroke
    2) When pasting with specific clipboard, save standard clipboard in memory
    3) Copy information from 1) to standard clipboard
    4) Paste standard clipboard
    5) Copy the saved clipboard from 2) to standard clipboard

    I don't like the 3 added copies.

  6. #6
    Registered User C_ntua's Avatar
    Join Date
    Jun 2008
    Posts
    1,853
    I made what I wanted, but browsers don't let you copy thinks by sending ctrl+c. Does anybody have any idea why? Searching a lot, I see it is a common issue, but didn't understand why.
    My workaround is sending a alt+e+c signal so it opens the edit menu of a browser and pressed the copy command.

    I used all possible functions (keybd_event, SendInput, SendMessage) with the same result. It seems to be an issue with some other external programs as well, though they are some (like AutoKeyboard) that work.

    Elaborating a bit, you sent a keyboard input in the system. Since the browser is the active window it will receive them. Which it does with other inputs. But it simply doesn't copy selected text in the clipboard. I was thinking that this might be a security issue, but if that was a cause it would block all inputs and don't allow my workaround.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How do I put this code into custom classes?
    By boblablabla in forum C++ Programming
    Replies: 4
    Last Post: 12-07-2009, 10:01 AM
  2. Custom Allocation
    By SevenThunders in forum C Programming
    Replies: 17
    Last Post: 04-09-2007, 04:10 PM
  3. Stl sets and custom classes.
    By cunnus88 in forum C++ Programming
    Replies: 3
    Last Post: 05-12-2006, 11:58 PM
  4. Requesting Affirmation [pointer 2 custom class]
    By Deo in forum C++ Programming
    Replies: 5
    Last Post: 06-09-2005, 12:02 PM
  5. Clipboard and Custom Types
    By McClamm in forum C# Programming
    Replies: 1
    Last Post: 09-16-2004, 04:43 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21