用易语言开发 用鼠标取窗口句柄 代码
时间: 2024-03-03 14:49:41 浏览: 636
以下是用易语言开发用鼠标取窗口句柄的代码:
```
'窗口句柄
Dim hWnd As Long
'鼠标点击事件
Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
'获取鼠标所在位置对应的窗口句柄
hWnd = WindowFromPoint(X, Y)
End Sub
'鼠标移动事件
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
'如果有窗口句柄
If hWnd <> 0 Then
'显示窗口句柄
Label1.Caption = "窗口句柄:" & hWnd
End If
End Sub
'鼠标松开事件
Private Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
'清空窗口句柄
hWnd = 0
Label1.Caption = ""
End Sub
```
这段代码实现了在窗口上点击鼠标左键后,可以获取鼠标所在位置对应的窗口句柄,并在鼠标移动时显示窗口句柄。需要注意的是,此代码只能获取当前鼠标所在位置对应的窗口句柄,如果需要获取其他窗口句柄,需要修改相应的参数。
相关问题
用易语言 实现 拖拽取窗口句柄 代码
以下是用易语言实现拖拽取窗口句柄的代码:
```
'窗口句柄
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
```
这段代码实现了在窗口上按下鼠标左键后,可以拖拽窗口并获取窗口句柄。需要注意的是,此代码只适用于拖拽窗口标题栏获取窗口句柄,如果需要获取其他窗口句柄,需要修改相应的参数。
用易语言开发 精易模块 用鼠标取窗口句柄
以下是用易语言开发精易模块用鼠标取窗口句柄的代码:
```
'声明精易模块
Declare Module "user32.dll"
Function WindowFromPoint(ByVal x As Long, ByVal y As Long) As Long
End Declare
'窗口句柄
Dim hWnd As Long
'鼠标点击事件
Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
'获取鼠标所在位置对应的窗口句柄
hWnd = WindowFromPoint(X, Y)
End Sub
'鼠标移动事件
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
'如果有窗口句柄
If hWnd <> 0 Then
'显示窗口句柄
Label1.Caption = "窗口句柄:" & hWnd
End If
End Sub
'鼠标松开事件
Private Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
'清空窗口句柄
hWnd = 0
Label1.Caption = ""
End Sub
```
这段代码和前面用易语言开发用鼠标取窗口句柄的代码实现方法相同,只不过使用了精易模块来声明WindowFromPoint函数。需要注意的是,使用精易模块需要在代码的开头声明该模块。
阅读全文