views:

237

answers:

3

Another clipboard question:

When text is put onto the clipboard, it frequently goes in multiple ways, usually with and without formatting information. What I want to know is this -- how do you change the text on the clipboard without altering the formatting. In other words, I want to change the text side of things, but keep the formatting exactly the same.

This is again for my "TextScrubber" application where I want to remove line breaks from the text on the clipboard, but I don't want to alter the format info about that text.

I'm hoping that I don't have to "brute force" it by iterating over all the formats present, storing each, and then reinserting them after the text has been scrubbed.

+6  A: 

I think the "brute force" is precisely what you'll have to do - according to MSDN Win32 API there is no way to do otherwise.

Andrew Y
Seconded.xxxxxx
gabr
A: 

Why not simply load from the clipboard, change the text, and write back to the clipboard?

Maybe something simple like Sergey Tkachenko's TBin Clipboard: http://delphi32.org/vcl/2889/

Eric Rosenberger's answer to "Can not round trip html format to clipboard" might also be of use.

lkessler
That's the "brute force" way he talked about. Store it, scrub it, and re-insert it into the clipboard.
Rob Kennedy
+3  A: 

Yep, Nick. I think in this case you're going to be stuck with the solution already suggested. The clipboard is one area that hasn't really gotten much attention in the enhancement department throughout the years. That is probably because it does need to be simple, ubiquitous, and functional.

Allen Bauer