Live-Forum - Die aktuellen Beiträge
Anzeige
Archiv - Navigation
1928to1932
Aktuelles Verzeichnis
Verzeichnis Index
Übersicht Verzeichnisse
Vorheriger Thread
Rückwärts Blättern
Nächster Thread
Vorwärts blättern
Anzeige
HERBERS
Excel-Forum (Archiv)
20+ Jahre Excel-Kompetenz: Von Anwendern, für Anwender
Inhaltsverzeichnis

Prgrammicon aus einer PID auslesen

Prgrammicon aus einer PID auslesen
10.05.2023 10:40:49
Sebastian

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




4
Beiträge zum Forumthread
Beiträge zu diesem Forumthread

Betreff
Datum
Anwender
Anzeige
AW: Prgrammicon aus einer PID auslesen
10.05.2023 18:07:33
onur
"das Programmicon" ??? Was soll das denn sein?


AW: Prgrammicon aus einer PID auslesen
10.05.2023 18:13:06
Sebastian
Naja z.B. bei Excel das Zeichen in der Taskleise oder im Taskmanager, oder bei VLC eben das VLC ICON aus dem Taskmanager usw. Viele Grüße


AW: Prgrammicon aus einer PID auslesen
11.05.2023 06:46:26
Sebastian
Genial, das funktioniert echt klasse :-) Ich bin beendruckt - vielen Lieben Dank

Anzeige

Links zu Excel-Dialogen

Beliebteste Forumthreads (12 Monate)

Anzeige

Beliebteste Forumthreads (12 Monate)

Anzeige
Anzeige
Anzeige