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("use r32.dll", EntryPoint:="Op enClipboard", _
SetLastError:=T rue, ExactSpelling:= True,
CallingConventi on:=CallingConv ention.StdCall) > _
Public Shared Function OpenClipboard(B yVal hWnd As IntPtr) As Boolean
End Function
<DllImport("use r32.dll", EntryPoint:="Em ptyClipboard", _
SetLastError:=T rue, ExactSpelling:= True,
CallingConventi on:=CallingConv ention.StdCall) > _
Public Shared Function EmptyClipboard( ) As Boolean
End Function
<DllImport("use r32.dll", EntryPoint:="Se tClipboardData" , _
SetLastError:=T rue, ExactSpelling:= True,
CallingConventi on:=CallingConv ention.StdCall) > _
Public Shared Function SetClipboardDat a(ByVal uFormat As Integer, ByVal
hWnd As IntPtr) As IntPtr
End Function
<DllImport("use r32.dll", EntryPoint:="Cl oseClipboard", _
SetLastError:=T rue, ExactSpelling:= True,
CallingConventi on:=CallingConv ention.StdCall) > _
Public Shared Function CloseClipboard( ) As Boolean
End Function
<DllImport("use r32.dll", EntryPoint:="Ge tClipboardData" , _
SetLastError:=T rue, ExactSpelling:= True,
CallingConventi on:=CallingConv ention.StdCall) > _
Public Shared Function GetClipboardDat a(ByVal uFormat As Integer) As
IntPtr
End Function
<DllImport("use r32.dll", EntryPoint:="Is ClipboardFormat Available", _
SetLastError:=T rue, ExactSpelling:= True,
CallingConventi on:=CallingConv ention.StdCall) > _
Public Shared Function IsClipboardForm atAvailable(ByV al 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.Metafil e
If ClipboardAPI.Op enClipboard(Me. Handle) Then
If ClipboardAPI.Is ClipboardFormat Available(CF_EN HMETAFILE) <> 0
Then
henmetafile = ClipboardAPI.Ge tClipboardData( CF_ENHMETAFILE)
metaFile = New Metafile(henmet afile, True)
ClipboardAPI.Cl oseClipboard()
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.lab s.agilent.com>
Cache-Post-Path: em************* *************** **@hploboe.labs .agilent.com
X-Cache: nntpcache 3.0.1 (see http://www.nntpcache.org/)
Cache-Post-Path: cs************* *************** **@emperor.labs .agilent.com
X-Cache: nntpcache 2.3.3 (see http://www.nntpcache.org/)
Newsgroups: microsoft.publi c.dotnet.langua ges.vb
NNTP-Posting-Host: cswrelay.cos.ag ilent.com 192.6.143.83
Path:
cpmsftngxa07.ph x.gbl!cpmsftngx a06.phx.gbl!TK2 MSFTNGP08.phx.g bl!TK2MSFTNGP10 .
phx.gblXref: cpmsftngxa07.ph x.gbl microsoft.publi c.dotnet.langua ges.vb:176589
X-Tomcat-NG: microsoft.publi c.dotnet.langua ges.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
EnhancedMetaFi le are available formats.
The following does NOT work:
Dim metaFile As System.Drawing. Imaging.Metafil e
If data.GetDataPre sent(DataFormat s.MetafilePict) Then
obj = data.GetData(Da taFormats.Metaf ilePict, True)
metaFile = CType(obj, System.Drawing. Imaging.Metafil e)
...
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