怎样用VB获取窗口句柄,进行筛选后将符合的句柄的将标题显示到ListBox中(要全部代码不要思路,谢谢!)

hnnn99 2011-08-21 02:36:37
怎样用VB获取窗口句柄,进行筛选后将符合的句柄的将标题显示到ListBox中, 理由有1个按钮和1个list
按一下按钮就把句柄 在list中显示
...全文
848 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
worldy 2011-08-22
  • 打赏
  • 举报
回复
[Quote=引用楼主 hnnn99 的回复:]
怎样用VB获取窗口句柄,进行筛选后将符合的句柄的将标题显示到ListBox中, 理由有1个按钮和1个list
按一下按钮就把句柄 在list中显示
[/Quote]

伸手党............................................
孤独剑_LPZ 2011-08-22
  • 打赏
  • 举报
回复
lz真懒呀,基本操作
guaiwu326 2011-08-22
  • 打赏
  • 举报
回复
不能这么说哟:

比如我就是业余打发时间学的VB,普通教材上是看不到这些高深的东西,要理解都感到有点困难,在急用时就想有现成的直接用上。

有很多人都不是学计算机专业的,多理解,现在提倡“和谐”了。大家住在天南海北,相识也是有缘。
zoujing1000 2011-08-22
  • 打赏
  • 举报
回复
参见百度
贝隆 2011-08-22
  • 打赏
  • 举报
回复
铜球。。。。。
无·法 2011-08-22
  • 打赏
  • 举报
回复
雄赳赳气昂昂要代码
hnnn99 2011-08-21
  • 打赏
  • 举报
回复
厄...不太会用,我很菜..2楼的能不能把 按钮的代码和怎样显示在list的代码也写出来吧..比如我搜3个同类名的窗口,把这3个都显示在list中
jlf629 2011-08-21
  • 打赏
  • 举报
回复
功能:获取窗口标题及对应的pid值

Option Explicit
'获取窗体标题名声明
Private Const GW_CHILD = 5
Private Const GW_HWNDNEXT = 2
Private Declare Function GetDesktopWindow 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 GetWindow Lib "user32" (ByVal hWnd As Long, ByVal wCmd As Long) As Long

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 * 260
End Type

'获取进程名pid声明
Private Const TH32CS_SNAPheaplist = &H1
Private Const TH32CS_SNAPPROCESS = &H2
Private Const TH32CS_SNAPthread = &H4
Private Const TH32CS_SNAPmodule = &H8
Private Const TH32CS_SNAPall = TH32CS_SNAPPROCESS + TH32CS_SNAPheaplist + TH32CS_SNAPthread + TH32CS_SNAPmodule

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 CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long

'函数功能:获取窗体标题
'参数说明:WndTitle 窗体标题
'返回值:输入某个窗体名的时候显示它的pid值,不输人任何参数则获取所有窗体的标题名
Function FindWindow_EX(Optional ByVal WndTitle As String)
Dim level, iFound, Resu
Dim hWnd As Long, K As Long
Dim sWindowText As String
Dim sClassname As String
Dim sID
hWnd = GetWindow(GetDesktopWindow, GW_CHILD)
Do Until hWnd = 0
DoEvents
'sWindowText = GetWinText(hWnd)
sWindowText = Space$(254)
K = GetWindowText(hWnd, sWindowText, 254)
sWindowText = StrConv(LeftB(StrConv(sWindowText, vbFromUnicode), K), vbUnicode)

If sWindowText = WndTitle Or WndTitle = vbNullString Then
If WndTitle <> "" Then '返回窗口句柄
Resu = hWnd
Exit Do
Else '获取所有窗体的标题名
If sWindowText <> "" Then Resu = Resu & sWindowText & vbNewLine
End If
End If
hWnd = GetWindow(hWnd, GW_HWNDNEXT)
Loop
FindWindow_EX = Resu
End Function

'函数功能:获取进程名pid
'参数说明:ProcName 进程名称
'返回值:进程名的pid值,如有多个则分行显示出来.
Function GetPIDFromProcName(ByVal ProcName As String) As String '根据路径获取被监控进程的进程句柄
Dim lPid As Long, S As String, i As Integer
Dim Proc As PROCESSENTRY32, hSnapshot As Long
Dim mSnapshot As Long
hSnapshot = CreateToolhelpSnapshot(TH32CS_SNAPall, 0) '创建一个snapshot对象
Proc.dwsize = Len(Proc)
lPid = ProcessFirst(hSnapshot, Proc) '获取第一个进程的PROCESSENTRY32结构信息数据
Do While lPid <> 0
mSnapshot = CreateToolhelpSnapshot(TH32CS_SNAPmodule, Proc.th32ProcessID)
S = Proc.szExeFile
i = InStr(S, Chr(0))
If i Then S = Left(S, i - 1)
If LCase(ProcName) = LCase(S) Then '如果找到了,则…
GetPIDFromProcName = GetPIDFromProcName & Proc.th32ProcessID & vbNewLine
End If
CloseHandle (mSnapshot)
lPid = ProcessNext(hSnapshot, Proc) '循环获取下一个进程的PROCESSENTRY32结构信息数据
Loop
CloseHandle hSnapshot
End Function
chinaboyzyq 2011-08-21
  • 打赏
  • 举报
回复
楼下的给代码,谢谢。

1,486

社区成员

发帖
与我相关
我的任务
社区描述
VB API
社区管理员
  • API
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧