Hallo Profis,
ich würde gerne wissen ob es möglich ist in einem Userform Image das zugehörige Icon einer Prozess ID darzustellen.
Die PIDs kann ich mir mit diesem Code Laden.
hat jemand eine Idee wie ich das Programmicon dazu bekommen kann?
Vielen Dnak und viele Grüße
Sebastian
Option Explicit
Private Declare Function GetDesktopWindow Lib "user32" () _
As Long
Private Declare Function GetWindow Lib "user32" _
(ByVal hWnd As Long, ByVal wCmd 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 GetClassName Lib "user32" _
Alias "GetClassNameA" _
(ByVal hWnd As Long, ByVal lpClassName As String, _
ByVal nMaxCount As Long) As Long
Private Declare Function GetWindowTextLength Lib "user32" _
Alias "GetWindowTextLengthA" (ByVal hWnd As Long) _
As Long
Private Declare Function GetWindowThreadProcessId Lib "user32" _
(ByVal hWnd As Long, lpdwProcessId As Long) As Long
Private Declare Function GetWindowLong Lib "user32" Alias _
"GetWindowLongA" (ByVal hWnd As Long, ByVal wIndx As _
Long) As Long
Private Declare Function GetParent Lib "user32" (ByVal hWnd _
As Long) As Long
Const GW_HWNDFIRST = 0
Const GW_HWNDLAST = 1
Const GW_HWNDNEXT = 2
Const GW_HWNDPREV = 3
Const GW_OWNER = 4
Const GW_CHILD = 5
Const GW_MAX = 5
Const GWL_STYLE = (-16)
Const WS_VISIBLE = &H10000000
Const WS_BORDER = &H800000
Private Sub GetWindowInfo(ByVal hWnd&)
Dim Parent&, Task&, Result&, X&, Style&, Title$
'Darstellung des Fensters
Style = GetWindowLong(hWnd, GWL_STYLE)
Style = Style And (WS_VISIBLE Or WS_BORDER)
Result = GetWindowTextLength(hWnd) + 1
Title = Space$(Result)
Result = GetWindowText(hWnd, Title, Result)
Title = Left$(Title, Len(Title) - 1)
If Style = (WS_VISIBLE Or WS_BORDER) Then
If Title > "" Then
Cells(Rows.Count, 1).End(xlUp).Offset(1, 0) = CStr(hWnd)
Cells(Rows.Count, 2).End(xlUp).Offset(1, 0) = Title
'Elternfenster ermitteln
Parent = hWnd
Do
Parent = GetParent(Parent)
Loop Until Parent = 0
'Task Id ermitteln
Result = GetWindowThreadProcessId(hWnd, Task)
Cells(Rows.Count, 3).End(xlUp).Offset(1, 0) = Task
End If
End If
End Sub
Sub vList_Prozesse()
Dim hWnd As Long, tbuf As String, RetVal As Long
'Zellen leeren und Überschrift
Cells.Clear
Range("A1") = "hwnd"
Range("B1") = "Titel"
Range("C1") = "Prozess ID"
Range("A1:C1").Font.Bold = True
hWnd = GetDesktopWindow()
hWnd = GetWindow(hWnd, GW_CHILD)
GetWindowInfo hWnd
Do While hWnd > 0
tbuf = String(255, 0)
RetVal = GetWindowText(hWnd, tbuf, Len(tbuf))
hWnd = GetWindow(hWnd, GW_HWNDNEXT)
GetWindowInfo hWnd
Loop
Columns("A:C").EntireColumn.AutoFit
End Sub