Private Declare Function GetWindow Lib "user32" (ByVal hwnd As Long, ByVal wCmd As Long) As Long Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long Private Declare Function GetWindowTextLength Lib "user32" Alias "GetWindowTextLengthA" (ByVal hwnd As Long) As Long Private Const GW_HWNDFIRST = 0 Private Const GW_HWNDNEXT = 2 Private Const GWL_STYLE = (-16) Private Const WS_VISIBLE = &H10000000 Private Const WS_BORDER = &H800000Private Sub Command1_Click() Dim hwcurr As Long Dim intLen As Long Dim strTitle As String '列表清空 List1.Clear '获得第一个窗口的句柄 hwcurr = GetWindow(Me.hwnd, GW_HWNDFIRST) '循环,找出主窗口列表中所有的窗口 Do While hwcurr If hwcurr <> Me.hwnd And TaskWindow(hwcurr) Then '获得该窗口的标题长度及标题 intLen = GetWindowTextLength(hwcurr) + 1 strTitle = Space$(intLen) intLen = GetWindowText(hwcurr, strTitle, intLen) If intLen > 0 Then List1.AddItem strTitle End If End If '获得下一个窗口的句柄 hwcurr = GetWindow(hwcurr, GW_HWNDNEXT) Loop End Sub
抱歉!忘了一段代码 dim IsTask as longPrivate Declare Function GetWindow Lib "user32" (ByVal hwnd As Long, ByVal wCmd As Long) As Long Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long Private Declare Function GetWindowTextLength Lib "user32" Alias "GetWindowTextLengthA" (ByVal hwnd As Long) As Long Private Const GW_HWNDFIRST = 0 Private Const GW_HWNDNEXT = 2 Private Const GWL_STYLE = (-16) Private Const WS_VISIBLE = &H10000000 Private Const WS_BORDER = &H800000Private Sub Command1_Click() Dim hwcurr As Long Dim intLen As Long Dim strTitle As String '列表清空 List1.Clear '获得第一个窗口的句柄 hwcurr = GetWindow(Me.hwnd, GW_HWNDFIRST) '循环,找出主窗口列表中所有的窗口 Do While hwcurr If hwcurr <> Me.hwnd And TaskWindow(hwcurr) Then '获得该窗口的标题长度及标题 intLen = GetWindowTextLength(hwcurr) + 1 strTitle = Space$(intLen) intLen = GetWindowText(hwcurr, strTitle, intLen) If intLen > 0 Then List1.AddItem strTitle End If End If '获得下一个窗口的句柄 hwcurr = GetWindow(hwcurr, GW_HWNDNEXT) Loop End Sub'判断窗口是否符合要求 Function TaskWindow(hwcurr As Long) As Long Dim lngStyle As Long '获取窗口风格,并判断是否符合要求 lngStyle = GetWindowLong(hwcurr, GWL_STYLE) If (lngStyle And IsTask) = IsTask Then TaskWindow = True End If End Function
Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Private Declare Function GetWindowTextLength Lib "user32" Alias "GetWindowTextLengthA" (ByVal hwnd As Long) As Long
Private Const GW_HWNDFIRST = 0
Private Const GW_HWNDNEXT = 2
Private Const GWL_STYLE = (-16)
Private Const WS_VISIBLE = &H10000000
Private Const WS_BORDER = &H800000Private Sub Command1_Click()
Dim hwcurr As Long
Dim intLen As Long
Dim strTitle As String
'列表清空
List1.Clear
'获得第一个窗口的句柄
hwcurr = GetWindow(Me.hwnd, GW_HWNDFIRST)
'循环,找出主窗口列表中所有的窗口
Do While hwcurr
If hwcurr <> Me.hwnd And TaskWindow(hwcurr) Then
'获得该窗口的标题长度及标题
intLen = GetWindowTextLength(hwcurr) + 1
strTitle = Space$(intLen)
intLen = GetWindowText(hwcurr, strTitle, intLen)
If intLen > 0 Then
List1.AddItem strTitle
End If
End If
'获得下一个窗口的句柄
hwcurr = GetWindow(hwcurr, GW_HWNDNEXT)
Loop
End Sub
dim IsTask as longPrivate Declare Function GetWindow Lib "user32" (ByVal hwnd As Long, ByVal wCmd As Long) As Long
Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Private Declare Function GetWindowTextLength Lib "user32" Alias "GetWindowTextLengthA" (ByVal hwnd As Long) As Long
Private Const GW_HWNDFIRST = 0
Private Const GW_HWNDNEXT = 2
Private Const GWL_STYLE = (-16)
Private Const WS_VISIBLE = &H10000000
Private Const WS_BORDER = &H800000Private Sub Command1_Click()
Dim hwcurr As Long
Dim intLen As Long
Dim strTitle As String
'列表清空
List1.Clear
'获得第一个窗口的句柄
hwcurr = GetWindow(Me.hwnd, GW_HWNDFIRST)
'循环,找出主窗口列表中所有的窗口
Do While hwcurr
If hwcurr <> Me.hwnd And TaskWindow(hwcurr) Then
'获得该窗口的标题长度及标题
intLen = GetWindowTextLength(hwcurr) + 1
strTitle = Space$(intLen)
intLen = GetWindowText(hwcurr, strTitle, intLen)
If intLen > 0 Then
List1.AddItem strTitle
End If
End If
'获得下一个窗口的句柄
hwcurr = GetWindow(hwcurr, GW_HWNDNEXT)
Loop
End Sub'判断窗口是否符合要求
Function TaskWindow(hwcurr As Long) As Long
Dim lngStyle As Long
'获取窗口风格,并判断是否符合要求
lngStyle = GetWindowLong(hwcurr, GWL_STYLE)
If (lngStyle And IsTask) = IsTask Then
TaskWindow = True
End If
End Function