用易语言 实现 拖拽取窗口句柄 代码
时间: 2024-03-03 11:49:39 浏览: 240
易语言-拖放鼠标取指定窗口句柄
以下是用易语言实现拖拽取窗口句柄的代码:
```
'窗口句柄
Dim hWnd As Long
'鼠标按下事件
Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
'按下左键
If Button = 1 Then
'取得窗口句柄
hWnd = GetCapture()
'设置鼠标捕获
SetCapture(Me.hWnd)
End If
End Sub
'鼠标移动事件
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
'如果有鼠标捕获
If hWnd <> 0 Then
'移动窗口
SendMessage(hWnd, WM_NCLBUTTONDOWN, HTCAPTION, 0&)
End If
End Sub
'鼠标松开事件
Private Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
'释放鼠标捕获
ReleaseCapture
'清空窗口句柄
hWnd = 0
End Sub
```
这段代码实现了在窗口上按下鼠标左键后,可以拖拽窗口并获取窗口句柄。需要注意的是,此代码只适用于拖拽窗口标题栏获取窗口句柄,如果需要获取其他窗口句柄,需要修改相应的参数。
阅读全文