开发者

CreatePen GDI function problem on Windows 7

CreatePen GDI function does not work on Windows 7 when pen width开发者_如何转开发 is 3 or 4 (LineTo draws nothing). It works for 0 - 2 width. In all cases PS_SOLID pen style was used.


LineTo does not include the final point of the line. Try a different endcap setting to see if it makes a difference.


does it return a handle or NULL?
have you considered using CreatePenIndirect and the structure LOGPEN?
http://msdn.microsoft.com/en-us/library/dd183510(v=VS.85).aspx
http://msdn.microsoft.com/en-us/library/dd145041(v=VS.85).aspx
this just works fine on my computer, Windows 7 x64:

Option Explicit

Private Declare Function CreatePen Lib "gdi32" ( _
   ByVal nPenStyle As Long, _
   ByVal nWidth As Long, _
   ByVal crColor 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 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

Dim x As Long
Dim y As Long
Dim w As Long

Private Sub Command1_Click()
   w = w + 1
   Dim hpen As Long: hpen = CreatePen(0, w, 0)
   Dim ret As Long: ret = SelectObject(Me.hDC, hpen)
   If ret <> 0 Then
       x = x + 10
       y = y + 10
       Call LineTo(Me.hDC, x, y)
   End If
   Call DeleteObject(hpen)
End Sub

click the button more times

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜