findwindow循环检索窗口
要获取所有窗口的标题,就应该获取所有窗口的句柄。可是怎么做到的呢?貌似findwindow只能找指定标题的呀。。最好能给出代码~~~~~~~~~~~~...
要获取所有窗口的标题,就应该获取所有窗口的句柄。可是怎么做到的呢?貌似findwindow只能找指定标题的呀。。最好能给出代码~~~~~~~~~~~~
展开
展开全部
恰好我刚写了一个,发给你。一个模块Module1.bas, 一个窗体Form1.frm.代码如下。
===========Module1.bas============
Option Explicit
Public Declare Function GetWindowTextLength Lib "user32" Alias "GetWindowTextLengthA" (ByVal hWnd 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 EnumWindows Lib "user32" (ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long
'lpEnumFunc-EnumWindowsProc函数地址
'lParam-自定义传递参数
Public Function EnumWindowsProc(ByVal hWnd As OLE_HANDLE, ByVal lParam As Long) As Boolean
'hWnd-枚举出来的窗口句柄
'lParam-自定义传递参数
Dim lLen As Long, sWnd As String
lLen = GetWindowTextLength(hWnd) + 1
sWnd = Space(lLen)
GetWindowText hWnd, sWnd, lLen
Debug.Print sWnd
EnumWindowsProc = True
End Function
===========Form1.frm===============
Option Explicit
Private Sub Form_Click() '单击窗体查看效果
EnumWindows AddressOf EnumWindowsProc, 0
End Sub
===========Module1.bas============
Option Explicit
Public Declare Function GetWindowTextLength Lib "user32" Alias "GetWindowTextLengthA" (ByVal hWnd 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 EnumWindows Lib "user32" (ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long
'lpEnumFunc-EnumWindowsProc函数地址
'lParam-自定义传递参数
Public Function EnumWindowsProc(ByVal hWnd As OLE_HANDLE, ByVal lParam As Long) As Boolean
'hWnd-枚举出来的窗口句柄
'lParam-自定义传递参数
Dim lLen As Long, sWnd As String
lLen = GetWindowTextLength(hWnd) + 1
sWnd = Space(lLen)
GetWindowText hWnd, sWnd, lLen
Debug.Print sWnd
EnumWindowsProc = True
End Function
===========Form1.frm===============
Option Explicit
Private Sub Form_Click() '单击窗体查看效果
EnumWindows AddressOf EnumWindowsProc, 0
End Sub
参考资料: 我的空间http://hi.baidu.com/arteriosclerosis/blog/item/11a9c110bb971719b9127b4b.html
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询