'以下在.Bas中
Type RECT '榘形的四个座标
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Type POINTAPI
x As Long
y As Long
End Type
Declare Function IntersectRect Lib "user32" (lpDestRect As RECT, _
lpSrc1Rect As RECT, lpSrc2Rect As RECT) As Long
Declare Function PtInRect Lib "user32" (lpRect As RECT, _
pt As POINTAPI) As Long
'Check rect1, rect2有没有相交集,若有,则Orect存相交集的四个座标
Public Function GetOverlap(rect1 As RECT, rect2 As RECT, Orect As RECT) _
As Boolean
Dim i As Long
GetOverlap = False
i = IntersectRect(Orect, rect1, rect2)
If i <> 0 Then GetOverlap = True
End Function
'以下在Form中,form中放两个CommandBox
Private Sub Form_Load()
Dim i As Long, rect1 As RECT, rect2 As RECT, rect3 As RECT
Dim oo As Boolean
rect1.Top = Command1.Top
rect1.Left = Command1.Left
rect1.Bottom = Command1.Top + Command1.Height
rect1.Right = Command1.Left + Command1.Width
rect2.Top = Command2.Top
rect2.Left = Command2.Left
rect2.Bottom = Command2.Top + Command2.Height
rect2.Right = Command2.Left + Command2.Width
oo = GetOverlap(rect1, rect2, rect3)
End Sub
|