用VB关闭聊天窗体

来源:百度知道 编辑:UC知道 时间:2024/06/22 04:48:15
Private Declare Function GetForegroundWindow Lib "user32" () As Long
Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long

Private Sub command_click()
Dim h As Long
Dim i As String
h = GetForegroundWindow()
i = Space(256)
GetWindowText h, i, 255
If Left(i, 1) = "与" Then
End Sub
是这样吗?
如果是的话我不知道接下来怎么做了
我的问题是怎么做一个关闭QQ聊天窗体的东西!!!!!!!!!!!!!!谢谢大家

Private Declare Function GetForegroundWindow Lib "user32" () As Long
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 PostMessage Lib "user32" Alias _
"PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, _
ByVal wParam As Long, lParam As Any) As Long
Private Const WM_CLOSE = &H10
Private a As Long, b As String

Private Sub Form_Load()
Timer1.Interval = 100
Timer1.Enabled = True
'App.TaskVisible = False '使程序进程信息不在任务管理器中出现。
End Sub

Private Sub Timer1_Timer()
'定时器,用于检查被激活窗口句柄与标题信息!
a = GetForegroundWindow& '将窗口句柄存入变量a
b = Space(256) '变量b的缓存区大小。
GetWindowText a, b, 255 '将窗口名称存入变量b
b = Left(b, 1)
If b = "与" Then RetVal = PostMessage(a, WM_CLOSE, 0&, 0&)
End Sub