Here's the scenario I'm creating a metafile using the CreateMetaFile API. When I try to create a dotted line everything seems to be fine, I can insert the image into Word and the dotted line prints fine, but not when I insert it into Crystal Report 9, the line prints as solid. My first thought was that there is a bug with Crystal Report, but I'm able to create a metafile in Visio that has dotted lines and it prints fine in Crystal.
I've put together a little function to duplicate what I'm doing. Any suggestion would be greatly appreciated.
Option Explicit
Private Type POINTAPI
X As Long
Y As Long
End Type
Private Declare Function CreateMetaFile Lib "gdi32" _
Alias "CreateMetaFileA" (ByVal lpString As String) As Long
Private Declare Function CloseMetaFile Lib "gdi32" _
(ByVal hMF As Long) As Long
Private Declare Function MoveToEx Lib "gdi32" _
(ByVal hdc As Long, ByVal X As Long, _
ByVal Y As Long, lpPoint As POINTAPI) 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 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 MhDC As Long
Private Declare Function CreatePen Lib "gdi32" _
(ByVal nPenStyle As Long, ByVal nWidth As Long, _
ByVal crColor 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 Enum PenStyle
PS_SOLID = 0
PS_DASH = 1
PS_DOT = 2
PS_DASHDOT = 3
PS_DASHDOTDOT = 4
End Enum
Private Sub DrawDottedLine(lngStartX, lngStartY, lngEndX, lngEndY)
Dim pt As POINTAPI
Dim hpen As Long
Dim hpenOLD As Long
MhDC = CreateMetaFile("C:\MyFolder\MyFile.wmf"
If MhDC = 0 Then
MsgBox "Error creating metafile."
Exit Sub
End If
Dim hMF As Long
hpen = CreatePen(PS_DOT, 1, vbBlack)
hpenOLD = SelectObject(MhDC, hpen)
MoveToEx MhDC, lngStartX, lngStartY, pt
LineTo MhDC, lngEndX, lngEndY
hMF = CloseMetaFile(MhDC)
DeleteMetaFile hMF
End Sub
Private Sub Command1_Click()
DrawDottedLine 0, 0, 100, 100
End Sub
I've put together a little function to duplicate what I'm doing. Any suggestion would be greatly appreciated.
Option Explicit
Private Type POINTAPI
X As Long
Y As Long
End Type
Private Declare Function CreateMetaFile Lib "gdi32" _
Alias "CreateMetaFileA" (ByVal lpString As String) As Long
Private Declare Function CloseMetaFile Lib "gdi32" _
(ByVal hMF As Long) As Long
Private Declare Function MoveToEx Lib "gdi32" _
(ByVal hdc As Long, ByVal X As Long, _
ByVal Y As Long, lpPoint As POINTAPI) 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 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 MhDC As Long
Private Declare Function CreatePen Lib "gdi32" _
(ByVal nPenStyle As Long, ByVal nWidth As Long, _
ByVal crColor 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 Enum PenStyle
PS_SOLID = 0
PS_DASH = 1
PS_DOT = 2
PS_DASHDOT = 3
PS_DASHDOTDOT = 4
End Enum
Private Sub DrawDottedLine(lngStartX, lngStartY, lngEndX, lngEndY)
Dim pt As POINTAPI
Dim hpen As Long
Dim hpenOLD As Long
MhDC = CreateMetaFile("C:\MyFolder\MyFile.wmf"
If MhDC = 0 Then
MsgBox "Error creating metafile."
Exit Sub
End If
Dim hMF As Long
hpen = CreatePen(PS_DOT, 1, vbBlack)
hpenOLD = SelectObject(MhDC, hpen)
MoveToEx MhDC, lngStartX, lngStartY, pt
LineTo MhDC, lngEndX, lngEndY
hMF = CloseMetaFile(MhDC)
DeleteMetaFile hMF
End Sub
Private Sub Command1_Click()
DrawDottedLine 0, 0, 100, 100
End Sub