VB 获取进程并修改标题

怎么样用VB来获取一个进程,并修改它窗口的标题啊?哪位大虾有源码,发下。。。感激。。... 怎么样用VB来获取一个进程,并修改它窗口的标题啊? 哪位大虾有源码,发下。。。感激。。 展开
 我来答
远风的梦想家
2010-08-02 · TA获得超过2550个赞
知道大有可为答主
回答量:1389
采纳率:0%
帮助的人:0
展开全部
Option Explicit

Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function GetWindow Lib "user32" (ByVal hwnd As Long, ByVal wCmd As Long) As Long
Private Declare Function GetDesktopWindow Lib "user32" () As Long
Private Declare Function SetWindowText Lib "user32" Alias "SetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String) As Long

Private Const GW_HWNDFIRST = 0
Private Const GW_HWNDNEXT = 2
Private Const GW_CHILD = 5
Private Declare Function CreateToolhelpSnapshot Lib "kernel32" Alias "CreateToolhelp32Snapshot" (ByVal lFlags As Long, ByVal lProcessID As Long) As Long
Private Declare Function ProcessFirst Lib "kernel32" Alias "Process32First" (ByVal hSnapShot As Long, uProcess As PROCESSENTRY32) As Long
Private Declare Function ProcessNext Lib "kernel32" Alias "Process32Next" (ByVal hSnapShot As Long, uProcess As PROCESSENTRY32) As Long
Private Declare Function TerminateProcess Lib "kernel32" (ByVal hProcess As Long, ByVal uExitCode As Long) As Long
Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Const MAX_PATH As Integer = 260
Private Type PROCESSENTRY32
dwSize As Long
cntUsage As Long
th32ProcessID As Long
th32DefaultHeapID As Long
th32ModuleID As Long
cntThreads As Long
th32ParentProcessID As Long
pcPriClassBase As Long
dwFlags As Long
szExeFile As String * MAX_PATH
End Type
Const TH32CS_SNAPheaplist = &H1
Const TH32CS_SNAPPROCESS = &H2
Const TH32CS_SNAPthread = &H4
Const TH32CS_SNAPmodule = &H8
Const TH32CS_SNAPall = TH32CS_SNAPPROCESS + TH32CS_SNAPheaplist + TH32CS_SNAPthread + TH32CS_SNAPmodule
Private Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hwnd As Long, lpdwProcessId As Long) As Long

Private Sub Command1_Click()
Dim i As Long, lPid As Long
Dim Proc As PROCESSENTRY32
Dim Tname As String
Dim hSnapShot As Long
Dim TC As Long
Dim lphand As Long
hSnapShot = CreateToolhelpSnapshot(TH32CS_SNAPall, 0) '获得进程“快照”的句柄
Proc.dwSize = Len(Proc)
lPid = ProcessFirst(hSnapShot, Proc) '获取第一个进程的PROCESSENTRY32结构信息数据
i = 0
Do While lPid <> 0 '当返回值非零时继续获取下一个进程
Tname = Left(Proc.szExeFile, InStr(Proc.szExeFile, Chr(0)) - 1)
If Tname = "IEXPLORE.EXE" Then
Call GetWindowList(Proc.th32ProcessID)
End If
i = i + 1
lPid = ProcessNext(hSnapShot, Proc) '循环获取下一个进程的PROCESSENTRY32结构信息数据
Loop
CloseHandle hSnapShot '关闭进程“快照”句柄
End Sub

Private Sub GetWindowList(ByVal Pid As Long) '查找所有窗体
Dim hwnd As Long
Dim s As String
Dim kPid As Long
ReDim wdt(0 To 0) As String
hwnd = GetDesktopWindow()

hwnd = GetWindow(hwnd, GW_CHILD Or GW_HWNDFIRST)

While hwnd <> 0
hwnd = GetWindow(hwnd, GW_HWNDNEXT)

GetWindowThreadProcessId hwnd, kPid
If kPid = Pid Then
SetWindowText hwnd, "aaaaaaaaaa"
End If
Wend

End Sub

'以上是把所有的IE窗口标题全部改掉的,不明白的百度HI我
落雪待玉人
2010-08-02 · TA获得超过170个赞
知道小有建树答主
回答量:286
采纳率:0%
帮助的人:165万
展开全部
好高深,做不到。算是支持一下。
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
百度网友d4f370c7e
2010-08-02 · TA获得超过2676个赞
知道小有建树答主
回答量:3606
采纳率:100%
帮助的人:1684万
展开全部
我试过很久只能获取进程,那个标题很难改。
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 更多回答(1)
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

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

类别

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

说明

0/200

提交
取消

辅 助

模 式