|
程序说明:
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
没有相关教程
|