http://support.microsoft.com/kb/230675的例子,但是小弟不才,一直未得正确的执行结果// This function returns an EMF HDC, on which has already been drawn the contents of the source EMF.
HDC MakeNewWritableMetafile( LPTSTR szSourceFileName, LPTSTR szTargetFileName )
{
HENHMETAFILE hSourceEMF;
HDC hTargetDC, hRefDC;
ENHMETAHEADER emh;
RECT Rect, rcSource;
float PixelsX, PixelsY, MMX, MMY; // Get a reference DC. Normally, you'd get the highest resolution DC available,
//    for example a printer DC. We just use a screen DC for this demonstration.
if( (hRefDC = GetDC( NULL )) == NULL )
return NULL;
// Open the source EMF
if( (hSourceEMF = GetEnhMetaFile( szSourceFileName )) == NULL )
{
ReleaseDC( NULL, hRefDC );
return NULL;
} // Get the header from the enhanced metafile.
ZeroMemory( &emh, sizeof(ENHMETAHEADER) );
emh.nSize = sizeof(ENHMETAHEADER);
if( GetEnhMetaFileHeader( hSourceEMF, sizeof( ENHMETAHEADER ), &emh ) == 0 )
{
DeleteEnhMetaFile( hSourceEMF );
ReleaseDC( NULL, hRefDC );
return NULL;
} // Get the characteristics of the output device.
PixelsX = (float)GetDeviceCaps( hRefDC, HORZRES );
PixelsY = (float)GetDeviceCaps( hRefDC, VERTRES );
MMX = (float)GetDeviceCaps( hRefDC, HORZSIZE );
MMY = (float)GetDeviceCaps( hRefDC, VERTSIZE ); // Calculate the rect in which to draw the metafile based on the
// intended size and the current output device resolution.
// Remember that the intended size is given in 0.01 mm units, so
// convert those to device units on the target device.
Rect.top = (int)((float)(emh.rclFrame.top) * PixelsY / (MMY*100.0f));
Rect.left = (int)((float)(emh.rclFrame.left) * PixelsX / (MMX*100.0f));
Rect.right = (int)((float)(emh.rclFrame.right) * PixelsX / (MMX*100.0f));
Rect.bottom = (int)((float)(emh.rclFrame.bottom) * PixelsY / (MMY*100.0f)); // Create the new metafile the same size as the old one.
SetRect( &rcSource, emh.rclFrame.left, emh.rclFrame.top, emh.rclFrame.right, emh.rclFrame.bottom );
hTargetDC = CreateEnhMetaFile( hRefDC, szTargetFileName, &rcSource, "Desc\0Desc\0\0" );
// Play the old metafile on to the new one.
PlayEnhMetaFile( hTargetDC, hSourceEMF, &Rect );
// Clean up.
DeleteEnhMetaFile( hSourceEMF );
ReleaseDC( NULL, hRefDC );
return hTargetDC;
}
每一步都正确执行,但是PlayEnhMetaFile执行后,保存的新建文件中内容是空,不知道还有什么地方需要注意!谢谢各位大侠