获取qq聊天窗口文本框句柄
大侠们,给点思路。怎么获取QQ2011聊天窗口文本框的句柄啊,我想获取文本后,向文本框发送数据。
[最优解释]
楼上的挺好用,qq名称要用聊天窗体名……
学习并拿来了
[其他解释]
同求!!!
坐等大虾!
[其他解释]
简单的FindWindow和FindWindowEx是不能获取的。qq的窗体是自行绘制的。
[其他解释]
Option Explicit
Private Const WM_CHAR = &H102
Private Const WM_LBUTTONDOWN = &H201
Private Const WM_LBUTTONUP = &H202
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
Private Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Private Declare Function GetFocus Lib "user32" () As Long
'在TM2009、QQ2011下通过
Private Sub Command1_Click()
Dim lngP As Long
Dim lngTextHwnd As Long
Dim lngEnterHwnd As Long
'窗体句柄,经过试验也就是输入文本框的句柄,和SPY++的结果完全相符
lngTextHwnd = FindWindow("TXGuiFoundation", "qq名称")
Call subPostString(lngTextHwnd, "ABC") '将字符串发送给输入文本框
End Sub
'将一个字符串通过PostMessage传送出去
Private Sub subPostString(ByVal lngHandle As Long, ByVal strP As String)
Dim intP As Integer
Dim intK As Integer
Dim lngAsc As Long
Dim lngP As Long
Dim strT As String
On Error GoTo errSub
For intP = 0 To Len(strP) - 1
strT = Mid(strP, intP + 1, 1)
If Asc(strT) <= 0 Then
lngAsc = AscW(StrConv(strT, 128))
If lngAsc < 0 Then
lngAsc = lngAsc + 65536 '2^16
End If
Else
lngAsc = Asc(strT)
End If
lngP = PostMessage(lngHandle, WM_CHAR, lngAsc, 0)
Next intP
Exit Sub
errSub:
End Sub