hallo zimmwarrior,
schau dir mal das an
Public Class Form1
Public Declare Function EnumWindows Lib "user32.dll" (ByVal lpEnumFunc As _
EnumWindowsProc, ByVal lParam As Int32) As Int32
Public Declare Function IsWindowVisible Lib "user32.dll" (ByVal hwnd As _
IntPtr) As Boolean
Public Delegate Function EnumWindowsProc(ByVal hwnd As IntPtr, ByVal lParam _
As Int32) As Boolean
Public Declare Function GetWindowText Lib "user32.dll" Alias _
"GetWindowTextA" (ByVal hwnd As IntPtr, ByVal lpString As String, ByVal cch _
As Int32) As Int32
Public Declare Function GetWindowTextLength Lib "user32.dll" Alias _
"GetWindowTextLengthA" (ByVal hwnd As IntPtr) As Int32
Public Declare Function GetWindowLong Lib "user32.dll" Alias _
"GetWindowLongA" (ByVal hwnd As IntPtr, ByVal nIndex As Int32) As Int32
Public Declare Function GetParent Lib "user32.dll" (ByVal intptr As IntPtr) _
As IntPtr
Private Declare Function GetWindowRect Lib "user32.dll" (ByVal hWnd As _
IntPtr, ByRef lpRect As RECT) As Boolean
Public Const GWL_HWNDPARENT As Int32 = -8
Private newwindowlist As List(Of String)
Private newhandlelist As List(Of IntPtr)
Private Structure RECT
Public left As Integer
Public top As Integer
Public right As Integer
Public bottom As Integer
' constructor
Public Sub New(ByVal _left As Integer, ByVal _top As Integer, ByVal _
_right As Integer, ByVal _bottom As Integer)
left = _left
top = _top
right = _right
bottom = _bottom
End Sub
End Structure
Private Function EnumWinProc(ByVal hwnd As IntPtr, ByVal lParam As Int32) _
As Boolean
If IsWindowVisible(hwnd) Then
If GetParent(hwnd) = IntPtr.Zero Then
If GetWindowLong(hwnd, GWL_HWNDPARENT) = 0 Then
Dim str As String = String.Empty.PadLeft( _
GetWindowTextLength(hwnd) + 1)
GetWindowText(hwnd, str, str.Length)
If Not String.IsNullOrEmpty(str.Substring(0, str.Length - _
1)) Then
newwindowlist.Add(str.Substring(0, str.Length - 1))
newhandlelist.Add(hwnd)
End If
End If
End If
End If
EnumWinProc = True
End Function
Private Sub RefreshWindowList()
newwindowlist = New List(Of String)
newhandlelist = New List(Of IntPtr)
EnumWindows(AddressOf EnumWinProc, CInt(True))
End Sub
Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As _
System.EventArgs) Handles Button1.Click
RefreshWindowList()
ListBox1.Items.Clear()
Dim count As Integer = 0
For Each item As String In newwindowlist
ListBox1.Items.Add(newhandlelist(count).ToString & " " & item)
count += 1
Next
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As _
System.EventArgs) Handles Button2.Click
'lastForeGroundWindow = foregroundWindow
'alle prozesse mit fensternamen durchlaufen und richtigen finden
'log.Add("Searching for Windows with MainWindowTitle", "")
ListBox2.Items.Clear()
For Each p As Process In Process.GetProcesses
If IsWindowVisible(p.MainWindowHandle) Then 'AndAlso
' p.MainWindowTitle <> String.Empty Then 'AndAlso p.ProcessName _
<> "explorer" Then
'If p.MainWindowHandle = foregroundWindow Then
ListBox2.Items.Add(p.MainWindowHandle.ToString & " " & _
p.ProcessName)
End If
Next
End Sub
Private Sub ListBox1_SelectedIndexChanged(ByVal sender As Object, ByVal e _
As System.EventArgs) Handles ListBox1.SelectedIndexChanged
Dim index As Integer = ListBox1.SelectedIndex
Dim windowrect As RECT
GetWindowRect(newhandlelist(index), windowrect)
Stop
End Sub
End Class sicher nicht perfekt - aber das war ja nur für mich zum testen was der unterschied zwischen process und enumwindows ist.
gruss
mikeb69 |