经测试,完全可以 Option ExplicitPrivate Type POINTAPI x As Long y As Long End TypePrivate Type LOGBRUSH lbStyle As Long lbColor As Long lbHatch As Long End TypePrivate Type Rect Left As Long Top As Long Right As Long Bottom As Long End Type'Private Declare Function CreateMetaFile Lib "gdi32" Alias "CreateMetaFileA" (ByVal lpString As String) As Long Private Declare Function CreateMetaFile Lib "gdi32" Alias "CreateMetaFileA" (ByVal lpString As Long) As LongPrivate Declare Function MoveToEx Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, lpPoint As Long) As Long Private Declare Function LineTo Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long) As Long Private Declare Function CreateBrushIndirect Lib "gdi32" (lpLogBrush As LOGBRUSH) As Long Private Declare Function CreateBitmap Lib "gdi32" (ByVal nWidth As Long, ByVal nHeight As Long, ByVal nPlanes As Long, ByVal nBitCount As Long, lpBits As Any) As Long Private Declare Function Rectangle Lib "gdi32" (ByVal hdc As Long, ByVal x1 As Long, ByVal y1 As Long, ByVal x2 As Long, ByVal y2 As Long) As Long Private Declare Function SelectObject Lib "gdi32" (ByVal hdc As Long, ByVal hObject As Long) As Long Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long Private Declare Function CloseMetaFile Lib "gdi32" (ByVal hMF As Long) As Long Private Declare Function PlayMetaFile Lib "gdi32" (ByVal hdc As Long, ByVal hMF As Long) As Long Private Declare Function CreateSolidBrush Lib "gdi32" (ByVal crColor As Long) As Long Private Declare Function Ellipse Lib "gdi32" (ByVal hdc As Long, ByVal x1 As Long, ByVal y1 As Long, ByVal x2 As Long, ByVal y2 As Long) As Long Private Declare Function DeleteMetaFile Lib "gdi32" (ByVal hMF As Long) As Long Private Declare Function SetWindowOrgEx Lib "gdi32" (ByVal hdc As Long, ByVal nX As Long, ByVal nY As Long, lpPoint As Long) As Long Private Declare Function SetMapMode Lib "gdi32" (ByVal hdc As Long, ByVal nMapMode As Long) As Long Private Declare Function SetWindowExtEx Lib "gdi32" (ByVal hdc As Long, ByVal nX As Long, ByVal nY As Long, lpSize As Any) As Long Private Declare Function SetViewportExtEx Lib "gdi32" (ByVal hdc As Long, ByVal nX As Long, ByVal nY As Long, lpSize As Any) 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 DeleteEnhMetaFile Lib "gdi32" (ByVal hemf As Long) As LongPrivate Declare Function SaveDC Lib "gdi32" (ByVal hdc As Long) As Long Private Declare Function RestoreDC Lib "gdi32" (ByVal hdc As Long, ByVal nSavedDC As Long) As Long Private Declare Function CloseEnhMetaFile Lib "gdi32" (ByVal hdc As Long) As LongPrivate Const MM_ANISOTROPIC = 8Dim hMF As LongPrivate Sub Form_Load() Dim hMetaDC As Long Dim hBrush As Long Dim r As Long hMetaDC = CreateMetaFile(ByVal 0&) r = MoveToEx(hMetaDC, 0, 0, ByVal 0) r = LineTo(hMetaDC, 100, 100) r = MoveToEx(hMetaDC, 0, 100, ByVal 0) r = LineTo(hMetaDC, 100, 0) hBrush = CreateSolidBrush(&HFF0000) r = SelectObject(hMetaDC, hBrush) r = Ellipse(hMetaDC, 20, 20, 80, 80)
hMF = CloseMetaFile(hMetaDC)
DeleteObject hBrush End SubPrivate Sub Form_Paint() PlayMetaFile hdc, hMF End SubPrivate Sub Form_Unload(Cancel As Integer) DeleteMetaFile hMF End SubPrivate Sub Picture1_Paint() PlayMetaFile Picture1.hdc, hMF End Sub
倒不是这个问题。picturebox可以载入emf和wmf格式的元文件,我试了的我把PlayEnhMetaFile 那一句改为loadpicture可以显示,只是疑惑为什么PlayEnhMetaFile会不能显示
Picture1.Picture = LoadPicture("c:\emf\temp.emf")
Option ExplicitPrivate Type POINTAPI
x As Long
y As Long
End TypePrivate Type LOGBRUSH
lbStyle As Long
lbColor As Long
lbHatch As Long
End TypePrivate Type Rect
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type'Private Declare Function CreateMetaFile Lib "gdi32" Alias "CreateMetaFileA" (ByVal lpString As String) As Long
Private Declare Function CreateMetaFile Lib "gdi32" Alias "CreateMetaFileA" (ByVal lpString As Long) As LongPrivate Declare Function MoveToEx Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, lpPoint As Long) As Long
Private Declare Function LineTo Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long) As Long
Private Declare Function CreateBrushIndirect Lib "gdi32" (lpLogBrush As LOGBRUSH) As Long
Private Declare Function CreateBitmap Lib "gdi32" (ByVal nWidth As Long, ByVal nHeight As Long, ByVal nPlanes As Long, ByVal nBitCount As Long, lpBits As Any) As Long
Private Declare Function Rectangle Lib "gdi32" (ByVal hdc As Long, ByVal x1 As Long, ByVal y1 As Long, ByVal x2 As Long, ByVal y2 As Long) As Long
Private Declare Function SelectObject Lib "gdi32" (ByVal hdc As Long, ByVal hObject As Long) As Long
Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
Private Declare Function CloseMetaFile Lib "gdi32" (ByVal hMF As Long) As Long
Private Declare Function PlayMetaFile Lib "gdi32" (ByVal hdc As Long, ByVal hMF As Long) As Long
Private Declare Function CreateSolidBrush Lib "gdi32" (ByVal crColor As Long) As Long
Private Declare Function Ellipse Lib "gdi32" (ByVal hdc As Long, ByVal x1 As Long, ByVal y1 As Long, ByVal x2 As Long, ByVal y2 As Long) As Long
Private Declare Function DeleteMetaFile Lib "gdi32" (ByVal hMF As Long) As Long
Private Declare Function SetWindowOrgEx Lib "gdi32" (ByVal hdc As Long, ByVal nX As Long, ByVal nY As Long, lpPoint As Long) As Long
Private Declare Function SetMapMode Lib "gdi32" (ByVal hdc As Long, ByVal nMapMode As Long) As Long
Private Declare Function SetWindowExtEx Lib "gdi32" (ByVal hdc As Long, ByVal nX As Long, ByVal nY As Long, lpSize As Any) As Long
Private Declare Function SetViewportExtEx Lib "gdi32" (ByVal hdc As Long, ByVal nX As Long, ByVal nY As Long, lpSize As Any) 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 DeleteEnhMetaFile Lib "gdi32" (ByVal hemf As Long) As LongPrivate Declare Function SaveDC Lib "gdi32" (ByVal hdc As Long) As Long
Private Declare Function RestoreDC Lib "gdi32" (ByVal hdc As Long, ByVal nSavedDC As Long) As Long
Private Declare Function CloseEnhMetaFile Lib "gdi32" (ByVal hdc As Long) As LongPrivate Const MM_ANISOTROPIC = 8Dim hMF As LongPrivate Sub Form_Load()
Dim hMetaDC As Long
Dim hBrush As Long
Dim r As Long
hMetaDC = CreateMetaFile(ByVal 0&)
r = MoveToEx(hMetaDC, 0, 0, ByVal 0)
r = LineTo(hMetaDC, 100, 100)
r = MoveToEx(hMetaDC, 0, 100, ByVal 0)
r = LineTo(hMetaDC, 100, 0) hBrush = CreateSolidBrush(&HFF0000)
r = SelectObject(hMetaDC, hBrush)
r = Ellipse(hMetaDC, 20, 20, 80, 80)
hMF = CloseMetaFile(hMetaDC)
DeleteObject hBrush
End SubPrivate Sub Form_Paint()
PlayMetaFile hdc, hMF
End SubPrivate Sub Form_Unload(Cancel As Integer)
DeleteMetaFile hMF
End SubPrivate Sub Picture1_Paint()
PlayMetaFile Picture1.hdc, hMF
End Sub