
ExtCreatePen does not work in Windows 2000 but works in Windows 98
I am using geometric type of pen for drawing sqaure (end cap) lines using
ExtCreatePen.
The below function works in Windows 98 but does not work in Windows 2000.
'
' API Declaration
'
Private Declare Function ExtCreatePen Lib "gdi32" _
(ByVal dwPenStyle&, ByVal dwWidth&, _
lplb As Any, dwStyleCount As Any, lpStyle As Any) As Long
'
' Types
'
Private Type LOGBRUSH
lbStyle As Long
lbColor As Long
lbHatch As Long
End Type
Function DrawLine(ByRef picBox As PictureBox, _
ByVal x1 As Long, y1 As Long, _
ByVal X2 As Long, Y2 As Long, _
) as Boolean
Dim old_pen As Long
Dim new_pen As Long
Dim pen_style As Long
Dim log_brush As LOGBRUSH
Const PS_ENDCAP_SQUARE = &H100
Const PS_JOIN_MITER = &H2000
Const PS_SOLID = 0
Const BS_SOLID = 0
log_brush.lbColor = RGB(200,0,0)
log_brush.lbHatch = 0
log_brush.lbStyle = BS_SOLID
pen_style = PS_GEOMETRIC + PS_ENCAP_SQUARE + PS_JOIN_MITER + PS_SOLID
'
' ExtCreatePen returns a hDC for the created pen.
' if it does not succeed it will return 0 (zero).
'
new_pen = ExtCreatePen(pen_style, _
10, _
log_brush, _
Null, _
Null)
'
' If pen is not created, use the primitive method.
'
If new_pen = 0 Then
DrawLine = False
Exit Function
End If
old_pen = SelectObject(picBox.hdc, _
new_pen)
BeginPath picBox.hdc
MoveToEx picBox.hdc, x1, y1, Null
LineTo picBox.hdc, X2, Y2
EndPath picBox.hdc
StrokePath picBox.hdc
SelectObject picBox.hdc, old_pen
DeleteObject new_pen
DrawLine = True
End Function
In Windows 2000, ExtCreatePen does not return the handle to the pen that is
it does not succeed in creating a pen and hence returns 0.
If any one can help please let me know.
Thanks
Rupesh Kokal.