home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / simula1a / frmclose.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1999-09-13  |  4.9 KB  |  153 lines

  1. VERSION 5.00
  2. Begin VB.Form frmCloseProgram 
  3.    Caption         =   "Close Program"
  4.    ClientHeight    =   5160
  5.    ClientLeft      =   60
  6.    ClientTop       =   345
  7.    ClientWidth     =   6390
  8.    Icon            =   "frmCloseprogs.frx":0000
  9.    LinkTopic       =   "Form1"
  10.    MaxButton       =   0   'False
  11.    MinButton       =   0   'False
  12.    ScaleHeight     =   5160
  13.    ScaleWidth      =   6390
  14.    StartUpPosition =   1  'CenterOwner
  15.    Begin VB.Frame frmPath 
  16.       Caption         =   "Display Path"
  17.       Height          =   615
  18.       Left            =   4200
  19.       TabIndex        =   5
  20.       Top             =   360
  21.       Width           =   2055
  22.       Begin VB.OptionButton optNo 
  23.          Caption         =   "No"
  24.          Height          =   255
  25.          Left            =   1080
  26.          TabIndex        =   7
  27.          Top             =   240
  28.          Width           =   615
  29.       End
  30.       Begin VB.OptionButton optYes 
  31.          BackColor       =   &H8000000A&
  32.          Caption         =   "Yes"
  33.          Height          =   255
  34.          Left            =   360
  35.          TabIndex        =   6
  36.          Top             =   240
  37.          Width           =   615
  38.       End
  39.    End
  40.    Begin VB.ListBox lstItems 
  41.       Height          =   3180
  42.       Left            =   120
  43.       TabIndex        =   3
  44.       Top             =   1080
  45.       Width           =   6135
  46.    End
  47.    Begin VB.CommandButton cmdQuit 
  48.       Caption         =   "Quit"
  49.       Height          =   495
  50.       Left            =   4800
  51.       TabIndex        =   2
  52.       Top             =   4440
  53.       Width           =   1355
  54.    End
  55.    Begin VB.CommandButton cmdStop 
  56.       Caption         =   "End Task"
  57.       Enabled         =   0   'False
  58.       Height          =   495
  59.       Left            =   2520
  60.       TabIndex        =   1
  61.       Top             =   4440
  62.       Width           =   1355
  63.    End
  64.    Begin VB.CommandButton cmdCloseProgram 
  65.       Caption         =   "List Active Programs"
  66.       Height          =   495
  67.       Left            =   240
  68.       TabIndex        =   0
  69.       Top             =   4440
  70.       Width           =   1335
  71.    End
  72.    Begin VB.Label lblActiveProg 
  73.       Caption         =   "Active Programs"
  74.       BeginProperty Font 
  75.          Name            =   "MS Sans Serif"
  76.          Size            =   9.75
  77.          Charset         =   0
  78.          Weight          =   700
  79.          Underline       =   0   'False
  80.          Italic          =   0   'False
  81.          Strikethrough   =   0   'False
  82.       EndProperty
  83.       Height          =   255
  84.       Left            =   120
  85.       TabIndex        =   4
  86.       Top             =   480
  87.       Width           =   1815
  88.    End
  89. Attribute VB_Name = "frmCloseProgram"
  90. Attribute VB_GlobalNameSpace = False
  91. Attribute VB_Creatable = False
  92. Attribute VB_PredeclaredId = True
  93. Attribute VB_Exposed = False
  94. Option Explicit
  95. Dim i As Integer
  96. Dim NumOfProcess As Long
  97. Dim objActiveProcess As clsActiveProcess
  98. Private Sub Form_Load()
  99.     Set objActiveProcess = New clsActiveProcess
  100.     Me.optYes = True
  101.            
  102. End Sub
  103. Private Sub Form_Unload(Cancel As Integer)
  104.     Set objActiveProcess = Nothing
  105. End Sub
  106. Private Sub cmdCloseProgram_Click()
  107. On Error Resume Next
  108.     lstItems.Clear
  109.     NumOfProcess = objActiveProcess.GetActiveProcess
  110.         For i = 0 To NumOfProcess
  111.             If optYes = True Then
  112.              lstItems.AddItem objActiveProcess.szExeFile(i)
  113.              lstItems.ItemData(i) = objActiveProcess.th32ProcessID(i)
  114.                Else
  115.              fEnumWindows objActiveProcess.th32ProcessID(i)
  116.              If i = 0 Then IsResond = "Responding"
  117.              lstItems.AddItem stripPath(objActiveProcess.szExeFile(i)) & " " & IsResond
  118.              lstItems.ItemData(i) = objActiveProcess.th32ProcessID(i)
  119.             End If
  120.         Next
  121.         
  122.         If optYes Then
  123.             lstItems.RemoveItem 0
  124.         End If
  125.         
  126.     lstItems.Selected(0) = True
  127.     Me.cmdStop.Enabled = True
  128. End Sub
  129. Private Sub cmdStop_Click()
  130. Dim lPid     As Long
  131. Dim lProcess As Long
  132. Dim lReturn  As Long
  133.     lPid = lstItems.ItemData(lstItems.ListIndex)
  134. ' Terminate the application unconditionally.
  135.     lProcess = OpenProcess(PROCESS_ALL_ACCESS, 0&, lPid)
  136.     lReturn = TerminateProcess(lProcess, 0&)
  137.     lstItems.RemoveItem lstItems.ListIndex
  138.     lstItems.Selected(0) = True
  139. End Sub
  140. Private Sub cmdQuit_Click()
  141.     Unload Me
  142. End Sub
  143. Private Function stripPath(path As String) As String
  144. 'strip the path from the string
  145. Dim holdval As Integer, holdString As String
  146.     holdval = InStr(1, path, Chr(0)) - 1
  147.        
  148.     holdString = StrReverse(Left(path, holdval))
  149.     holdString = Left(holdString, (InStr(1, holdString, "\") - 1))
  150.     holdString = StrReverse(holdString)
  151.     stripPath = holdString
  152. End Function
  153.