View Poll Results: what do you think of this probelm?

Voters
2. You may not vote on this poll
  • solution guaranteed

    2 100.00%
  • solution possible

    0 0%
  • kinda possible

    0 0%
  • impossible

    0 0%
Results 1 to 6 of 6

Thread: Windows Task Manager

  1. #1

    Thread Starter
    Member
    Join Date
    Sep 2001
    Location
    New Delhi
    Posts
    34

    Unhappy Windows Task Manager

    Hey guys!
    well can neone tell me how can i teract with the windows task manager in win NT or when we use Ctrl-Alt-Del in 95/98 to get information about what all applications are running?

    Ne help is higly appriciated

    AmPrat
    **** Happens!

  2. #2
    Junior Member
    Join Date
    Sep 2000
    Location
    Yate England
    Posts
    22
    Try this.....

    Create a new standard project..

    Add a listbox and a command button (leave the names default)

    Add the following code to the form:

    Private Sub Command1_Click()

    Dim vCaps As Variant
    Dim lIndex As Long

    vCaps = GetAllCaptions()
    List1.Clear
    For lIndex = 0 To UBound(vCaps)
    List1.AddItem vCaps(lIndex)
    Next

    End Sub

    Now create a module...

    Add the following code to the module:

    Option Explicit

    Private Declare Function EnumWindows Lib "user32" (ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long
    Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
    Private Declare Function IsWindowVisible Lib "user32" (ByVal hwnd As Long) As Long

    Private Const WM_GETTEXT = &HD

    Private aCaptions() As String
    Private lCount As Long

    Public Function GetAllCaptions() As Variant
    lCount = 0
    Call EnumWindows(AddressOf EnumWindowsProc, 0&)
    If lCount Then ReDim Preserve aCaptions(lCount - 1)
    GetAllCaptions = IIf(lCount, aCaptions, Array())
    End Function

    Private Function EnumWindowsProc(ByVal hwnd As Long, ByVal lParam As Long) As Long
    Dim sBuffer As String * 260
    If IsWindowVisible(hwnd) Then
    ReDim Preserve aCaptions(lCount)
    aCaptions(lCount) = Left(sBuffer, SendMessage(hwnd, WM_GETTEXT, 260, ByVal sBuffer))
    If Len(Trim(aCaptions(lCount))) Then lCount = lCount + 1
    End If
    EnumWindowsProc = hwnd
    End Function
    Gibbo

  3. #3

    Thread Starter
    Member
    Join Date
    Sep 2001
    Location
    New Delhi
    Posts
    34

    Thanx Man....a li'll bit more required

    thanx a lot gibbo .....the code works.....but my problem is a bit more complex.....
    the thing is i want my application to be resident in memory(dormant though) and i want it to start executing as soon as Internet Explorer is fired.......
    i was planning to get the information about IE from the task manager and then planning to fire my application.......
    so in the end
    how do i keep my application dormant in memory till IE Fires ?

    Ne Suggestions?

    Amprat
    **** Happens!

  4. #4
    Junior Member
    Join Date
    Sep 2000
    Location
    Yate England
    Posts
    22
    AmPrat,

    I'm not sure!!!

    Maybe:

    Write a stub app that does not load any forms etc. but waits in memory or checks the enumwindows until it finds IE. Once found, your sub could then load your main App.

    I'm not familiar with IE. Can it be customized so that IE starts your app on load??

    Some code to try:

    Create a new project.

    Remove the default form1.

    Add a module and insert the following code:

    Option Explicit

    Private Declare Function EnumWindows Lib "user32" (ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long
    Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
    Private Declare Function IsWindowVisible Lib "user32" (ByVal hwnd As Long) As Long

    Private Const WM_GETTEXT = &HD

    Private aCaptions() As String
    Private lCount As Long

    Public Function GetAllCaptions() As Variant
    lCount = 0
    Call EnumWindows(AddressOf EnumWindowsProc, 0&)
    If lCount Then ReDim Preserve aCaptions(lCount - 1)
    GetAllCaptions = IIf(lCount, aCaptions, Array())
    End Function

    Private Function EnumWindowsProc(ByVal hwnd As Long, ByVal lParam As Long) As Long
    Dim sBuffer As String * 260
    If IsWindowVisible(hwnd) Then
    ReDim Preserve aCaptions(lCount)
    aCaptions(lCount) = Left(sBuffer, SendMessage(hwnd, WM_GETTEXT, 260, ByVal sBuffer))
    If Len(Trim(aCaptions(lCount))) Then lCount = lCount + 1
    End If
    EnumWindowsProc = hwnd
    End Function

    Private Sub Main()

    Do
    Dim vCaps As Variant
    Dim AppName As Variant

    vCaps = GetAllCaptions()

    For Each AppName In vCaps
    If AppName Like "*Microsoft Internet Explorer*" Then
    ' Load your main App Here instead of message
    MsgBox "Microsoft Internet Explorer loaded"
    Exit Do
    End If
    Next
    Pause 10
    Loop
    End Sub

    Private Sub Pause(pauseTime As Single)
    Dim start As Single
    start = Timer ' Set start time.

    Do While Timer < start + pauseTime
    DoEvents ' Yield to other processes.
    Loop


    Now set the project startup to be Sub Main:

    Start IE and a message should be displayed.

    I don't think this is a very goog way to achieve your goal but it's the best way I know how!!

    Let me know how you get on.
    Gibbo

  5. #5

    Thread Starter
    Member
    Join Date
    Sep 2001
    Location
    New Delhi
    Posts
    34
    Hey Gibbo,
    thanx again man....yup the code does work......but only when my application gets focus.......if the focus is on IE (The way i want it) the message is not displayed....it is only displayed when i shift the focus to my window!!!

    Ne suggestions?

    Amprat
    **** Happens!

  6. #6
    Junior Member
    Join Date
    Sep 2000
    Location
    Yate England
    Posts
    22

    Hmmm

    You amy be on your own this one. I'm not to sure!

    Let me know if you resolve it though.

    Best of luke Gibbo....
    Gibbo

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width