|
下記ソースで、複数表示されているIEやエクスプローラも画面毎に取得できました。
しかし、ダイアログや、VBで作った画面でも、form.ShowInTaskbarがFalseの場合(?)のウィンドウなどは
取得できません。
こういったフォーム(画面)はどうやったら取得できるのでしょうか。
Imports System.Runtime.InteropServices
Imports System.Text
Public Class Form1
Private Delegate Function Callback(ByVal hWnd As IntPtr, ByVal lParam As Integer) As Integer
' EnumWindows
<DllImport("user32", EntryPoint:="EnumWindows")> _
Private Shared Function EnumWindows( _
ByVal lpEnumFunc As Callback, _
ByVal lParam As Integer) _
As Integer
End Function
' GetWindowText
<DllImport("user32", EntryPoint:="GetWindowText", CharSet:=CharSet.Auto)> _
Private Shared Function GetWindowText( _
ByVal hWnd As IntPtr, _
ByVal lpString As StringBuilder, _
ByVal nMaxCount As Integer) _
As Integer
End Function
' IsWindowVisible
<DllImport("user32", EntryPoint:="IsWindowVisible")> _
Private Shared Function IsWindowVisible( _
ByVal hWnd As IntPtr) _
As Integer
End Function
Public Function EnumerateWindows(ByVal hWnd As IntPtr, ByVal lParam As Integer) As Integer
Dim sb As New StringBuilder(&H1000)
If IsWindowVisible(hWnd) <> 0 Then
If GetWindowText(hWnd, sb, &H1000) <> 0 Then
Me.ListBox1.Items.Add(sb.ToString())
End If
End If
Return Not 0
End Function
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Me.ListBox1.Items.Clear()
' 列挙を開始
EnumWindows(AddressOf EnumerateWindows, 0)
End Sub
End Class
|