Private Type BITMAP bmType As Long bmWidth As Long bmHeight As Long bmWidthBytes As Long bmPlanes As Integer bmBitsPixel As Integer bmBits As Long End Type
Private Type RECT Left As Long Top As Long Right As Long Bottom As Long End Type
Private Declare Function CreateCompatibleDC Lib "gdi32" (ByVal hdc As Long) As _ Long Private Declare Function SelectObject Lib "gdi32" (ByVal hdc As Long, _ ByVal hObject As Long) As Long Private Declare Function BitBlt Lib "gdi32" (ByVal hDestDC As Long, _ ByVal X As Long, ByVal Y As Long, ByVal nWidth As Long, _ ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, _ ByVal ySrc As Long, ByVal dwRop As Long) As Long Private Declare Function DeleteDC Lib "gdi32" (ByVal hdc As Long) As Long Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As _ Long Private Declare Function GetObject Lib "gdi32" Alias "GetObjectA" (ByVal _ hObject As Long, ByVal nCount As Long, lpObject As Any) As Long Private Declare Function StretchBlt Lib "gdi32" (ByVal hdc As Long, _ ByVal X As Long, ByVal Y As Long, ByVal nWidth As Long, _ ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, _ ByVal ySrc As Long, ByVal nSrcWidth As Long, ByVal nSrcHeight As Long, _ ByVal dwRop As Long) As Long
Private Declare Function CreateEnhMetaFile Lib "gdi32" Alias _ "CreateEnhMetaFileA" (ByVal hdcRef As Long, ByVal lpFileName As String, _ lpRect As RECT, ByVal lpDescription As String) As Long Private Declare Function CloseEnhMetaFile Lib "gdi32" (ByVal hdc As Long) As _ Long Private Declare Function DeleteEnhMetaFile Lib "gdi32" (ByVal hEmf As Long) As _ Long Private Declare Function SetMapMode Lib "gdi32" (ByVal hdc As Long, _ ByVal nMapMode As Long) As Long
Public Enum MMETRIC MM_HIMETRIC = 3 MM_LOMETRIC = 2 MM_LOENGLISH = 4 MM_ISOTROPIC = 7 MM_HIENGLISH = 5 MM_ANISOTROPIC = 8 MM_ADLIB = 9 End Enum
Public Function CreateEmf(ByRef SourceImage As Object, ByVal FileName As String, _ ByVal Metrics As MMETRIC, Optional ByVal Comments As String) As Long Dim bm As BITMAP Dim hdcMem As Long
Dim hdc As Long Dim hEmf As Long Dim R As RECT Dim OldScale As Integer Dim HoldBitmap As Long Comments = Comments & vbNullChar GetObject SourceImage, Len(bm), bm R.Top = SourceImage.Top R.Left = SourceImage.Left R.Right = SourceImage.Picture.Width R.Bottom = SourceImage.Picture.Height OldScale = SourceImage.ScaleMode SourceImage.ScaleMode = vbPixels hdc = CreateEnhMetaFile(SourceImage.hdc, FileName, R, Comments) SetMapMode hdc, Metrics hdcMem = CreateCompatibleDC(hdc) HoldBitmap = SelectObject(hdcMem, SourceImage) BitBlt hdcMem, 0, 0, SourceImage.ScaleWidth, SourceImage.ScaleHeight, _ SourceImage.hdc, 0, 0, vbSrcCopy BitBlt hdc, 0, 0, SourceImage.ScaleWidth, SourceImage.ScaleHeight, hdcMem, _ 0, 0, vbSrcCopy SelectObject hdcMem, HoldBitmap DeleteDC (hdcMem) DeleteObject SelectObject(hdcMem, SourceImage)
hEmf = CloseEnhMetaFile(hdc) If DeleteEnhMetaFile(hEmf) = 1 Then CreateEmf = 0 Else CreateEmf = 1 End If SourceImage.ScaleMode = OldScale End Function |