乐筑天下

搜索
欢迎各位开发者和用户入驻本平台 尊重版权,从我做起,拒绝盗版,拒绝倒卖 签到、发布资源、邀请好友注册,可以获得银币 请注意保管好自己的密码,避免账户资金被盗
查看: 50|回复: 2

请问:如何枚举当前打开的窗口名称,指WINDOWS进程

[复制链接]

15

主题

127

帖子

6

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
187
发表于 2004-7-16 10:53:00 | 显示全部楼层 |阅读模式
我现在想用API函数枚举出当前WINDOWS里打开的窗口,然后把它们的标题列表出来!
回复

使用道具 举报

26

主题

589

帖子

10

银币

中流砥柱

Rank: 25

铜币
693
发表于 2004-7-16 20:02:00 | 显示全部楼层
  1. Option Explicit
  2. Private Declare Function GetDesktopWindow Lib "user32" () As Long
  3. Private Declare Function GetWindow Lib "user32" (ByVal hwnd As Long, ByVal wCmd As Long) As Long
  4. Private Declare Function GetParent Lib "user32" (ByVal hwnd As Long) As Long
  5. Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
  6. Private Declare Function IsWindowVisible Lib "user32" (ByVal hwnd As Long) As Long
  7. Private Const GW_HWNDNEXT = 2
  8. Private Const GW_CHILD = 5
  9. Private Sub Form_Load()
  10.        '使用前在窗体上创建一个ListBox控件,名称为List1
  11.        Dim hwnd As Long
  12.        hwnd = GetDesktopWindow() '返回桌面的句柄
  13.        hwnd = GetWindow(hwnd, GW_CHILD) '返回桌面的第一个子窗口
  14.        Dim sWindowText As String
  15.        Dim r As Long
  16.        Do While hwnd  0
  17.                If GetParent(hwnd) = 0 Then '顶层窗口
  18.                        If IsWindowVisible(hwnd) Then '窗口状态是显示的
  19.                                sWindowText = String(255, Chr(0))
  20.                                r = GetWindowText(hwnd, sWindowText, 255) '返回窗口的标题
  21.                                sWindowText = Left(sWindowText, r)
  22.                                If sWindowText  "" Then List1.AddItem sWindowText
  23.                        End If
  24.                End If
  25.                hwnd = GetWindow(hwnd, GW_HWNDNEXT) '返回下一个窗口
  26.        Loop
  27. End Sub
回复

使用道具 举报

120

主题

326

帖子

7

银币

中流砥柱

Rank: 25

铜币
806
发表于 2008-3-29 19:51:00 | 显示全部楼层

efan2000
对API有比较深的了解
回复

使用道具 举报

发表回复

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

QQ|关于我们|小黑屋|乐筑天下 繁体中文

GMT+8, 2025-7-5 03:00 , Processed in 1.311937 second(s), 67 queries .

© 2020-2025 乐筑天下

联系客服 关注微信 帮助中心 下载APP 返回顶部 返回列表