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