+ 5 And MyPoint.y > MyRect.Bottom - 5
Screen.MousePointer = vbSizeNESW
Action = “LeftDown”
''鼠标位于窗体左边
Case MyPoint.x < MyRect.Left + 5
''水平双向鼠标指针
Screen.MousePointer = vbSizeWE
Action = “Left”
''鼠标位于窗体右边
Case MyPoint.x > MyRect.Right - 5
Screen.MousePointer = vbSizeWE
Action = “Right”
''鼠标位于窗体上方
Case MyPoint.y < MyRect.Top + 5
''垂直双向鼠标指针
Screen.MousePointer = vbSizeNS
Action = “Up”
''鼠标位于窗体下方
Case MyPoint.y > MyRect.Bottom - 5
Screen.MousePointer = vbSizeNS
Action = “Down”
''鼠标位于窗体其他位置
Case Else
''默认鼠标指针
Screen.MousePointer = 0
Action = “Move”
End Select
End Sub
当利用SendMessage函数由系统向窗口发送改变大小的信息时,只要将上面移动窗体的语句“SendMessage Me.hwnd, WM_SYSCOMMAND, SC_MOVE, 0”中的第3个参数改为相应的常数即可。
VB中&HF001~&HF008分别是从左、右、上、左上、右上、下、左下、右下8个方向改变窗体大小的常数。结合移动窗体的代码,将上述Form_MouseDown事件的代码综合如下(也可以把这8个常数声明为自定义常数):
Private Sub Form_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
''按下鼠标左键
If Button = vbLeftButton Then
''为当前的应用
程序释放鼠标捕获
ReleaseCapture
Select Case Action
Case “Left”
SendMessage Me.hwnd, WM_SYSCOMMAND, &HF001, 0
Case “Right”
SendMessage Me.hwnd, WM_SYSCOMMAND, &HF002, 0
Case “Up”
SendMessage Me.hwnd, WM_SYSCOMMAND, &HF003, 0
Case “LeftUp”
SendMessage Me.hwnd, WM_SYSCOMMAND, &HF004, 0
Case “RightUp”
SendMessage Me.hwnd, WM_SYSCOMMAND, &HF005, 0
Case “Down”
SendMessage Me.hwnd, WM_SYSCOMMAND, &HF006, 0
Case “LeftDown”
SendMessage Me.hwnd, WM_SYSCOMMAND, &HF007, 0
Case “RightDown”
SendMessage Me.hwnd, WM_SYSCOMMAND, &HF008, 0
Case “Move”
SendMessage Me.hwnd, WM_SYSCOMMAND, SC_MOVE, 0
End Select
End If
End Sub