Dieses Problem, da .NET Framework ein neues Zwischenablageformat, verwendet wenn es in die Zwischenablage Metadateien hinzufügt. Andere Anwendungen, wie z. B. Word oder das Betriebssystem können nicht nicht mit diesem neuen Format bewusst sind und daher einfügen oder das Bild angezeigt.
Um eine Metadatei in die Zwischenablage hinzufügen, damit es für andere Anwendungen sichtbar ist, müssen Sie das CF_ENHMETAFILE-Format verwenden. Unterstützung für dieses Format wird über das DataObject -Klasse mit der DataFormats.EnhancedMetafile -Methode bereitgestellt. Leider verhindert Einschränkungen in der aktuellen Implementierung von .NET Framework dies eine geeignete Lösung. Daher müssen Sie Interoperabilität mit Win32- Zwischenablage Anwendungsprogrammierschnittstellen (APIs) zur Behebung dieses Problems erhalten.
Die Codebeispiele, die zeigen, wie eine Metadatei in die Zwischenablage hinzufügen, damit es für andere Anwendungen sichtbar ist.
Beispiel für Microsoft Visual Basic .NET
Imports System.Drawing.Imaging
Imports System.Runtime.InteropServices
Public Class ClipboardMetafileHelper
<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("gdi32.dll", EntryPoint:="CopyEnhMetaFileA", _
SetLastError:=True, ExactSpelling:=True, CallingConvention:=CallingConvention.StdCall)> _
Public Shared Function CopyEnhMetaFile(ByVal hemfSrc As IntPtr, ByVal hNULL As IntPtr) As IntPtr
End Function
<DllImport("gdi32.dll", EntryPoint:="DeleteEnhMetaFile", _
SetLastError:=True, ExactSpelling:=True, CallingConvention:=CallingConvention.StdCall)> _
Public Shared Function DeleteEnhMetaFile(ByVal hemfSrc As IntPtr) As Boolean
End Function
' Metafile mf is set to a state that is not valid inside this function.
Public Shared Function PutEnhMetafileOnClipboard(ByVal hWnd As IntPtr, ByVal mf As Metafile) As Boolean
Dim bResult As New Boolean()
bResult = False
Dim hEMF, hEMF2 As IntPtr
hEMF = mf.GetHenhmetafile() ' invalidates mf
If Not hEMF.Equals(New IntPtr(0)) Then
hEMF2 = CopyEnhMetaFile(hEMF, New IntPtr(0))
If Not hEMF2.Equals(New IntPtr(0)) Then
If OpenClipboard(hWnd) Then
If EmptyClipboard() Then
Dim hRes As IntPtr
hRes = SetClipboardData(14, hEMF2) ' 14 == CF_ENHMETAFILE
bResult = hRes.Equals(hEMF2)
CloseClipboard()
End If
End If
End If
DeleteEnhMetaFile(hEMF)
End If
Return bResult
End Function
End Class
'You can call this function with code that is similar to the following code:
Dim mf As New Metafile("filename.emf")
ClipboardMetafileHelper.PutEnhMetafileOnClipboard(me.Handle,mf)
Beispiel für Microsoft Visual c# .NET
using System.Drawing.Imaging;
using System.Runtime.InteropServices;
public class ClipboardMetafileHelper
{
[DllImport("user32.dll")]
static extern bool OpenClipboard(IntPtr hWndNewOwner);
[DllImport("user32.dll")]
static extern bool EmptyClipboard();
[DllImport("user32.dll")]
static extern IntPtr SetClipboardData(uint uFormat, IntPtr hMem);
[DllImport("user32.dll")]
static extern bool CloseClipboard();
[DllImport("gdi32.dll")]
static extern IntPtr CopyEnhMetaFile(IntPtr hemfSrc, IntPtr hNULL);
[DllImport("gdi32.dll")]
static extern bool DeleteEnhMetaFile(IntPtr hemf);
// Metafile mf is set to a state that is not valid inside this function.
static public bool PutEnhMetafileOnClipboard( IntPtr hWnd, Metafile mf )
{
bool bResult = false;
IntPtr hEMF, hEMF2;
hEMF = mf.GetHenhmetafile(); // invalidates mf
if( ! hEMF.Equals( new IntPtr(0) ) )
{
hEMF2 = CopyEnhMetaFile( hEMF, new IntPtr(0) );
if( ! hEMF2.Equals( new IntPtr(0) ) )
{
if( OpenClipboard( hWnd ) )
{
if( EmptyClipboard() )
{
IntPtr hRes = SetClipboardData( 14 /*CF_ENHMETAFILE*/, hEMF2 );
bResult = hRes.Equals( hEMF2 );
CloseClipboard();
}
}
}
DeleteEnhMetaFile( hEMF );
}
return bResult;
}
}
//You can call this function with code that is similar to the following code:
Metafile mf = new Metafile( "filename.emf" );
ClipboardMetafileHelper.PutEnhMetafileOnClipboard(this.Handle, mf );
Die Informationen in diesem Artikel beziehen sich auf:
Microsoft .NET Framework Software Development Kit 1.0 Service Pack 2
Microsoft .NET Framework Software Development Kit 1.0 Service Pack 2
Microsoft Windows XP Professional
the operating system: Microsoft Windows XP 64-Bit Edition
Keywords:
kbmt kbdswgdi2003swept kbprb KB323530 KbMtde
Maschinell übersetzter Artikel
Wichtig: Dieser Artikel wurde maschinell und nicht von einem Menschen übersetzt. Die Microsoft Knowledge Base ist sehr umfangreich und ihre Inhalte werden ständig ergänzt beziehungsweise überarbeitet. Um Ihnen dennoch alle Inhalte auf Deutsch anbieten zu können, werden viele Artikel nicht von Menschen, sondern von Übersetzungsprogrammen übersetzt, die kontinuierlich optimiert werden. Doch noch sind maschinell übersetzte Texte in der Regel nicht perfekt, insbesondere hinsichtlich Grammatik und des Einsatzes von Fremdwörtern sowie Fachbegriffen. Microsoft übernimmt keine Gewähr für die sprachliche Qualität oder die technische Richtigkeit der Übersetzungen und ist nicht für Probleme haftbar, die direkt oder indirekt durch Übersetzungsfehler oder die Verwendung der übersetzten Inhalte durch Kunden entstehen könnten.
Den englischen Originalartikel können Sie über folgenden Link abrufen: 323530
(http://support.microsoft.com/kb/323530/en-us/
)
Microsoft stellt Ihnen die in der Knowledge Base angebotenen Artikel und Informationen als Service-Leistung zur Verfügung. Microsoft übernimmt keinerlei Gewährleistung dafür, dass die angebotenen Artikel und Informationen auch in Ihrer Einsatzumgebung die erwünschten Ergebnisse erzielen. Die Entscheidung darüber, ob und in welcher Form Sie die angebotenen Artikel und Informationen nutzen, liegt daher allein bei Ihnen. Mit Ausnahme der gesetzlichen Haftung für Vorsatz ist jede Haftung von Microsoft im Zusammenhang mit Ihrer Nutzung dieser Artikel oder Informationen ausgeschlossen.
Danke! Dieses Feedback hilft uns dabei, die Supportartikel weiter zu verbessern. Weitere Informationen finden Sie auf der Hilfe und Support-Startseite.