DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: Determine if an application is running

  1. #1
    John Nelson Guest

    Determine if an application is running


    From within VB5, is there an API function that will allow me to check the
    status of a particular application to determine whether or not it is running?

    John Nelson
    Programmer/Analyst
    Marianna, FL

  2. #2
    Alex Nitulescu Guest

    Re: Determine if an application is running


    "John Nelson" <john.nelson@alliancels.com> wrote:
    >
    >From within VB5, is there an API function that will allow me to check the
    >status of a particular application to determine whether or not it is running?
    >
    >John Nelson
    >Programmer/Analyst
    >Marianna, FL


    If you don't know the class (and I don't advise you to use the class (which
    is not unique) you should use the caption. But now the caption might change
    (in MDI programs) so you'd have to search for partial strings, so FindWindow
    won't help. I use <snip from some old code>:

    Public Function WindowFind_ByCaptionEvenIfMDI(strCaption) As Long

    m_lngWindowFind_WindowHwnd = 0
    m_strWindowFind_CaptionSearched = strCaption
    Call EnumWindows(AddressOf WindowFind_EnumAllWindows, &H0) 'lParam is
    not used here
    WindowFind_ByCaptionEvenIfMDI = m_lngWindowFind_WindowHwnd
    End Function

    Private Function WindowFind_EnumAllWindows(ByVal hwnd As Long, ByVal lParam
    As Long) As Long

    'To continue enumeration, we must return True. Return False to stop enumeration.
    'When 1 is returned, enumeration continues until there are no more windows
    left.

    Const SW_SHOWMINIMIZED = 2
    Const SW_SHOWNORMAL = 1

    Dim strCaption As String * 255
    Dim lngLength As Long

    lngLength = GetWindowText(hwnd, strCaption, Len(strCaption))
    If InStr(Left(strCaption, lngLength), m_strWindowFind_CaptionSearched)
    > 0 Then 'found it !

    m_lngWindowFind_WindowHwnd = hwnd
    WindowFind_EnumAllWindows = False 'Since it's found, why look for
    more windows ?
    Else
    WindowFind_EnumAllWindows = True 'Continue searching...
    End If
    End Function

    where
    Private Declare Function EnumWindows Lib "user32" (ByVal lpEnumFunc As Long,
    ByVal lParam As Long) As Long
    Private m_strWindowFind_CaptionSearched As String
    Private m_lngWindowFind_WindowHwnd As Long


    You can use PARTIAL CAPTIONS, like "Word" instead of "Microsoft Word - Document
    1".

  3. #3
    Alex Nitulescu Guest

    Re: Determine if an application is running


    "John Nelson" <john.nelson@alliancels.com> wrote:
    >
    >From within VB5, is there an API function that will allow me to check the
    >status of a particular application to determine whether or not it is running?
    >
    >John Nelson
    >Programmer/Analyst
    >Marianna, FL


    If you don't know the class (and I don't advise you to use the class (which
    is not unique) you should use the caption. But now the caption might change
    (in MDI programs) so you'd have to search for partial strings, so FindWindow
    won't help. I use <snip from some old code>:

    Public Function WindowFind_ByCaptionEvenIfMDI(strCaption) As Long

    m_lngWindowFind_WindowHwnd = 0
    m_strWindowFind_CaptionSearched = strCaption
    Call EnumWindows(AddressOf WindowFind_EnumAllWindows, &H0) 'lParam is
    not used here
    WindowFind_ByCaptionEvenIfMDI = m_lngWindowFind_WindowHwnd
    End Function

    Private Function WindowFind_EnumAllWindows(ByVal hwnd As Long, ByVal lParam
    As Long) As Long

    'To continue enumeration, we must return True. Return False to stop enumeration.
    'When 1 is returned, enumeration continues until there are no more windows
    left.

    Const SW_SHOWMINIMIZED = 2
    Const SW_SHOWNORMAL = 1

    Dim strCaption As String * 255
    Dim lngLength As Long

    lngLength = GetWindowText(hwnd, strCaption, Len(strCaption))
    If InStr(Left(strCaption, lngLength), m_strWindowFind_CaptionSearched)
    > 0 Then 'found it !

    m_lngWindowFind_WindowHwnd = hwnd
    WindowFind_EnumAllWindows = False 'Since it's found, why look for
    more windows ?
    Else
    WindowFind_EnumAllWindows = True 'Continue searching...
    End If
    End Function

    where
    Private Declare Function EnumWindows Lib "user32" (ByVal lpEnumFunc As Long,
    ByVal lParam As Long) As Long
    Private m_strWindowFind_CaptionSearched As String
    Private m_lngWindowFind_WindowHwnd As Long


    You can use PARTIAL CAPTIONS, like "Word" instead of "Microsoft Word - Document
    1".

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center