列举系统中所有窗口

2008-04-09 04:42:39来源:互联网 阅读 ()

新老客户大回馈,云服务器低至5折

程序说明:

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

标签:

版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有

上一篇:每次启动 Windows 时自动运行程序

下一篇:“回调”(CallBacks)的实现

热门词条
热门标签