非洲红木酸枝茶具套装:帮忙看看这一小段代码哪里有问题(vb+api)

来源:百度文库 编辑:神马品牌网 时间:2024/04/29 17:25:11
Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Declare Function CreateSolidBrush Lib "gdi32" (ByVal crColor As Long) As Long
Declare Function FillRect Lib "user32" (ByVal hdc As Long, lpRect As RECT, ByVal hBrush As Long) As Long
Declare Function MoveToEx Lib "gdi32" (ByVal hdc As Long, ByVal X As Long, ByVal Y As Long, lpPoint As Any) As Long
Declare Function LineTo Lib "gdi32" (ByVal hdc As Long, ByVal X As Long, ByVal Y As Long) As Long
Public r As RECT

‘--------以上为标准模块中内容,以下为窗体中内容

Public phdc
Public pbrush

Private Sub Form_Activate()
phdc = Picture1.hdc
pbrush = CreateSolidBrush(&HFFFFFF)
r.Bottom = Picture1.ScaleHeight
r.Left = 0
r.Right = Picture1.ScaleWidth
r.Top = 0
End Sub

Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
FillRect phdc, r, pbrush
For i = -10 To 10
For j = -10 To 10
MoveToEx phdc, 1, 1, Null
LineTo phdc, X + i, Y + j
Next j
Next i
Picture1.Refresh
End Sub

以上代码会导致非法操作
为什么呢

改后:

//////////////////////////////////////
Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim ppt As POINTAPI
FillRect phdc, r, pbrush
For i = -10 To 10
For j = -10 To 10
MoveToEx phdc, 1, 1,0 ///////不要传入null,在VB中不要传null,要么就传0。
LineTo phdc, X + i, Y + j
Next j
Next i
Picture1.Refresh
End Sub

//////////////////////////////////////最好是
加个结构:
Type POINTAPI
x As Long
y As Long
End Type
然后:。。。
Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single)
Dim ppt As POINTAPI

FillRect phdc, r, pbrush
For i = -10 To 10
For j = -10 To 10
MoveToEx phdc, 1, 1, ppt
LineTo phdc, x + i, y + j
Next j
Next i
Picture1.Refresh
End Sub