求教:Mouse在窗口中的移动相关问题!

oo渣渣oo 2000-08-15 06:03:00
当Mouse在窗口中移动时,我想取得Mouse下的控件的名称,如何做?
比如:Mouse在Command1上时取出来为"Command1",而在Command2上时
取出来为"Command2".

另:不要告诉我用Mouse_Move事件!这我知道。我问的是用API!!!
...全文
93 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
shines77 2000-08-15
  • 打赏
  • 举报
回复
heng_s: 你是在本程序里用还是,对任意的一个窗体来说,如果是对任意窗体,只要知道控件的句柄,用GetWindowText()即可获得。
具体使用程序如下:

Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Private Declare Function SetWindowText Lib "user32" Alias "SetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String) As Long
Private Sub Form_Activate()
Dim MyStr As String
'Create a buffer
MyStr = String(100, Chr$(0))
'Get the windowtext
GetWindowText Me.hwnd, MyStr, 100
'strip the rest of buffer
MyStr = Left$(MyStr, InStr(MyStr, Chr$(0)) - 1)
'Triple the window's text
MyStr = MyStr + MyStr + MyStr
'Set the new window text
SetWindowText Me.hwnd, MyStr
End Sub

如果想获得任意控件的句柄也很简单,不知是否感兴趣:)
用GetCursorPos()和WindowFromPoint()实现。
opkj 2000-08-15
  • 打赏
  • 举报
回复
可以使用广播事件。
moyixin 2000-08-15
  • 打赏
  • 举报
回复
你可以定义mouse事件的hook函数,参数中有窗口的局柄,一定要用dll来做,这样代码才能注入到对方应用程序中。

7,759

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧