home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Programmer'…arterly (Limited Edition) / Visual_Basic_Programmers_Journal_VB-CD_Quarterly_Limited_Edition_1995.iso / code / ch21code / system.cls < prev    next >
Text File  |  1994-10-27  |  4KB  |  116 lines

  1. Version 1.0 Class
  2. Attribute VB_Name = "Application"
  3. Attribute VB_Creatable = True
  4. Attribute VB_Exposed = True
  5. Option Explicit
  6. ' Declare Windows API functions for finding running applicaitons.
  7. Private Declare Function GetNextWindow Lib "User" _
  8.     (ByVal hWnd As Integer, ByVal wFlag As Integer) As Integer
  9. Private Declare Function GetActiveWindow Lib "User" () As Integer
  10. Private Declare Function GetWindowText Lib "User" _
  11.     (ByVal hWnd As Integer, ByVal lpString As String, ByVal aint As Integer) As Integer
  12. Const GW_HWNDNEXT = 2
  13.  
  14.  
  15.  
  16. Private Declare Function GlobalCompact Lib "Kernel" (ByVal dwMinFree As Long) As Long
  17. Private Declare Function GetWinFlags Lib "Kernel" () As Long
  18. Const WF_CPU286 = &h2
  19. Const WF_CPU386 = &h4
  20. Const WF_CPU486 = &h8
  21.  
  22. ' DeclareWindows API functions for showing invisible instances of applications.
  23. Private Declare Function ShowWindow Lib "User" (ByVal hWnd As Integer, ByVal nCmdShow As Integer) As Integer
  24. Const SW_SHOW = 5
  25.  
  26.  
  27. ' Checks if a system meets processor and memory hardware requirement.
  28. ' iProcessor is a three-digit number: 286, 386, or 486
  29. ' iMemory is the number of megabytes of physical memory required.
  30. Public Function MeetsCritera(iProcessor As Integer, iMemory As Integer) As Boolean
  31.     Dim iAvailableMemory  As Integer, lWinFlags As Long
  32.     Dim bProcessor As Boolean
  33.     lWinFlags = GetWinFlags()
  34.     Select Case iProcessor
  35.         Case 286
  36.             ' Windows 3.1 won't run on earlier machines, so True.
  37.             bProcessor = True
  38.         Case 386
  39.             ' If meets critieria, set to True.
  40.              If lWinFlags And WF_CPU386 Then bProcessor = True
  41.             ' If exceeds critieria, set to True.
  42.              If lWinFlags And WF_CPU486 Then bProcessor = True
  43.         Case 486
  44.              If lWinFlags And WF_CPU486 Then bProcessor = True
  45.         Case Else
  46.              ' Error, so return False.
  47.     End Select
  48.     ' Get available physical memory.
  49.     iAvailableMemory = GlobalCompact(0) / (1024 ^ 2)
  50.     ' Combine results of two tests: True And True = True.
  51.     MeetsCritera = bProcessor And iAvailableMemory >= iMemory
  52. End Function
  53.  
  54. Public Function GetTasks() As Variant
  55.     ReDim strTaskList(200) As String
  56.     Dim hWnd As Integer, hWndNext As Integer
  57.     Dim iLen As Integer, iTaskCount As Integer
  58.     Dim strTitle As String * 80
  59.     hWnd = GetActiveWindow()
  60.     Do Until hWnd = 0
  61.         hWndNext = GetNextWindow(hWnd, GW_HWNDNEXT)
  62.         iLen = GetWindowText(hWndNext, strTitle, Len(strTitle))
  63.         If iLen Then
  64.             strTaskList(iTaskCount) = Left$(strTitle, iLen)
  65.             iTaskCount = iTaskCount + 1
  66.         End If
  67.         hWnd = hWndNext
  68.     Loop
  69.     ' Trim off unused elements.
  70.     ReDim Preserve strTaskList(iTaskCount)
  71.     GetTasks = strTaskList
  72. End Function
  73.  
  74. Public Function IsRunning(strAppName) As Boolean
  75.     Dim hWnd As Integer, hWndNext As Integer, iLen As Integer
  76.     Dim strTitle As String * 80
  77.     ' Get a handle to the active window (first in task list).
  78.     hWnd = GetActiveWindow()
  79.     ' Loop until you reach the end of the list.
  80.     Do Until hWnd = 0
  81.         ' Get the next window handle.
  82.         hWndNext = GetNextWindow(hWnd, GW_HWNDNEXT)
  83.         ' Get the text from the window's caption.
  84.         iLen = GetWindowText(hWndNext, strTitle, Len(strTitle))
  85.         If iLen Then
  86.             ' If found, return True.
  87.             If InStr(strTitle, strAppName) Then
  88.                 IsRunning = True
  89.                 Exit Function
  90.             End If
  91.         End If
  92.         hWnd = hWndNext
  93.     Loop
  94.     ' Not found, so return False.
  95.     IsRunning = False
  96. End Function
  97.  
  98. ' Makes all applications visible.
  99. Public Sub MakeVisible()
  100.     Dim hWnd As Integer, iTemp As Integer, iLen As Integer
  101.     Dim strTitle As String * 80
  102.     ' Get a handle to the active window (first in task list).
  103.     hWnd = GetActiveWindow()
  104.     ' Loop until you reach the end of the list.
  105.     Do Until hWnd = 0
  106.         iLen = GetWindowText(hWnd, strTitle, Len(strTitle))
  107.         If iLen Then
  108.             iTemp = ShowWindow(hWnd, SW_SHOW)
  109.         End If
  110.         ' Get the next window handle.
  111.         hWnd = GetNextWindow(hWnd, GW_HWNDNEXT)
  112.     Loop
  113. End Sub
  114.  
  115.  
  116.