Version 1.0 Class
Attribute VB_Name = "Application"
Attribute VB_Creatable = True
Attribute VB_Exposed = True
Option Explicit
' Declare Windows API functions for finding running applicaitons.
Private Declare Function GetNextWindow Lib "User" _
    (ByVal hWnd As Integer, ByVal wFlag As Integer) As Integer
Private Declare Function GetActiveWindow Lib "User" () As Integer
Private Declare Function GetWindowText Lib "User" _
    (ByVal hWnd As Integer, ByVal lpString As String, ByVal aint As Integer) As Integer
Const GW_HWNDNEXT = 2



Private Declare Function GlobalCompact Lib "Kernel" (ByVal dwMinFree As Long) As Long
Private Declare Function GetWinFlags Lib "Kernel" () As Long
Const WF_CPU286 = &h2
Const WF_CPU386 = &h4
Const WF_CPU486 = &h8

' DeclareWindows API functions for showing invisible instances of applications.
Private Declare Function ShowWindow Lib "User" (ByVal hWnd As Integer, ByVal nCmdShow As Integer) As Integer
Const SW_SHOW = 5


' Checks if a system meets processor and memory hardware requirement.
' iProcessor is a three-digit number: 286, 386, or 486
' iMemory is the number of megabytes of physical memory required.
Public Function MeetsCritera(iProcessor As Integer, iMemory As Integer) As Boolean
    Dim iAvailableMemory  As Integer, lWinFlags As Long
    Dim bProcessor As Boolean
    lWinFlags = GetWinFlags()
    Select Case iProcessor
        Case 286
            ' Windows 3.1 won't run on earlier machines, so True.
            bProcessor = True
        Case 386
            ' If meets critieria, set to True.
             If lWinFlags And WF_CPU386 Then bProcessor = True
            ' If exceeds critieria, set to True.
             If lWinFlags And WF_CPU486 Then bProcessor = True
        Case 486
             If lWinFlags And WF_CPU486 Then bProcessor = True
        Case Else
             ' Error, so return False.
    End Select
    ' Get available physical memory.
    iAvailableMemory = GlobalCompact(0) / (1024 ^ 2)
    ' Combine results of two tests: True And True = True.
    MeetsCritera = bProcessor And iAvailableMemory >= iMemory
End Function

Public Function GetTasks() As Variant
    ReDim strTaskList(200) As String
    Dim hWnd As Integer, hWndNext As Integer
    Dim iLen As Integer, iTaskCount As Integer
    Dim strTitle As String * 80
    hWnd = GetActiveWindow()
    Do Until hWnd = 0
        hWndNext = GetNextWindow(hWnd, GW_HWNDNEXT)
        iLen = GetWindowText(hWndNext, strTitle, Len(strTitle))
        If iLen Then
            strTaskList(iTaskCount) = Left$(strTitle, iLen)
            iTaskCount = iTaskCount + 1
        End If
        hWnd = hWndNext
    Loop
    ' Trim off unused elements.
    ReDim Preserve strTaskList(iTaskCount)
    GetTasks = strTaskList
End Function

Public Function IsRunning(strAppName) As Boolean
    Dim hWnd As Integer, hWndNext As Integer, iLen As Integer
    Dim strTitle As String * 80
    ' Get a handle to the active window (first in task list).
    hWnd = GetActiveWindow()
    ' Loop until you reach the end of the list.
    Do Until hWnd = 0
        ' Get the next window handle.
        hWndNext = GetNextWindow(hWnd, GW_HWNDNEXT)
        ' Get the text from the window's caption.
        iLen = GetWindowText(hWndNext, strTitle, Len(strTitle))
        If iLen Then
            ' If found, return True.
            If InStr(strTitle, strAppName) Then
                IsRunning = True
                Exit Function
            End If
        End If
        hWnd = hWndNext
    Loop
    ' Not found, so return False.
    IsRunning = False
End Function

' Makes all applications visible.
Public Sub MakeVisible()
    Dim hWnd As Integer, iTemp As Integer, iLen As Integer
    Dim strTitle As String * 80
    ' Get a handle to the active window (first in task list).
    hWnd = GetActiveWindow()
    ' Loop until you reach the end of the list.
    Do Until hWnd = 0
        iLen = GetWindowText(hWnd, strTitle, Len(strTitle))
        If iLen Then
            iTemp = ShowWindow(hWnd, SW_SHOW)
        End If
        ' Get the next window handle.
        hWnd = GetNextWindow(hWnd, GW_HWNDNEXT)
    Loop
End Sub


