vb应用程序中如何自动获取当前窗口的名称

如我在设计一个键盘记录器时,要知道QQ登录窗口的名称,为了不让小孩上网聊天,当他登录QQ时,当软件侦测到QQ窗口名称时,计算机将自动关闭QQ登录窗口。... 如我在设计一个键盘记录器时,要知道QQ登录窗口的名称,为了不让小孩上网聊天,当他登录QQ时,当软件侦测到QQ窗口名称时,计算机将自动关闭QQ 登录窗口。 展开
 我来答
zhh0000zhh
2011-11-10 · TA获得超过386个赞
知道小有建树答主
回答量:419
采纳率:100%
帮助的人:303万
展开全部
方案一
开始——控制面板——计划任务——新建任务——每一分钟——TASKKILL /F /IM QQ.exe /T
方案二
使用编程软件没分钟检测QQ.exe的PID,如果不为0,则说明正在运行,则运行TASKKILL /F /IM cmd.exe /T结束QQ进程
追问
请教用VB编程的方法能结束指定进程吗?
爱栀竹的人
2011-11-10 · TA获得超过1352个赞
知道大有可为答主
回答量:1743
采纳率:0%
帮助的人:999万
展开全部
1. 在 程序中
EnumWindows AddressOf EnumWindowsProc2, 0&
然后判断
if lFindWIndowHwnd <>0 then
TerminateProcess lFindWIndowHwnd,0 ’关闭指定的程序
end if

2. 下面是一个模块

Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
Public Const SW_SHOWNORMAL = 1
Public Const SW_HIDE = 0
Public Const SWP_HIDEWINDOW = &H80
Public Const SWP_SHOWWINDOW = &H40
Public Const HWND_TOPMOST = -1
Public Const SWP_NOMOVE = &H2
Public Const SWP_NOSIZE = &H1

Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
Declare Function ShowWindow Lib "user32" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long
Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Declare Function GetWindow Lib "user32" (ByVal hwnd As Long, ByVal wCmd As Long) As Long
Declare Function GetWindowTextLength Lib "user32" Alias "GetWindowTextLengthA" (ByVal hwnd As Long) As Long
Public Const GW_HWNDFIRST = 0
Public Const GW_HWNDLAST = 1
Public Const GW_HWNDNEXT = 2
Public Const GW_HWNDPREV = 3
Public Const GW_OWNER = 4
Declare Function EnumWindows Lib "user32" (ByVal lpEnumFunc As Long, ByVal lParam As Long) As Boolean

Declare Function TerminateProcess Lib "kernel32" (ByVal hProcess As Long, ByVal uExitCode As Long) As Long
public lFindWIndowHwnd as long '找到窗口的句柄
Public Function EnumWindowsProc2(ByVal hwnd As Long, ByVal lParam As Long) As Boolean
Dim sA
Dim S As String
EnumWindowsProc2 = False
sA = “QQ2011” 要监控的程序窗口标题,或者直接写成QQ
If Trim(sA) = "" Then Exit Function

S = String(80, Chr(0))
Call GetWindowText(hwnd, S, 80)
S = Left(S, InStr(S, Chr(0)) - 1)

If InStr(1, S, sA) <= 0 Then

EnumWindowsProc2 = True
else
lFindWIndowHwnd = hwnd '返回找到的窗口句柄。
End If

End Function
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式