Programm erkennen und in den Vordergrund setzten

Von: , Frage gestellt am So, 5. Nov 2000

Hi X-perts

Weiss jemand wie ich in VB herausfinden kann ob ein bestimmtes Programm, vo dem ich den Dateinamen kenne, gestartet ist und es dann in den Vordergrund setzten kann??

thx Dani

3 Antworten zu dieser Frage

  1. Antwort von nach 3 Stunden 1 hilfreich
    Re: Programm erkennen und in den Vordergrund setzt

    Z.B. so:

    Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" _
      (ByVal lpClassName As Any, ByVal lpCaption As Any) As Long
    Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" _
      (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
    Private Declare Function IsIconic Lib "user32" (ByVal hwnd As Long) As Long
    Private Declare Function ShowWindow Lib "user32" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long
    Private Declare Function SetForegroundWindow Lib "user32" (ByVal hwnd As Long) As Long
     
    Function IsAppRunning(ByVal strAppName As String, _
            Optional fActivate As Boolean) As Boolean
      Dim hwnd As Long, strClassName As String
      Dim lngX As Long, lngTmp As Long
      On Local Error GoTo Er
      IsAppRunning = False
      Select Case LCase$(strAppName)
        Case "calc":        strClassName = "SciCalc"
        Case "excel":       strClassName = "XLMain"
        Case "word":        strClassName = "OpusApp"
        Case "access":      strClassName = "OMain"
        Case "powerpoint95": strClassName = "PP7FrameClass"
        Case "powerpoint97": strClassName = "PP97FrameClass"
        Case "notepad":     strClassName = "NOTEPAD"
        Case "paintbrush":  strClassName = "pbParent"
        Case "wordpad":     strClassName = "WordPadClass"
        Case "outlook2000": strClassName = "rctrl_renwnd32"
        Case Else:          strClassName = strAppName
      End Select
      
      If strClassName = "" Then
        hwnd = FindWindow(vbNullString, strAppName)
      Else
        hwnd = FindWindow(strClassName, vbNullString)
      End If
      If hwnd <> 0 Then
        SendMessage hwnd, WM_USER + 18, 0, 0
        lngX = IsIconic(hwnd)
        If lngX <> 0 Then
          lngTmp = ShowWindow(hwnd, SW_SHOWNORMAL)
        End If
        If fActivate Then
          lngTmp = SetForegroundWindow(hwnd)
        End If
        IsAppRunning = True
      End If
    Ex:
      Exit Function
    Er:
      MsgBox Err.Description
      IsAppRunning = False
      Resume Ex
    End Function
    


    Reinhard

    • Antwort von nach 2 Tagen hilfreich
      Re^2: Programm erkennen und in den Vordergrund set

      Nicht schlecht!! Aber wie kann man heraus finden welches der Appname ist ...

      thx Dani

      • Antwort von nach 2 Tagen hilfreich
        Re^3: Programm erkennen und in den Vordergrund set

        Das solltest du schon selber wissen - oder halt herausfinden - z.B. mit Spy++ (oder alternativ die Caption in FindWindow verwenden).

        Reinhard

Keine passende Antwort gefunden? Jetzt eigene Frage stellen!