473,395 Members | 2,798 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

How to detect BOTH text and (multiple?) images in the clipboard

Hi gurus

.Net 2.0

I'm on a project where I need to be able to detect if my clipboard contains BOTH images AND text (eg. when copying from a web page).

For some reason Clipboard.ContainsImage() only returns true if the clipboard contains one and only one image. I use Clipboard.GetDataObject().GetDataPresent(DataForma ts.Text) to detect the presence of text.

What I need to figure out is how to detect if the clipboard contains one or more images and/or text at the same time.

Can anyone help me out?

Thanks in advance...

./kroogar
Sep 1 '09 #1
8 8063
GaryTexmo
1,501 Expert 1GB
Have a look at this article...

http://www.codeproject.com/KB/shell/clipboard01.aspx

Good luck! :)
Sep 1 '09 #2
Thanks for the reply GaryTexmo but unfortunately it didn't help :-(

The example works only when trying to detect bitmap images but pasting any other format doesn't work. E.g. when copying both images and text from Internet Explorer the sample code is inadequate.

So I'm back to square one :-(
Sep 2 '09 #3
GaryTexmo
1,501 Expert 1GB
Darn, I had thought the section entitled Maintain multiple formats in the Clipboard where they paste both images and text was right up your alley, but I guess that's a single instance of one or the other, isn't it?

I don't know much about this object. I was looking at it but I couldn't see a way to find the data that was actually on the clipboard. It seems the Clipboard class only lets you ask for a type of data... which is downright weird if you ask me. I googled around and couldn't see anything helpful.

If you do copy a group of images and pictures from IE, what exactly do you find in the Clipboard with your code?
Sep 2 '09 #4
Plater
7,872 Expert 4TB
Here's a little snipit that might help you out:
Expand|Select|Wrap|Line Numbers
  1. DataObject ido = (DataObject)Clipboard.GetDataObject();
  2. string[] formats = ido.GetFormats();
  3. foreach (string f in formats)
  4. {
  5.    object o = ido.GetData(f);
  6. //you can use o.GetType() to see the actual type, but the string f should also have it
  7. }
  8.  
Sep 2 '09 #5
Thanks for your effort guys - appreciate it

Using Platers snippet (thanks P) I get the following result when copy/pasting from Firefox (FF) and Internet Explorer (IE). The results are "f" / "o.GetType()" with reference to Platers code. Trouble is that I cannot know where the client is copying from hence I would not know the formats to check for in advance...

Here are the results:

Copy/paste from FF - text and images
======================================
text/html / System.IO.MemoryStream
HTML Format / System.String
text/_moz_htmlcontext / System.IO.MemoryStream
text/_moz_htmlinfo / System.IO.MemoryStream
System.String / System.String
UnicodeText / System.String
Text / System.String
text/x-moz-url-priv / System.IO.MemoryStream


Copy/paste from IE - text and images
======================================
System.String / System.String
UnicodeText / System.String
Text / System.String
HTML Format / System.String
Rich Text Format / System.String


Copy/paste from FF - single picture
======================================
application/x-moz-nativeimage / object is null
DeviceIndependentBitmap / System.IO.MemoryStream


Copy/paste from IE - single picture (same picture as above)
======================================
UntrustedDragDrop / System.IO.MemoryStream
FileDrop / System.String[]
FileNameW / System.String[]
FileName / System.String[]
UniformResourceLocatorW / System.IO.MemoryStream
DeviceIndependentBitmap / System.IO.MemoryStream
HTML Format / System.String


Copy/paste from FF - text only
======================================
text/html / System.IO.MemoryStream
HTML Format / System.String
text/_moz_htmlcontext / System.IO.MemoryStream
text/_moz_htmlinfo / System.IO.MemoryStream
System.String / System.String
UnicodeText / System.String
Text / System.String
text/x-moz-url-priv / System.IO.MemoryStream


Copy/paste from IE - text only
======================================
System.String / System.String
UnicodeText / System.String
Text / System.String
HTML Format / System.String
Rich Text Format / System.String
Sep 3 '09 #6
GaryTexmo
1,501 Expert 1GB
Do you need to know in advance? With Platter's code, you can just loop through the types on the Clipboard and use a switch statement on the type to take the appropriate action... couldn't you?

You shouldn't need to know where it's copying from, just take the appropriate action with whatever you have at any given time.
Sep 3 '09 #7
@GaryTexmo
Well... I need to know prior to pasting as pasting of content containing other than (formatted) text OR a single image has to be prevented and the user has to get a warning that he/she is pasting "illegal" content.

@GaryTexmo
I guess my two main sources for content would be a browser and MS Word. I was thinking of detecting the content as HTML and parsing that for existense of <img> tags (if possible) and in the other case (Word) extracting the clipboard content into some sort of officeautomation object and parsing that as XML...

Any thoughts on this approach?
Sep 4 '09 #8
To stop further investigation into this issue let me start by saying that I have found a suitable workaround.

The project I'm working on has to produce a Word add-in to "transform" Word into an advanced XML editor. To do this we are using VSTO (an MS Office framework from Microsoft). Working with Word is done using a Range object that has a couple of useful collections: Hyperlinks and InlineShapes. Using these I can determine if a pasted Range contains one or more Hyperlinks and/or InlineShapes. If that is the case then reject the paste.

Thanks guys for your effort!

Have a nice weekend!
Sep 4 '09 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Meikel | last post by:
I created a ClipboardUtils class which makes it easy to copy Strings or images to the clipboard. I don't claim that it's no way perfect, but has been useful in my applications so far. If you try...
157
by: Dennis | last post by:
Is there some way --using, say, DOM or javascript-- to detect the current pixel width and/or height of a relatively sized table or of one of its columns or rows. I'm going to be writing javascript...
4
by: Risto Heinonen | last post by:
Hi. I have a web page that has images and text. I can carefully select one image and the on the right of the image and then copy & paste to Word. Is it possible to make javascript do the same:...
8
by: Chris Beall | last post by:
I'm struggling with how to handle, on a web page, images that contain text that the user must be able to read. Examples: tombstone photos, photos or scans of historic documents (handwritten or...
7
by: William Gill | last post by:
Is there a simple way to cut and paste from a tkinter text widget to an entry widget? I know I could create a mouse button event that triggers a popup (message widget) prompting for cut/paste in...
1
by: Blog the Haggis | last post by:
Hi everyone, The program I am writing has a rich text window showing particular types of data message, and my plan is to insert a small BMP image before each message depending on its type. So...
2
by: jmDesktop | last post by:
I have two listview controls. I have three items of text. I can drag and drop the listview items between each other, back and forth. But the images from the imagelist do not copy over from...
0
by: Robert | last post by:
Hi! I want to fill the clipboard programmatically in oder to manual copy the data to word. The data consists of cells of a grid which contains text or images. Using the standard copy/paste of...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.