首页 » Visual Basic » VB枚举所有顶级窗体句柄

VB枚举所有顶级窗体句柄

Private Sub Form_Load()
    Me.AutoRedraw = tre
    EnumWindows AddressOf EnumWindowsProc, ByVal 0&
End Sub
 
'上面是窗体中的代码,下面是模块中的代码,窗体上添个list控件  
Declare Function EnumWindows Lib "user32" (ByVal lpEnumFunc As Long, ByVal lParam As Long) As Boolean
Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Declare Function GetWindowTextLength Lib "user32" Alias "GetWindowTextLengthA" (ByVal hwnd As Long) As Long
 
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
    EnumWindowsProc = True
End Function

, , , ,

转发到新浪微博 转发到新浪微博

目前这篇文章有26条评论(Rss)

我要评论