找到了。用以下代码就可以了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 WindowFromPoint Lib "user32" (ByVal x As Long, ByVal y As Long) As Long Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long '声明过程 Private Const WM_GETTEXT = &HD Private Const WM_SETTEXT = &HC Private Type POINTAPI x As Long y As Long End Type Private Sub Timer1_Timer() Dim Shu As POINTAPI Dim Str As String * 300 GetCursorPos Shu SendMessage WindowFromPoint(Shu.x, Shu.y), WM_GETTEXT, 299, ByVal Str Label1.Caption = Str '使获得的句柄在label1里显示End Sub
Private Declare Function WindowFromPoint Lib "user32" (ByVal x As Long, ByVal y As Long) As Long
Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
'声明过程
Private Const WM_GETTEXT = &HD
Private Const WM_SETTEXT = &HC Private Type POINTAPI
x As Long
y As Long
End Type Private Sub Timer1_Timer()
Dim Shu As POINTAPI
Dim Str As String * 300
GetCursorPos Shu
SendMessage WindowFromPoint(Shu.x, Shu.y), WM_GETTEXT, 299, ByVal Str
Label1.Caption = Str '使获得的句柄在label1里显示End Sub
我这里只是得到caption或text中的文字就可以了。如果是任意地方取词,像金山词霸一样,就得拦截API,太麻烦了。