Moin!
Ich möchte gerne alle Prozesse die aktiv sind, diese ein Fenster haben, anzeigen lassen.
Leider zeigt das zweite Listview, die Einträge doppelt an.
Obwohl es z.B nur zwei Editoren gestartet sind, zeigt es dann mehrfach an.
Wie kann ich das Problem lösen?
BIG THX
Ich möchte gerne alle Prozesse die aktiv sind, diese ein Fenster haben, anzeigen lassen.
Leider zeigt das zweite Listview, die Einträge doppelt an.
Obwohl es z.B nur zwei Editoren gestartet sind, zeigt es dann mehrfach an.
Wie kann ich das Problem lösen?
BIG THX
VB.NET-Quellcode
- 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
- Public Const GWL_HWNDPARENT As Int32 = -8
- Private newwindowlist As List(Of String)
- 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))
- End If
- End If
- End If
- EnumWinProc = True
- End Function
- Private Sub RefreshWindowList()
- newwindowlist = New List(Of String)
- EnumWindows(AddressOf EnumWinProc, CInt(True))
- End Sub
- Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
- RefreshWindowList()
- Me.ListView1.Items.Clear()
- Me.ListView2.Items.Clear()
- For Each item As String In newwindowlist
- If Not item = "Program Manager" Then
- Me.ListView1.Items.Add(item)
- End If
- For Each proc As Process In Process.GetProcesses
- If proc.MainWindowTitle <> "" Then
- If Not proc.MainWindowTitle = item Then
- Me.ListView2.Items.Add(proc.ProcessName).SubItems.Add(proc.WorkingSet64.ToString)
- End If
- End If
- Next
- Next
- Me.Label1.Text = Me.ListView1.Items.Count
- End Sub
Visual Basic.NET
MS-SQL
MS-SQL