b13690976754
来自:207寝室
等级:小飞侠
文章:1028
积分:8380
注册:2006年11月9日
-------------------------
这样的问题……
'实例二(窗体鼠标左键拖动时移动窗体)
'主要用于无边框窗体移动,当然也可以移动有边框的窗体。
'******************************************************************************************************************
'*********** 作 者 :南宫飘雪
'*********** Email :joforn@sohu.com
'*********** QQ号码:42978116
'*********** Blog :http://blog.163.com/joforn/
'******************************************************************************************************************
Option Explicit
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Declare Function ReleaseCapture Lib "user32" () As Long
Private Declare Sub mouse_event Lib "user32" (ByVal dwFlags As Long, ByVal dx As Long, ByVal dy As Long, ByVal cButtons As Long, ByVal dwExtraInfo As Long)
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
theForm_Move Button
End Sub
Private Sub theForm_Move(ByVal Button As Integer)
If Button <> vbLeftButton Then Exit Sub
ReleaseCapture
SendMessage hwnd, &HA1, 2, 0
mouse_event &H4, 0, 0, 0, 0 '这条不用,但在某些特殊情况下就要用了(我自己写的程序里不用就会出错。呵)。
End Sub
'这是我的API函数查询管理器中的实例
[此贴子已经被作者于2007-4-23 20:56:54编辑过]
唉``给你写个简单的吧
Private Declare Function ReleaseCapture Lib "user32" () As Long
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Const WM_NCLBUTTONDOWN = &HA1
Private Const HTCAPTION = 2
Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
ReleaseCapture
SendMessage hwnd, WM_NCLBUTTONDOWN, HTCAPTION, 0&
End Sub
Dim mouseX, mouseY, currX, currY As Single
Dim flag As Boolean
Private Sub Form_Load()
flag = False
End Sub
Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
mouseX = X
mouseY = Y
flag = True
End Sub
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = vbKeyLButton And flag = True Then
currX = Me.Left - mouseX + X
currY = Me.Top - mouseY + Y
Me.Move currX, currY
End If
End Sub
Private Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
flag = False
End Sub