鼠标左键点着FORM图中间不松,拖动鼠标使窗体跟鼠标一起动

来源:百度知道 编辑:UC知道 时间:2024/09/23 15:16:47
就是点在FORM窗体的中间(放控件的地方,不是边边),不松鼠标,拖动,使起达到不把鼠标点在边边也能拖动窗体的效果

不好意思,0871love的代码有点小错误,楼主要的是窗口的拖动,而不是picture1的,所以,呵呵...
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)
If Button = 1 Then '左键拖动窗体
Call ReleaseCapture
Call SendMessage(Hwnd, WM_NCLBUTTONDOWN, HTCAPTION, 0)
End If
End Sub

'**********************************************************************************************
'拖动窗体 API
Private Declare Function ReleaseCapture Lib "user32" () As Long

Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" ( _