
 |
Ejemplos para Programadoras de Visual Basic::
Getting the Windows Task List:
' Instructions:
' 1) Create a new project with one form and one module
' 2) Add a list box and command button to the form.
' 3) Paste the code as indicated below.
' 4) Run the project and click the button. All tasks currently running will
' be loaded into the list box.
' ------------- Paste this code into Module1 -------------
' This sample code is presented as is.
' Although every reasonable effort has been
' made to insure the correctness of the example
' below, Idianna Software Inc. makes no warranty
' of any kind with regard to this program sample
' either implicitly or explicitly.
' This program example may be freely distributed for the
' use of writing computer programs only. Any other use of
' this material requires written permission from Idianna Software inc.
' (c) 2000 Idianna Software inc. All rights reserved.
' Title: Load Windows Task List
' Platform: Visual Basic - 32 bit
' Author: Jon Vote
' Contact: jon@idioma-software.com
' Date: 02/00
'
' Getting the Windows Task List
Option Explicit
Const GW_HWNDFIRST = 0
Const GW_HWNDLAST = 1
Const GW_HWNDNEXT = 2
Const GW_HWNDPREV = 3
Const GW_OWNER = 4
Const GW_CHILD = 5
Declare Function getWindow Lib "user32" _
Alias "GetWindow" _
(ByVal hwnd As Long, _
ByVal wCmd As Long) As Long
Declare Function GetWindowText Lib "user32" _
Alias "GetWindowTextA" (ByVal hwnd As Long, _
ByVal lpString As String, _
ByVal cch As Long) As Long
Declare Function GetWindowTextLength Lib "user32" _
Alias "GetWindowTextLengthA" _
(ByVal hwnd As Long) As Long
Public sWindowTitles() As String
Function LoadTasks(ByVal hwndStartWindow As Long) As Integer
' Read the windows task list
' returns number of tasks
' puts task titles in sWindowTitles()
' Author Jon Vote
' (c) 1998 Idianna Software inc.
'
' www.idioma-software.com
' jon@idoma-software.com
'
'
Dim length As Long
Dim entry As String
Dim rc As Long
Dim hwnd As Long
Dim nWindowTitle As Integer
Dim nLastWIndowSpace As Integer
nLastWIndowSpace = 20
Erase sWindowTitles
ReDim sWindowTitles(nLastWIndowSpace)
hwnd = getWindow(hwndStartWindow, GW_HWNDFIRST)
nWindowTitle = 0
Do While hwnd <> 0
length = GetWindowTextLength(hwnd)
If length > 0 Then
entry = Space$(length + 1)
rc = GetWindowText(hwnd, entry, length + 1)
If nWindowTitle = nLastWIndowSpace Then
nLastWIndowSpace = nLastWIndowSpace + 10
ReDim Preserve sWindowTitles(nLastWIndowSpace)
End If
sWindowTitles(nWindowTitle) = entry
nWindowTitle = nWindowTitle + 1
End If
hwnd = getWindow(hwnd, GW_HWNDNEXT)
Loop
LoadTasks = nWindowTitle - 1
End Function
' ------------- End code for Module -------------
' ------------- Paste this code into Form1 -------------
Option Explicit
Private Sub Command1_Click()
Dim nTaskCount As Integer
Dim i As Integer
Screen.MousePointer = 1
List1.Clear
nTaskCount = LoadTasks(Me.hwnd)
For i = 1 To nTaskCount
List1.AddItem sWindowTitles(i)
Next i
Screen.MousePointer = 0
End Sub
' ------------- End code for Form1 -------------
|