欢迎来到Java学习网!
设为首页 | 加入收藏
当前位置: 首页 > 编程开发 > VB语言 >

Option Explicit
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 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 LCMapString Lib "kernel32" Alias "LCMapStringA" (ByVal Locale As Long, ByVal dwMapFlags As Long, ByVal lpSrcStr As String, ByVal cchSrc As Long, ByVal lpDestStr As String, ByVal cchDest As Long) As Long
Private Const EM_REPLACESEL = &HC2
Private Const BM_CLICK = &HF5
Private Const WM_GETTEXTLENGTH = &HE
Private Const WM_GETTEXT = &HD
Private Const WM_CLOSE = &H10
Dim H As Long, L As Long, S As String

Dim Hwnd1 As Long, Hwnd2 As Long, I As Long, Hwnd3 As Long

Private Sub Command1_Click()
Timer1.Enabled = True
Timer1.Interval = 1000 * Text2.Text
End Sub

Private Sub Command2_Click()
Timer1.Enabled = False
End Sub

Private Sub Timer1_Timer()
H = FindWindowEx(0, H, "#32770", vbNullString)
If H > 0 Then
L = SendMessage(H, WM_GETTEXTLENGTH, 0, ByVal 0)
S = String(L, " ")
SendMessage H, WM_GETTEXT, L + 1, ByVal S
If (S Like "*聊天中") Or (S Like "*群") Or (S Like "*会话中") Then
Hwnd1 = FindWindowEx(H, 0, "#32770", vbNullString)
Hwnd2 = FindWindowEx(Hwnd1, 0, "Button", "发送(&S)")
Hwnd3 = FindWindowEx(Hwnd1, 0, "Button", "关闭(&C)")
Hwnd1 = FindWindowEx(Hwnd1, Hwnd2, "AfxWnd42", vbNullString)
Hwnd1 = FindWindowEx(Hwnd1, 0, "RichEdit20A", vbNullString)
'追加消息
SendMessage Hwnd1, &HC2, 0, ByVal Text1.Text
'发送消息
SendMessage Hwnd2, &HF5, 0, ByVal 0
'关闭窗口
'SendMessage Hwnd3, &HF5, 0, ByVal 0

End If
End If
End Sub

    相关教程
    推荐内容