频道直达 - 专题 - 新闻 - 技巧 - 组网 - 开发 - 安全 - web编程 - 图像 - 操作系统 - 数据库 - 教育 - 旅游 - 健康 - 时尚 - 驱动 - 软件 - 游戏 - 多媒体 - ERP - 讨论组

VB列举系统中所有窗口

来源:yesky 作者: 出处:巧巧读书 2006-09-10 进入讨论组
QQRead:http://www.qqread.com/vb/i207825.html

程序说明:

EnumWindows : 列举系统中的所有窗口
GetWindowText : 取的窗口的标题
EnumWindowsProc :用户自定义函数,给EnumWindows调用,以达到列举的目的
AddressOf : 取的函数的地址,此函数一定在放在 Module 中

所有的控件:

List1
Command1
Command1

程序代码:

Module1

Public Declare Function EnumWindows Lib "user32" (ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long
Public Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long

Public Declare Function GetWindowTextLength Lib "user32" Alias "GetWindowTextLengthA" (ByVal hwnd As Long) As Long


Public Function EnumWindowsProc2(ByVal hwnd As Long, ByVal lParam As Long) As Boolean

Dim S As String

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

If Len(S) > 0 Then
Form1.List1.AddItem S
End If

EnumWindowsProc2 = True

End Function

Public Function EnumWindowsProc(ByVal hwnd As Long, ByVal lParam As Long) As Boolean
Dim sSave As String, Ret As Long
Ret = GetWindowTextLength(hwnd)
sSave = Space(Ret)
GetWindowText hwnd, sSave, Ret + 1
Form1.List1.AddItem Str$(hwnd) + " " + sSave
'continue enumeration
EnumWindowsProc = True
End Function

Form1

Private Sub Command1_Click()

List1.Clear
EnumWindows AddressOf EnumWindowsProc2, 0&
End Sub

Private Sub Command2_Click()


List1.Clear
EnumWindows AddressOf EnumWindowsProc, 0&

End Sub

Private Sub Form_Load()

End Sub

更多文章 更多内容请看系统优化大全系统安全设置系统安装手册专题,或进入讨论组讨论。
收藏此文】【 】【打印】【关闭
相关图文阅读
频道图文推荐
健 康 咨 询
时 尚 咨 询
巧巧读书宗旨
相关专题
最新论坛文章
站内各频道最新更新文档
站内最新制作专题
热门关键字导读
Photoshop教 程照片处理 照片制作 PS快捷键 抠图
计 算 机 故 障XP系统修复
艺 术 与 设 计设计 流媒体 设计欣赏 边框
计 算 机 安 全ARP
站内频道文章精选
巧巧电脑频道编辑信箱  告诉我们您想看的专题或文章