473,406 Members | 2,377 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,406 software developers and data experts.

Get metafile from clipboard object

Hi

I need to retrieve a metafile image from the clipboard and render it as a
bitmap in my application. In particular, an image will be placed on the
clipboard by pasting from PowerPoint (I really do need to do this!). The
original image is a bitmap, but PowerPoint doesn't place it on the clipboard
as such. A call to GetFormats() indicates that MetafilePict and
EnhancedMetaFile are available formats.

The following does NOT work:

Dim metaFile As System.Drawing.Imaging.Metafile

If data.GetDataPresent(DataFormats.MetafilePict) Then
obj = data.GetData(DataFormats.MetafilePict, True)
metaFile = CType(obj, System.Drawing.Imaging.Metafile)
....
End If
The GetDataPresent() test returns true, indicating there is a MetafilePict.
The GetData returns something (it's not "Nothing") but I can't figure out
what to do with it. The CType returns "Nothing" in metaFile.

Help?

Thanks,
--George
* George Yefchak
* Phone: 408-970-0419
* Cell: 408-981-5521
* E-mail: ge****@yefchak.com
* Web: www.yefchak.com
Nov 20 '05 #1
2 7958
Hi George,

You may want to try using the type rather than the data format name. I'm
not sure why, but this seemed to work more reliably for me than using the
formats. The following works when I copy a picture from PowerPoint

Dim objData As DataObject = Clipboard.GetDataObject()

If objData.GetDataPresent(GetType(System.Drawing.Bitm ap)) Then
Dim bmp As System.Drawing.Bitmap =
CType(objData.GetData(GetType(System.Drawing.Bitma p)),
System.Drawing.Bitmap)
End If

I'll have to do a little research to find out the prescribed way to convert
the MemoryStream from the clipboard to a MetaFile.

Craig,
VB .Net Team
--------------------------------------------------------------------
This reply is provided AS IS, without warranty (express or implied).

--------------------
From: "George Yefchak" <ge****@yefchak.com>
Subject: Get metafile from clipboard object
Date: Tue, 27 Jan 2004 11:30:03 -0800
Lines: 35
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1106
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106
Organization: Agilent Laboratories, Palo Alto, CA
Message-ID: <10***************@emperor.labs.agilent.com>
Cache-Post-Path: em******************************@hploboe.labs.agil ent.com
X-Cache: nntpcache 3.0.1 (see http://www.nntpcache.org/)
Cache-Post-Path: cs******************************@emperor.labs.agil ent.com
X-Cache: nntpcache 2.3.3 (see http://www.nntpcache.org/)
Newsgroups: microsoft.public.dotnet.languages.vb
NNTP-Posting-Host: cswrelay.cos.agilent.com 192.6.143.83
Path: cpmsftngxa07.phx.gbl!cpmsftngxa06.phx.gbl!TK2MSFTN GP08.phx.gbl!TK2MSFTNGP10.
phx.gblXref: cpmsftngxa07.phx.gbl microsoft.public.dotnet.languages.vb:176589
X-Tomcat-NG: microsoft.public.dotnet.languages.vb

Hi

I need to retrieve a metafile image from the clipboard and render it as a
bitmap in my application. In particular, an image will be placed on the
clipboard by pasting from PowerPoint (I really do need to do this!). The
original image is a bitmap, but PowerPoint doesn't place it on the clipboardas such. A call to GetFormats() indicates that MetafilePict and
EnhancedMetaFile are available formats.

The following does NOT work:

Dim metaFile As System.Drawing.Imaging.Metafile

If data.GetDataPresent(DataFormats.MetafilePict) Then
obj = data.GetData(DataFormats.MetafilePict, True)
metaFile = CType(obj, System.Drawing.Imaging.Metafile)
...
End If
The GetDataPresent() test returns true, indicating there is a MetafilePict.
The GetData returns something (it's not "Nothing") but I can't figure out
what to do with it. The CType returns "Nothing" in metaFile.

Help?

Thanks,
--George
* George Yefchak
* Phone: 408-970-0419
* Cell: 408-981-5521
* E-mail: ge****@yefchak.com
* Web: www.yefchak.com



Nov 20 '05 #2
Hi George,

I was able to get more information on your question. First of all, there
seems to be an issue getting apps in general and .NET apps to be able to
see each others metafiles when saved to the clipboard. Here's a KB article
that examines one half of this issue:
http://support.microsoft.com/?id=323530

There is a way to do what you want, but you have to use WinAPIs. Here's an
example (which you may want to refine).

1. Add a class named ClipboardAPI and add the following code to the class

Imports System.Runtime.InteropServices

Public Class ClipboardAPI

<DllImport("user32.dll", EntryPoint:="OpenClipboard", _
SetLastError:=True, ExactSpelling:=True,
CallingConvention:=CallingConvention.StdCall)> _
Public Shared Function OpenClipboard(ByVal hWnd As IntPtr) As Boolean
End Function

<DllImport("user32.dll", EntryPoint:="EmptyClipboard", _
SetLastError:=True, ExactSpelling:=True,
CallingConvention:=CallingConvention.StdCall)> _
Public Shared Function EmptyClipboard() As Boolean
End Function

<DllImport("user32.dll", EntryPoint:="SetClipboardData", _
SetLastError:=True, ExactSpelling:=True,
CallingConvention:=CallingConvention.StdCall)> _
Public Shared Function SetClipboardData(ByVal uFormat As Integer, ByVal
hWnd As IntPtr) As IntPtr
End Function

<DllImport("user32.dll", EntryPoint:="CloseClipboard", _
SetLastError:=True, ExactSpelling:=True,
CallingConvention:=CallingConvention.StdCall)> _
Public Shared Function CloseClipboard() As Boolean
End Function

<DllImport("user32.dll", EntryPoint:="GetClipboardData", _
SetLastError:=True, ExactSpelling:=True,
CallingConvention:=CallingConvention.StdCall)> _
Public Shared Function GetClipboardData(ByVal uFormat As Integer) As
IntPtr
End Function

<DllImport("user32.dll", EntryPoint:="IsClipboardFormatAvailable", _
SetLastError:=True, ExactSpelling:=True,
CallingConvention:=CallingConvention.StdCall)> _
Public Shared Function IsClipboardFormatAvailable(ByVal uFormat As
Integer) As Short
End Function
End Class

2. Add the following to your button click event

Const CF_ENHMETAFILE As Integer = 14

Dim henmetafile As IntPtr
Dim metaFile As System.Drawing.Imaging.Metafile

If ClipboardAPI.OpenClipboard(Me.Handle) Then
If ClipboardAPI.IsClipboardFormatAvailable(CF_ENHMETA FILE) <> 0
Then
henmetafile = ClipboardAPI.GetClipboardData(CF_ENHMETAFILE)
metaFile = New Metafile(henmetafile, True)
ClipboardAPI.CloseClipboard()
End If
End If

Hope this helps,
Craig VB.NET Team
--------------------------------------------------------------------
This reply is provided AS IS, without warranty (express or implied).

--------------------
From: "George Yefchak" <ge****@yefchak.com>
Subject: Get metafile from clipboard object
Date: Tue, 27 Jan 2004 11:30:03 -0800
Lines: 35
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1106
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106
Organization: Agilent Laboratories, Palo Alto, CA
Message-ID: <10***************@emperor.labs.agilent.com>
Cache-Post-Path: em******************************@hploboe.labs.agil ent.com
X-Cache: nntpcache 3.0.1 (see http://www.nntpcache.org/)
Cache-Post-Path: cs******************************@emperor.labs.agil ent.com
X-Cache: nntpcache 2.3.3 (see http://www.nntpcache.org/)
Newsgroups: microsoft.public.dotnet.languages.vb
NNTP-Posting-Host: cswrelay.cos.agilent.com 192.6.143.83
Path: cpmsftngxa07.phx.gbl!cpmsftngxa06.phx.gbl!TK2MSFTN GP08.phx.gbl!TK2MSFTNGP10.
phx.gblXref: cpmsftngxa07.phx.gbl microsoft.public.dotnet.languages.vb:176589
X-Tomcat-NG: microsoft.public.dotnet.languages.vb

Hi

I need to retrieve a metafile image from the clipboard and render it as a
bitmap in my application. In particular, an image will be placed on the
clipboard by pasting from PowerPoint (I really do need to do this!). The
original image is a bitmap, but PowerPoint doesn't place it on the clipboardas such. A call to GetFormats() indicates that MetafilePict and
EnhancedMetaFile are available formats.

The following does NOT work:

Dim metaFile As System.Drawing.Imaging.Metafile

If data.GetDataPresent(DataFormats.MetafilePict) Then
obj = data.GetData(DataFormats.MetafilePict, True)
metaFile = CType(obj, System.Drawing.Imaging.Metafile)
...
End If
The GetDataPresent() test returns true, indicating there is a MetafilePict.
The GetData returns something (it's not "Nothing") but I can't figure out
what to do with it. The CType returns "Nothing" in metaFile.

Help?

Thanks,
--George
* George Yefchak
* Phone: 408-970-0419
* Cell: 408-981-5521
* E-mail: ge****@yefchak.com
* Web: www.yefchak.com

Nov 20 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: fowlertrainer | last post by:
Hi ! My problem is that: I have a program that copy pictures from Notes NSF file. The format is METAFILE or METAFILEPICT. I can save these pictures with this code: import win32api import...
2
by: Julian Ziersch | last post by:
This code causes a severe memory leak - the critical part is the call to GetHenhmetafile(). System.Drawing.Imaging.Metafile lImage = new System.Drawing.Imaging.Metafile("C:\\meta0.emf"); IntPtr...
3
by: Richard Skopal | last post by:
In .NET Windows forms I can create a metafile using this code: Graphics grph = aControl.CreateGraphics(); IntPtr ipHDC = grph.GetHdc(); Metafile mf = new Metafile(aImgFilePath, ipHDC,...
0
by: Ben Leino | last post by:
Hi out there, I have a quite huge problem that I can't solve after huge "googeling and msdnning". Ich have a litte VB.NET class that opens a PowerPoint Presentation (COM) and wants to extract...
1
by: B. Cline | last post by:
Hi, I need to write a conversion routine to split pictures out of about 10000 word documents. (Actually the text is converted to RTF, the pictures should be converted to jpg). I thought I...
0
by: weiruic | last post by:
I am trying to create a metafile (.emf) on the harddisk, write graphics from a graphics object to it, and then save it. I can do this successfully except I cannot set the horizontal and vertical...
2
by: NickP | last post by:
Hi there, I am obtaining a meta file from the clipboard via the following code Dim CF_ENHMETAFILE As Integer = 14 Dim cMFeImage As Imaging.Metafile Dim pIPrClipboard As IntPtr =...
2
by: Alexander Gorbylev | last post by:
Hi! Let the size of vector is e.g. 3.5". I render the same vector on a printer & a screen on the same procedure: printDoc_BeginPrint(object sender, PrintEventArgs e) { .... vector.Width *...
1
by: bern11 | last post by:
I can get bitmaps from the clipboard, but how do I get Metafiles? The specific instance I am testing is copying a piece of Word clip-art into the clipboard and trying to read it in an application. ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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.