Solved

List Active Applications (Windows Task Manager)

Posted on 2001-07-11
7
248 Views
Last Modified: 2012-06-21
I'm looking for the API call and its implimentation to list active windows applications similar to Windows Task Manager
0
Comment
Question by:raybeam
7 Comments
 
LVL 3

Accepted Solution

by:
andysalih earned 100 total points
ID: 6272192
this does exactly what you want

http://www.planetsourcecode.com/xq/ASP/txtCodeId.14899/lngWId.1/qx/vb/scripts/ShowCode.htm

you can also build of the code

hope this helps

cheers
andy

0
 
LVL 3

Expert Comment

by:andysalih
ID: 6272201
http://www.planetsourcecode.com/xq/ASP/txtCodeId.9704/lngWId.1/qx/vb/scripts/ShowCode.htm


Declare Function ShowWindow Lib "User" _
    (ByVal hWnd As Integer, ByVal flgs As Integer) _
    As Integer


Declare Function GetWindow Lib "User" _
    (ByVal hWnd As Integer, ByVal wCmd As Integer) _
    As Integer


Declare Function GetWindowWord Lib "User" _
    (ByVal hWnd As Integer, ByVal wIndx As Integer) _
    As Integer


Declare Function GetWindowLong Lib "User" _
    (ByVal hWnd As Integer, ByVal wIndx As Integer) As Long


Declare Function GetWindowText Lib "User" _
    (ByVal hWnd As Integer, ByVal lpSting As String, _
    ByVal nMaxCount As Integer) As Integer


Declare Function GetWindowTextLength Lib "User" _
    (ByVal hWnd As Integer) As Integer


Declare Function SetWindowPos Lib "User" _
    (ByVal hWnd As Integer, ByVal insaft As Integer, _
    ByVal x%, ByVal y%, ByVal cx%, ByVal cy%, _
    ByVal flgs As Integer) As Integer
    Const WS_MINIMIZE = &H20000000 ' Style bit 'is minimized'
    Const HWND_TOP = 0 ' Move to top of z-order
    Const SWP_NOSIZE = &H1 ' Do not re-size window
    Const SWP_NOMOVE = &H2 ' Do not reposition window
    Const SWP_SHOWWINDOW = &H40 ' Make window visible/active
    Const GW_HWNDFIRST = 0 ' Get first Window handle
    Const GW_HWNDNEXT = 2 ' Get next window handle
    Const GWL_STYLE = (-16) ' Get Window's style bits
    Const SW_RESTORE = 9 ' Restore window
    Dim IsTask As Long ' Style bits for normal task
    ' The following bits will be combined to
    '     define properties
    ' of a 'normal' task top-level window. A
    '     ny window with ' these set will be
    included in the list:
    Const WS_VISIBLE = &H10000000 ' Window is not hidden
    Const WS_BORDER = &H800000 ' Window has a border
    ' Other bits that are normally set inclu
    '     de:
    Const WS_CLIPSIBLINGS = &H4000000 ' can clip windows
    Const WS_THICKFRAME = &H40000 ' Window has thick border
    Const WS_GROUP = &H20000 ' Window is top of group
    Const WS_TABSTOP = &H10000 ' Window has tabstop


    For VB4 32-bit change the function defintions to the following:


Private Declare Function ShowWindow Lib "User32" _
    (ByVal hWnd As Long, ByVal flgs As Long) As Long


Private Declare Function GetWindow Lib "User32" _
    (ByVal hWnd As Long, ByVal wCmd As Long) As Long


Private Declare Function GetWindowWord Lib "User32" _
    (ByVal hWnd As Long, ByVal wIndx As Long) As Long


Private Declare Function GetWindowLong Lib "User32" Alias "GetWindowLongA" _
    (ByVal hWnd As Long, ByVal wIndx As Long) As Long


Private Declare Function GetWindowText Lib "User32" Alias "GetWindowTextA" _
    (ByVal hWnd As Long, ByVal lpSting As String, ByVal nMaxCount As Long) As
    Long


Private Declare Function GetWindowTextLength Lib "User32" Alias
    "GetWindowTextLengthA" _
    (ByVal hWnd As Long) As Long


Private Declare Function SetWindowPos Lib "User32" (ByVal hWnd As Long, _
    ByVal insaft As Long, ByVal x%, ByVal y%, ByVal cx%, ByVal cy%, _
    ByVal flgs As Long) As Long
'**************************************
' Name: Simulating the task manager func
'     tion from VB
' Description:Here's a simple applicatio
'     n to function like the Windows Task Mana
'     ger...
' By: Sams Beta
'
'
' Inputs:None
'
' Returns:None
'
'Assumes:Start a new project and add the
'     following controls to the form:
Control Name Caption
----------------------------------------------------------
commandbutton cmdRefresh Refresh
commandbutton cmdSwitch Switch
commandbutton cmdExitExit
listboxlstApp
'
'Side Effects:None
'This code is copyrighted and has limite
'     d warranties.
'Please see http://www.Planet-Source-Cod
'     e.com/xq/ASP/txtCodeId.235/lngWId.1/qx/v
'     b/scripts/ShowCode.htm
'for details.
'**************************************



Sub cmdExit_Click ()
    Unload Me ' Get me out of here!
    Set activate = Nothing ' Kill Form reference for good measure
End Sub


Sub cmdRefresh_Click ()
    FindAllApps ' Update list of tasks
End Sub


Sub cmdSwitch_Click ()
    Dim hWnd As Long ' handle to window
    Dim x As Long ' work area
    Dim lngWW As Long ' Window Style bits
    If lstApp.ListIndex < 0 Then Beep: Exit Sub
    ' Get window handle from listbox array
    hWnd = lstApp.ItemData(lstApp.ListIndex)
    ' Get style bits for window
    lngWW = GetWindowLong(hWnd, GWL_STYLE)
    ' If minimized do a restore
    If lngWW And WS_MINIMIZE Then
    x = ShowWindow(hWnd, SW_RESTORE)
End If
' Move window to top of z-order/activate
'     ; no move/resize
x = SetWindowPos(hWnd, HWND_TOP, 0, 0, 0, 0, _
SWP_NOMOVE Or SWP_NOSIZE Or SWP_SHOWWINDOW)
End Sub


Sub FindAllApps ()
    Dim hwCurr As Long
    Dim intLen As Long
    Dim strTitle As String
    ' process all top-level windows in maste
    '     r window list
    lstApp.Clear
    hwCurr = GetWindow(Me.hWnd, GW_HWNDFIRST) ' get first window


    Do While hwCurr ' repeat for all windows


        If hwCurr Me.hWnd And TaskWindow(hwCurr) Then
            intLen = GetWindowTextLength(hwCurr) + 1 ' Get length
            strTitle = Space$(intLen) ' Get caption
            intLen = GetWindowText(hwCurr, strTitle, intLen)


            If intLen > 0 Then ' If we have anything, add it
                lstApp.AddItem strTitle
                ' and let's save the window handle in th
                '     e itemdata array
                lstApp.ItemData(lstApp.NewIndex) = hwCurr
            End If
        End If
        hwCurr = GetWindow(hwCurr, GW_HWNDNEXT)
    Loop
End Sub


Sub Form_Load ()
    IsTask = WS_VISIBLE Or WS_BORDER ' Define bits for normal task
    FindAllApps ' Update list
End Sub


Sub Form_Paint ()
    FindAllApps ' Update List
End Sub


Sub Label1_Click ()
    FindAllApps ' Update list
End Sub


Sub lstApp_DblClick ()
    cmdSwitch.Value = True
End Sub


Function TaskWindow (hwCurr As Long) As Long
    Dim lngStyle As Long
    lngStyle = GetWindowLong(hwCurr, GWL_STYLE)
    If (lngStyle And IsTask) = IsTask Then TaskWindow = True
End Function
0
 
LVL 3

Expert Comment

by:andysalih
ID: 6272205
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 3

Expert Comment

by:andysalih
ID: 6272208
the best on ive seen, have graphical representation is :-
http://www.planetsourcecode.com/xq/ASP/txtCodeId.21195/lngWId.1/qx/vb/scripts/ShowCode.htm

all these threads you can download the actaul source code and build of them

hope this helps

andy
0
 
LVL 49

Expert Comment

by:Ryan Chong
ID: 6272280
Hi raybeam, try this:

Obtaining a List of Running Processes:

http://www.mvps.org/vbnet/code/system/toolhelpprocesses.htm

'Hope will help.
0
 
LVL 8

Expert Comment

by:glass_cookie
ID: 6273289
Hi!

Here's one:

Download...
http://www.vb-helper.com/Howto/listtask.zip

Description: List top-level tasks (3K)

It gives ONLY the windows that are running.  Not the ones at the background.

To use, type:

FindTopLevelWindows Me

That's it!

glass cookie : )
0
 
LVL 1

Author Comment

by:raybeam
ID: 6276825
Thanx guys, all comments were valuable information but the 1st was andy, but I still have a problem, it won't create the hsnap object under Win NT 4

regards to all

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now