Determining if there is an image in the clipboard

I am using Delphi 2010 and would like to be able to know if the content of the clipboard contains any images before I paste.  I thought I could use clipboard.hasformat(CF_text) but this does not work if the content of the clipboard contains both images and text it returns true as  I am wanting to prevent users from pasting images from the clipboard into a memo control.

Thanks for your help

Daniel
DanielManchesterAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Sinisa VukSoftware architectCommented:
More about clipboard:
http://delphi.about.com/od/vclusing/a/tclipboard.htm
http://msdn.microsoft.com/en-us/library/windows/desktop/ms649013%28v=vs.85%29.aspx
http://www.delphipages.com/forum/showthread.php?t=172339

...so, check for CF_BITMAP or CF_PICTURE. It is possible to have custom/private clipboard format but this is for you app only. You can hold only one type in memory
at same time - but same "object" can be represented in multiple formats (like text as native text or text as image on clipboard). For your usage check if format is CF_TEXT only  and not one of CF_BITMAP, CF_PICTURE,...

If you pull only text as: Clipboard.AsText then image part is ignored...

 if (Clipboard.HasFormat(CF_BITMAP)) and 
    (not Clipboard.HasFormat(CF_BITMAP)) and
    (not Clipboard.HasFormat(CF_PICTURE)) then 
...

Open in new window


app that may help you:
http://www.nirsoft.net/utils/inside_clipboard.html
0
DanielManchesterAuthor Commented:
The problem with this approach is if you select any text from a word doc the combination of
(Clipboard.HasFormat(CF_BITMAP)) or  (Clipboard.HasFormat(CF_PICTURE)) always returns true even if it contains no images.  I need a function that correctly tells me if there is an image.  I want the user to be able to pasted formatted text so using clipboard.asText all the time does not work.

Thanks for your help

Daniel
0
Sinisa VukSoftware architectCommented:
Are you sure? Please can you take screenshot of inside_clipboard utility when you do copy this text with images in Word. I think that when text is included then CF_TEXT is set as one of clipboard types. Then AsText should work - to pull text part only...

There are object in Word that looks like text - but it is not common text - so no CF_TEXT on clipboard.
0
Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

DanielManchesterAuthor Commented:
As you can see in the screenshot I have only selected some text (not the image) from a Word document that does contain an image yet clipboard.hasformat(CF_PICTURE) returns true.
clip.png
0
Sinisa VukSoftware architectCommented:
As you can see - there is no Delphi Picture format (CF_PICTURE - Delphi custom format) on clipboard. HasFormat with CF_PICTURE enumerates all formats compatible with TPicture component (bitmaps, metafiles,...) and as you can see - there is a metafile on clipboard (ENHMETAFILE) - This is why HasFormat(CF_PICTURE) returns True.
Try to check CF_BITMAP and CF_DIB in pair and not CF_PICTURE.
This is list of standard clipboard formats:
http://msdn.microsoft.com/en-us/library/windows/desktop/ff729168%28v=vs.85%29.aspx
0
DanielManchesterAuthor Commented:
The problem with pairing  CF_BITMAP and CF_DIB as it still allows images to be pasted.  See attached.
clipexample.doc
0
Sinisa VukSoftware architectCommented:
Unfortunately, I use LibreOffice which doesn't expose images when do copy of contents. I think that simple memo component that comes with Delphi doesn't support images. Which component you use for pasting? If you do not want to paste images - why you don't use Clipboard.AsText? It will pull text only. When you get True on Clipboard.Hasformat(CF_TEXT) - then use ...AsText - nothing more, nothing less - images are ignored (same with CF_UNICODETEXT).

Can you post sample code here to see ...?
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
DanielManchesterAuthor Commented:
Using a tmemo as a workaround will get the job done for now.

Thanks
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.