vb@rchiv
VB Classic
VB.NET
ADO.NET
VBA
C#
Schützen Sie Ihre Software vor Software-Piraterie - mit sevLock 1.0 DLL!  
 vb@rchiv Quick-Search: Suche startenErweiterte Suche starten   Impressum  | Datenschutz  | vb@rchiv CD Vol.6  | Shop Copyright ©2000-2025
 
zurück

 Sie sind aktuell nicht angemeldet.Funktionen: Einloggen  |  Neu registrieren  |  Suchen

Visual-Basic Einsteiger
Re: Liste laufender Programme 
Autor: Tolwyn
Datum: 01.02.02 15:47

Hi,

dazu gibt es (glaub ich) zwar auch einen Tip, aber den hab ich gerade nicht gefungen

hier ist nochmal einiges an Code. Was Du brauchst ist ein Form mit einem ListView und einem Button und dann noch ein neues Modul.
' Code für den Botton
Private Sub Command1_Click()
  Call GetWindowList(Me.ListView1, True)
End Sub
 
'*********************************************
' Und das hier alles in ein Modul kopieren
Option Explicit
 
Private Declare Function GetWindow Lib "user32" _
    (ByVal hWnd As Long, ByVal wCmd 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 GetWindowTextLength Lib "user32" Alias _
  "GetWindowTextLengthA" _
    (ByVal hWnd 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 GetWindowThreadProcessId Lib "user32" _
    (ByVal hWnd As Long, lpdwProcessId 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
 
Public Function GetWindowList(oLSV As ListView, Optional bVisible As Boolean = _
  True)
  ' oLSV     - Ein bbeliebiges ListView das die Informationen aufnehmen soll
  ' bVisible - Wenn True werden nur sichtbare Windows angezeigt, ansonsten alles
  Dim hWnd      As Long
  Dim sTitle    As String
  Dim lTaskID   As Long
  Dim lStyle    As Long
  Dim oListItem As ListItem
 
  With oLSV.ColumnHeaders
    .Clear
    .Add , "hWnd", "hWnd"
    .Add , "TaskID", "TaskID"
    .Add , "Visible", "Visible"
    .Add , "Title", "Title"
  End With
  oLSV.ListItems.Clear
  oLSV.View = lvwReport
  ' Erstes WindowHandle holen
  hWnd = GetWindow(oLSV.Parent.hWnd, GW_HWNDFIRST)
  Do
    ' Handle auswerten und im ListView eintragen
    lStyle = GetWindowLong(hWnd, GWL_STYLE)
    lStyle = lStyle And (WS_VISIBLE Or WS_BORDER)
    sTitle = GetWindowTitle(hWnd)
    lTaskID = GetWindowTaskID(hWnd)
 
    If (lStyle = (WS_VISIBLE Or WS_BORDER)) = bVisible Then
      ' in das ListView eintragen
      Set oListItem = oLSV.ListItems.Add(, , hWnd)
      With oListItem
        .SubItems(1) = lTaskID
        .SubItems(2) = lStyle = (WS_VISIBLE Or WS_BORDER)
        .SubItems(3) = sTitle
      End With
    End If
    ' Nächses Handle
    hWnd = GetWindow(hWnd, GW_HWNDNEXT)
  Loop Until hWnd = 0
 
End Function
 
Private Function GetWindowTitle(ByVal hWnd As Long) As String
  ' Ermittelt den Namen eines Windows anhand des Window Handle
  Dim lResult       As Long
  Dim sTemp         As String
 
  lResult = GetWindowTextLength(hWnd) + 1
  sTemp = Space(lResult)
  lResult = GetWindowText(hWnd, sTemp, lResult)
  GetWindowTitle = Left(sTemp, Len(sTemp) - 1)
End Function
 
Private Function GetWindowTaskID(ByVal hWnd As Long) As Long
  ' Ermittelt die TaskID eines Windows anhand des Window Handle
  Dim lResult       As Long
  Dim lTemp         As Long
 
  lResult = GetWindowThreadProcessId(hWnd, lTemp)
  GetWindowTaskID = lTemp
End Function
 
Public Function WordIsRunning(oForm As Form) As Boolean
  ' Gibt True zurück, wenn Word geladen ist
  Dim hWnd      As Long
  Dim sTitle    As String
  Dim lStyle    As Long
 
  WordIsRunning = False ' Ich alter Pessimist ;-)
 
  ' Erstes WindowHandle holen
  hWnd = GetWindow(oForm.hWnd, GW_HWNDFIRST)
 
  Do
    ' Handle auswerten und im ListView eintragen
    lStyle = GetWindowLong(hWnd, GWL_STYLE)
    lStyle = lStyle And (WS_VISIBLE Or WS_BORDER)
 
    If (lStyle = (WS_VISIBLE Or WS_BORDER)) = True Then
      sTitle = GetWindowTitle(hWnd)
      If InStr(1, sTitle, "Microsoft Word", vbTextCompare) > 0 Then
        WordIsRunning = True
        Exit Do
      End If
    End If
    ' Nächses Handle
    hWnd = GetWindow(hWnd, GW_HWNDNEXT)
  Loop Until hWnd = 0
End Function
 
Private Sub GetWindowInfo(ByVal hWnd As Long, sTitle As String, lTaskID As Long)
 
  Dim Parent&, Task&, Result&, x&, Style&, Title$
 
    'Darstellung des Fensters
    Style = GetWindowLong(hWnd, GWL_STYLE)
    Style = Style And (WS_VISIBLE Or WS_BORDER)
 
    'Title des Fenster auslesen
    Result = GetWindowTextLength(hWnd) + 1
    Title = Space$(Result)
    Result = GetWindowText(hWnd, Title, Result)
    Title = Left$(Title, Len(Title) - 1)
 
    'In Abhängigkeit der Optionen die Ausgabe erstellen
    If (Title <> "" Or (Check1.Value = vbChecked)) And _
       (Style = (WS_VISIBLE Or WS_BORDER) Or Option2.Value) Then
 
      List1(0).AddItem CStr(hWnd)
      List1(1).AddItem Title
 
      'Elternfenster ermitteln
      Parent = hWnd
      Do
        Parent = GetParent(Parent)
      Loop Until Parent = 0
 
      'Task Id ermitteln
      Result = GetWindowThreadProcessId(hWnd, Task)
      List1(2).AddItem Task
    End If
End Sub
'*********************************************
Gruß
Tolwyn
alle Nachrichten anzeigenGesamtübersicht  |  Zum Thema  |  Suchen

 ThemaViews  AutorDatum
Liste laufender Programme53Byte301.02.02 14:42
Re: Liste laufender Programme146Tolwyn01.02.02 15:47
Reanke!!32Byte302.02.02 14:40

Sie sind nicht angemeldet!
Um auf diesen Beitrag zu antworten oder neue Beiträge schreiben zu können, müssen Sie sich zunächst anmelden.

Einloggen  |  Neu registrieren

Funktionen:  Zum Thema  |  GesamtübersichtSuchen 

nach obenzurück
 
   

Copyright ©2000-2025 vb@rchiv Dieter Otter
Alle Rechte vorbehalten.
Microsoft, Windows und Visual Basic sind entweder eingetragene Marken oder Marken der Microsoft Corporation in den USA und/oder anderen Ländern. Weitere auf dieser Homepage aufgeführten Produkt- und Firmennamen können geschützte Marken ihrer jeweiligen Inhaber sein.

Diese Seiten wurden optimiert für eine Bildschirmauflösung von mind. 1280x1024 Pixel