top
Loading...
列舉系統中所有窗口

程序說明:

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

作者:http://www.zhujiangroad.com
來源:http://www.zhujiangroad.com
北斗有巢氏 有巢氏北斗